fix tsc errors
Signed-off-by: Nima Kaviani <nkaviani@amazon.com>
This commit is contained in:
parent
10b78fca7a
commit
b1d4cf26ab
7 changed files with 74 additions and 26 deletions
|
@ -179,10 +179,6 @@ const overviewContent = (
|
|||
</Grid>
|
||||
);
|
||||
|
||||
const terraFormContent = (
|
||||
<TerraformPluginPage />
|
||||
);
|
||||
|
||||
const serviceEntityPage = (
|
||||
<EntityLayout>
|
||||
<EntityLayout.Route path="/" title="Overview">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigApi } from "@backstage/core-plugin-api"
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
|
||||
|
@ -7,9 +8,29 @@ import { createRouter } from './router';
|
|||
describe('createRouter', () => {
|
||||
let app: express.Express;
|
||||
|
||||
const mockConfig: jest.Mocked<ConfigApi> = {
|
||||
has: jest.fn(),
|
||||
keys: jest.fn(),
|
||||
get: jest.fn(),
|
||||
getOptional: jest.fn(),
|
||||
getConfig: jest.fn(),
|
||||
getOptionalConfig: jest.fn(),
|
||||
getConfigArray: jest.fn(),
|
||||
getOptionalConfigArray: jest.fn(),
|
||||
getNumber: jest.fn(),
|
||||
getOptionalNumber: jest.fn(),
|
||||
getBoolean: jest.fn(),
|
||||
getOptionalBoolean: jest.fn(),
|
||||
getString: jest.fn(),
|
||||
getOptionalString: jest.fn(),
|
||||
getStringArray: jest.fn(),
|
||||
getOptionalStringArray: jest.fn(),
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
const router = await createRouter({
|
||||
logger: getVoidLogger(),
|
||||
config: mockConfig,
|
||||
});
|
||||
app = express().use(router);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import { errorHandler } from '@backstage/backend-common';
|
||||
import { coreServices } from '@backstage/backend-plugin-api';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import express from 'express';
|
||||
import Router from 'express-promise-router';
|
||||
import {DefaultAwsCredentialsManager} from '@backstage/integration-aws-node';
|
||||
import {S3Client, ListObjectsV2Command, GetObjectCommand} from "@aws-sdk/client-s3";
|
||||
import * as fs from 'fs';
|
||||
|
||||
const {inflate} = require('pako');
|
||||
|
||||
type ListObjectsInput = {
|
||||
|
@ -14,8 +16,8 @@ type ListObjectsInput = {
|
|||
};
|
||||
|
||||
export interface RouterOptions {
|
||||
logger: coreServices.logger;
|
||||
config: coreServices.rootConfig,
|
||||
logger: LoggerService;
|
||||
config: Config,
|
||||
}
|
||||
|
||||
export async function createRouter(
|
||||
|
@ -40,10 +42,10 @@ export async function createRouter(
|
|||
let jsonData:any = {};
|
||||
|
||||
if(req.body.tfState) {
|
||||
var bytes = [];
|
||||
const bytes = [];
|
||||
const inputString = atob(req.body.tfState);
|
||||
for (var i = 0; i < inputString.length; i++) {
|
||||
var abyte = inputString.charCodeAt(i) & 0xff;
|
||||
for (let i = 0; i < inputString.length; i++) {
|
||||
const abyte = inputString.charCodeAt(i) & 0xff;
|
||||
bytes.push(abyte);
|
||||
}
|
||||
const binData = new Uint8Array(bytes);
|
||||
|
@ -58,7 +60,7 @@ export async function createRouter(
|
|||
let responseObject: any = [];
|
||||
let token: string | undefined = "1";
|
||||
while (token) {
|
||||
let input: ListObjectsInput = {
|
||||
const input: ListObjectsInput = {
|
||||
Bucket: req.body.Bucket,
|
||||
Prefix: req.body.Key,
|
||||
}
|
||||
|
@ -75,15 +77,15 @@ export async function createRouter(
|
|||
});
|
||||
|
||||
router.post('/getLocalFileList', async (req, res) => {
|
||||
let responseObject: any[] = [];
|
||||
const responseObject: any[] = [];
|
||||
|
||||
try {
|
||||
const fsstat = fs.lstatSync(req.body.FileLocation);
|
||||
if (fsstat.isDirectory()) {
|
||||
const filenames = fs.readdirSync(req.body.FileLocation);
|
||||
for (let i in filenames) {
|
||||
for (const i in filenames) {
|
||||
responseObject.push({
|
||||
Key: req.body.FileLocation + "/" + filenames[i]
|
||||
Key: `${req.body.FileLocation }/${ filenames[i]}`
|
||||
});
|
||||
}
|
||||
} else if (fsstat.isFile()) {
|
||||
|
@ -92,7 +94,7 @@ export async function createRouter(
|
|||
});
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(e)
|
||||
logger.error(String(e))
|
||||
}
|
||||
|
||||
res.json(responseObject);
|
||||
|
@ -114,7 +116,7 @@ export async function createRouter(
|
|||
const data = fs.readFileSync(req.body.Key, {encoding: 'utf8', flag: 'r'});
|
||||
jsonData = JSON.parse(data);
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
logger.error(String(e));
|
||||
}
|
||||
|
||||
res.json(jsonData);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import React from 'react';
|
||||
import { createDevApp } from '@backstage/dev-utils';
|
||||
import { terraformPlugin, TerraformPage } from '../src/plugin';
|
||||
import { terraformPlugin, TerraformPluginPage } from '../src/plugin';
|
||||
|
||||
createDevApp()
|
||||
.registerPlugin(terraformPlugin)
|
||||
.addPage({
|
||||
element: <TerraformPage />,
|
||||
element: <TerraformPluginPage />,
|
||||
title: 'Root Page',
|
||||
path: '/terraform'
|
||||
})
|
||||
|
|
|
@ -2,16 +2,45 @@ import { Terraform } from "./Terraform";
|
|||
import { KubernetesApi } from "@backstage/plugin-kubernetes";
|
||||
import { FrontendHostDiscovery } from "@backstage/core-app-api";
|
||||
import { UserIdentity } from "@backstage/core-components";
|
||||
import { IdentityApi, ConfigApi } from "@backstage/core-plugin-api"
|
||||
|
||||
describe("TerraformClient", () => {
|
||||
const mockKClient: jest.Mocked<KubernetesApi> = {
|
||||
getObjectsByEntity: jest.fn(),
|
||||
getClusters: jest.fn(),
|
||||
getCluster: jest.fn(),
|
||||
getWorkloadsByEntity: jest.fn(),
|
||||
getCustomObjectsByEntity: jest.fn(),
|
||||
proxy: jest.fn(),
|
||||
};
|
||||
|
||||
const mockIdentity: jest.Mocked<IdentityApi> = {
|
||||
getProfileInfo:jest.fn(),
|
||||
getBackstageIdentity: jest.fn(),
|
||||
getCredentials: jest.fn(),
|
||||
signOut: jest.fn(),
|
||||
|
||||
}
|
||||
|
||||
const mockConfig: jest.Mocked<ConfigApi> = {
|
||||
has: jest.fn(),
|
||||
keys: jest.fn(),
|
||||
get: jest.fn(),
|
||||
getOptional: jest.fn(),
|
||||
getConfig: jest.fn(),
|
||||
getOptionalConfig: jest.fn(),
|
||||
getConfigArray: jest.fn(),
|
||||
getOptionalConfigArray: jest.fn(),
|
||||
getNumber: jest.fn(),
|
||||
getOptionalNumber: jest.fn(),
|
||||
getBoolean: jest.fn(),
|
||||
getOptionalBoolean: jest.fn(),
|
||||
getString: jest.fn(),
|
||||
getOptionalString: jest.fn(),
|
||||
getStringArray: jest.fn(),
|
||||
getOptionalStringArray: jest.fn(),
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
jest
|
||||
.spyOn(FrontendHostDiscovery.prototype, "getBaseUrl")
|
||||
|
@ -35,7 +64,7 @@ describe("TerraformClient", () => {
|
|||
ok: true,
|
||||
text: async () => "teststring",
|
||||
} as Response);
|
||||
const a = new Terraform(mockKClient);
|
||||
const a = new Terraform(mockKClient, mockIdentity, mockConfig);
|
||||
const spy = jest.spyOn(mockKClient, "proxy");
|
||||
const resp = await a.getSecret("abc", "default", "test");
|
||||
expect(resp).toBeDefined();
|
||||
|
@ -57,7 +86,7 @@ describe("TerraformClient", () => {
|
|||
},
|
||||
]);
|
||||
|
||||
const a = new Terraform(mockKClient);
|
||||
const a = new Terraform(mockKClient, mockIdentity, mockConfig);
|
||||
const spy = jest.spyOn(a, "getFirstCluster");
|
||||
const resp = await a.getSecret(undefined, "default", "test");
|
||||
expect(resp).toBeDefined();
|
||||
|
@ -71,7 +100,7 @@ describe("TerraformClient", () => {
|
|||
text: async () => "oh no",
|
||||
} as Response);
|
||||
|
||||
const a = new Terraform(mockKClient);
|
||||
const a = new Terraform(mockKClient, mockIdentity, mockConfig);
|
||||
await expect(
|
||||
a.getSecret("abc", "default", "test")
|
||||
).rejects.toEqual(
|
||||
|
|
|
@ -23,7 +23,7 @@ export class Terraform implements TerraformApi {
|
|||
async fetchURL(url: string, type: string, requestBody: any) {
|
||||
const { token } = await this.identityApi.getCredentials();
|
||||
const backendUrl = this.configApi.getString('backend.baseUrl');
|
||||
const response = await fetch(backendUrl+""+url, {
|
||||
const response = await fetch(`${backendUrl}${url}`, {
|
||||
method: type,
|
||||
body: JSON.stringify(requestBody),
|
||||
headers: {
|
||||
|
@ -95,7 +95,7 @@ export class Terraform implements TerraformApi {
|
|||
Bucket:string,
|
||||
file:any
|
||||
):Promise<any> {
|
||||
let bodyObj:any = {
|
||||
const bodyObj:any = {
|
||||
Key: file.Key
|
||||
};
|
||||
if(Bucket) {
|
||||
|
@ -156,4 +156,4 @@ export class Terraform implements TerraformApi {
|
|||
}
|
||||
return Promise.reject("no clusters found in configuration");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ export const MainPageFetchComponent = () => {
|
|||
const [resources, setResources] = useState<any[]>([]);
|
||||
const [outputs, setOutputs] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<ResponseError>();
|
||||
const [error] = useState<ResponseError>();
|
||||
|
||||
function parseResources(resourcesArr:any[]) {
|
||||
let resourcesObj:any = {};
|
||||
|
@ -338,4 +338,4 @@ export const MainPageFetchComponent = () => {
|
|||
<ResourceDetailComponent resourceDetail={resourceDetail} allResources={allResources} setResourceDetail={setResourceDetail}/>
|
||||
</Drawer>
|
||||
</>;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue