From d00ea30b149ced67396f56b502bc0cca401261f3 Mon Sep 17 00:00:00 2001 From: Mohamed Mohamed Date: Mon, 31 Jul 2023 14:02:01 -0500 Subject: [PATCH] prettier fix Signed-off-by: Mohamed Mohamed --- .../src/service/argocd.service.ts | 10 +-- .../src/service/argocd.test.ts | 34 ++++---- .../src/service/router.test.ts | 32 ++++---- .../src/service/router.ts | 82 +++++++++++-------- .../src/service/types.ts | 1 - 5 files changed, 87 insertions(+), 72 deletions(-) diff --git a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts index d2def1b36..aaa4d080f 100644 --- a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts +++ b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.service.ts @@ -119,7 +119,7 @@ export class ArgoService implements ArgoServiceApi { argoInstance.url, argoInstance.name, token, - options + options, ); } catch (error: any) { return null; @@ -176,14 +176,14 @@ export class ArgoService implements ArgoServiceApi { options?: { name?: string; selector?: string; - } + }, ): Promise { - let urlSuffix = "" + let urlSuffix = ''; if (options?.name) { - urlSuffix = `/${options.name}` + urlSuffix = `/${options.name}`; } if (options?.selector) { - urlSuffix = `?selector=${options.selector}` + urlSuffix = `?selector=${options.selector}`; } const requestOptions: RequestInit = { method: 'GET', diff --git a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.test.ts b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.test.ts index f34207040..3633eefb9 100644 --- a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.test.ts +++ b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/argocd.test.ts @@ -133,7 +133,7 @@ describe('ArgoCD service', () => { namespace: 'testNamespace2', }, }, - ] + ], }), ); const resp = await argoService.getArgoAppData( @@ -142,29 +142,29 @@ describe('ArgoCD service', () => { 'testToken', ); - expect(resp).toStrictEqual( { + expect(resp).toStrictEqual({ items: [ { metadata: { - name: "testAppName", - namespace: "testNamespace", + name: 'testAppName', + namespace: 'testNamespace', instance: { - name: "argoInstance1" - } - } + name: 'argoInstance1', + }, + }, }, { metadata: { - name: "testAppName2", - namespace: "testNamespace2", + name: 'testAppName2', + namespace: 'testNamespace2', instance: { - name: "argoInstance1" - } - } - } - ] + name: 'argoInstance1', + }, + }, + }, + ], }); - }) + }); it('should get argo app data', async () => { fetchMock.mockResponseOnce( @@ -180,7 +180,7 @@ describe('ArgoCD service', () => { 'https://argoInstance1.com', 'argoInstance1', 'testToken', - { name: 'testApp' } + { name: 'testApp' }, ); expect(resp).toStrictEqual({ @@ -200,7 +200,7 @@ describe('ArgoCD service', () => { 'https://argoInstance1.com', 'argoInstance1', 'testToken', - { name: 'testApp' } + { name: 'testApp' }, ), ).rejects.toThrow(); }); diff --git a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.test.ts b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.test.ts index 04854e8c3..9187606d3 100644 --- a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.test.ts +++ b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.test.ts @@ -130,7 +130,7 @@ describe('router', () => { password: 'password', }, ]); - mockGetArgoToken.mockReturnValue("token") + mockGetArgoToken.mockReturnValue('token'); mockGetArgoAppData.mockReturnValue({ items: [ { @@ -140,10 +140,10 @@ describe('router', () => { }, spec: { source: { - repoURL: "test.repo.url", - path: "source/path" - } - } + repoURL: 'test.repo.url', + path: 'source/path', + }, + }, }, { metadata: { @@ -152,20 +152,24 @@ describe('router', () => { }, spec: { source: { - repoURL: "test.repo.url.two", - path: "source/path" - } - } + repoURL: 'test.repo.url.two', + path: 'source/path', + }, + }, }, - ] - }) + ], + }); - const response = await request(app).get('/argoInstance/argoInstance1/repo/testrepo/source/testsource') + const response = await request(app).get( + '/argoInstance/argoInstance1/repo/testrepo/source/testsource', + ); expect(response.body).toEqual(false); - const response2 = await request(app).get('/argoInstance/argoInstance1/repo/test.repo.url/source/source%2Fpath') + const response2 = await request(app).get( + '/argoInstance/argoInstance1/repo/test.repo.url/source/source%2Fpath', + ); expect(response2.body).toEqual(true); - }) + }); it('delete sends back status of app and project deletion', async () => { mockDeleteAppandProject.mockResolvedValue({ diff --git a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.ts b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.ts index 04ccb3fda..bf13c2295 100644 --- a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.ts +++ b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/router.ts @@ -47,7 +47,7 @@ export function createRouter({ return token; } - router.get('/allArgoApps/:argoInstanceName', async(request, response) => { + router.get('/allArgoApps/:argoInstanceName', async (request, response) => { const argoInstanceName = request.params.argoInstanceName; const matchedArgoInstance = findArgoInstance(argoInstanceName); if (matchedArgoInstance === undefined) { @@ -65,39 +65,51 @@ export function createRouter({ message: 'could not generate token', }); } - return response.send(await argoSvc.getArgoAppData( - matchedArgoInstance.url, - matchedArgoInstance.name, - token - )) - }) - - router.get('/argoInstance/:argoInstance/repo/:repo/source/:source', async(request, response) => { - const argoInstanceName = request.params.argoInstance; - const matchedArgoInstance = findArgoInstance(argoInstanceName); - if (matchedArgoInstance === undefined) { - return response.status(500).send({ - status: 'failed', - message: 'cannot find an argo instance to match this cluster', - }); - } - const token: string = await findMatchedArgoInstanceToken( - matchedArgoInstance, + return response.send( + await argoSvc.getArgoAppData( + matchedArgoInstance.url, + matchedArgoInstance.name, + token, + ), ); - if (!token) { - return response.status(500).send({ - status: 'failed', - message: 'could not generate token', - }); - } - const argoData = await argoSvc.getArgoAppData( - matchedArgoInstance.url, - matchedArgoInstance.name, - token - ) - const repoAndSource = argoData.items.map((argoApp: any) => `${argoApp?.spec?.source?.repoURL}/${argoApp?.spec?.source?.path}`) - return response.send(repoAndSource.includes(`${request.params.repo}/${decodeURIComponent(request.params.source)}`)) - }) + }); + + router.get( + '/argoInstance/:argoInstance/repo/:repo/source/:source', + async (request, response) => { + const argoInstanceName = request.params.argoInstance; + const matchedArgoInstance = findArgoInstance(argoInstanceName); + if (matchedArgoInstance === undefined) { + return response.status(500).send({ + status: 'failed', + message: 'cannot find an argo instance to match this cluster', + }); + } + const token: string = await findMatchedArgoInstanceToken( + matchedArgoInstance, + ); + if (!token) { + return response.status(500).send({ + status: 'failed', + message: 'could not generate token', + }); + } + const argoData = await argoSvc.getArgoAppData( + matchedArgoInstance.url, + matchedArgoInstance.name, + token, + ); + const repoAndSource = argoData.items.map( + (argoApp: any) => + `${argoApp?.spec?.source?.repoURL}/${argoApp?.spec?.source?.path}`, + ); + return response.send( + repoAndSource.includes( + `${request.params.repo}/${decodeURIComponent(request.params.source)}`, + ), + ); + }, + ); router.get('/find/name/:argoAppName', async (request, response) => { const argoAppName = request.params.argoAppName; @@ -153,7 +165,7 @@ export function createRouter({ matchedArgoInstance.url, matchedArgoInstance.name, token, - { name: argoAppName } + { name: argoAppName }, ); return response.send(resp); }, @@ -184,7 +196,7 @@ export function createRouter({ matchedArgoInstance.url, matchedArgoInstance.name, token, - { selector: argoAppSelector } + { selector: argoAppSelector }, ); return response.send(resp); }, diff --git a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/types.ts b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/types.ts index e72847644..c729aea85 100644 --- a/plugins/backend/backstage-plugin-argo-cd-backend/src/service/types.ts +++ b/plugins/backend/backstage-plugin-argo-cd-backend/src/service/types.ts @@ -103,7 +103,6 @@ export interface ArgoServiceApi { name: string; selector: string; }, - ) => Promise; createArgoProject: (props: CreateArgoProjectProps) => Promise; createArgoApplication: (props: CreateArgoApplicationProps) => Promise;