From ec60e69df4514ee63d4a0f8779584d2f4be587b9 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Fri, 17 Feb 2023 17:01:46 +0100 Subject: [PATCH] Use the fetchApi Fix an issue previously introduced Signed-off-by: Jonathan Mezach --- plugins/octopus-deploy/src/api/index.ts | 15 ++++++--------- plugins/octopus-deploy/src/plugin.ts | 8 ++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/plugins/octopus-deploy/src/api/index.ts b/plugins/octopus-deploy/src/api/index.ts index 8a29415dcc..c1a2711b09 100644 --- a/plugins/octopus-deploy/src/api/index.ts +++ b/plugins/octopus-deploy/src/api/index.ts @@ -16,7 +16,7 @@ import { createApiRef, DiscoveryApi, - IdentityApi, + FetchApi, } from '@backstage/core-plugin-api'; /** @public */ @@ -58,7 +58,7 @@ const DEFAULT_PROXY_PATH_BASE = '/octopus-deploy'; /** @public */ export type Options = { discoveryApi: DiscoveryApi; - identityApi: IdentityApi; + fetchApi: FetchApi; /** * Path to use for requests via the proxy, defaults to /octopus-deploy */ @@ -76,12 +76,12 @@ export interface OctopusDeployApi { /** @public */ export class OctopusDeployClient implements OctopusDeployApi { private readonly discoveryApi: DiscoveryApi; - private readonly identityApi: IdentityApi; + private readonly fetchApi: FetchApi; private readonly proxyPathBase: string; constructor(options: Options) { this.discoveryApi = options.discoveryApi; - this.identityApi = options.identityApi; + this.fetchApi = options.fetchApi; this.proxyPathBase = options.proxyPathBase ?? DEFAULT_PROXY_PATH_BASE; } @@ -91,10 +91,7 @@ export class OctopusDeployClient implements OctopusDeployApi { ): Promise { const url = await this.getApiUrl(projectId, releaseHistoryCount); - const { token: idToken } = await this.identityApi.getCredentials(); - const response = await fetch(url, { - headers: idToken ? { Authorization: `Bearer ${idToken}` } : {}, - }); + const response = await this.fetchApi.fetch(url); let responseJson; @@ -122,6 +119,6 @@ export class OctopusDeployClient implements OctopusDeployApi { }); return `${proxyUrl}${this.proxyPathBase}/projects/${encodeURIComponent( projectId, - )}/progression?releaseHistoryCount=${queryParameters}`; + )}/progression?${queryParameters}`; } } diff --git a/plugins/octopus-deploy/src/plugin.ts b/plugins/octopus-deploy/src/plugin.ts index f2ca924032..9365f93bdb 100644 --- a/plugins/octopus-deploy/src/plugin.ts +++ b/plugins/octopus-deploy/src/plugin.ts @@ -23,7 +23,7 @@ import { createPlugin, createRoutableExtension, discoveryApiRef, - identityApiRef, + fetchApiRef, } from '@backstage/core-plugin-api'; import { Entity } from '@backstage/catalog-model'; @@ -38,9 +38,9 @@ export const octopusDeployPlugin = createPlugin({ apis: [ createApiFactory({ api: octopusDeployApiRef, - deps: { discoveryApi: discoveryApiRef, identityApi: identityApiRef }, - factory: ({ discoveryApi, identityApi }) => - new OctopusDeployClient({ discoveryApi, identityApi }), + deps: { discoveryApi: discoveryApiRef, fetchApi: fetchApiRef }, + factory: ({ discoveryApi, fetchApi }) => + new OctopusDeployClient({ discoveryApi, fetchApi }), }), ], });