diff --git a/docs/integrations/harness/locations.md b/docs/integrations/harness/locations.md index 8911d7918c..a3d0e2cfd4 100644 --- a/docs/integrations/harness/locations.md +++ b/docs/integrations/harness/locations.md @@ -20,14 +20,14 @@ integrations: harness: - host: app.harness.io token: ${HARNESS_CODE_BEARER_TOKEN} + apiKey: ${HARNESS_CODE_APIKEY} ``` -Directly under the `harnessCode` key is a list of provider configurations, where you -can list the Gitea instances you want to be able to fetch -data from. Each entry is a structure with up to four elements: +Directly under the `harness` key is a list of provider configurations, where you +can list the Harness instances you want to be able to fetch + +check out https://developer.harness.io/docs/platform/automation/api/add-and-manage-api-keys/ for more information - `host`: The host of the Harness Code instance that you want to match on. -- `baseUrl` (optional): Needed if the Harness Code instance is not reachable at - the base of the `host` option (e.g. `https://app.harness.io`). This is the address that you would open in a browser. -- `username` (optional): The gitea username to use in API requests. - `token` (optional): The password or api token to authenticate with. +- `apiKey` (optional): The apiKey to authenticate with. diff --git a/packages/backend-common/src/reading/HarnessUrlReader.ts b/packages/backend-common/src/reading/HarnessUrlReader.ts index fd01e4f8a2..95114ae9d6 100644 --- a/packages/backend-common/src/reading/HarnessUrlReader.ts +++ b/packages/backend-common/src/reading/HarnessUrlReader.ts @@ -118,7 +118,7 @@ export class HarnessUrlReader implements UrlReader { toString() { const { host } = this.integration.config; return `harness{host=${host},authed=${Boolean( - this.integration.config.token, + this.integration.config.token || this.integration.config.apiKey, )}}`; } } diff --git a/packages/integration/api-report.md b/packages/integration/api-report.md index a693c1314c..b40b66b0b6 100644 --- a/packages/integration/api-report.md +++ b/packages/integration/api-report.md @@ -552,7 +552,7 @@ export type GiteaIntegrationConfig = { host: string; baseUrl?: string; username?: string; - token?: string; + password?: string; }; // @public @@ -711,8 +711,7 @@ export class HarnessIntegration implements ScmIntegration { // @public export type HarnessIntegrationConfig = { host: string; - baseUrl?: string; - username?: string; + apiKey?: string; token?: string; }; diff --git a/packages/integration/src/harness/HarnessIntegration.test.ts b/packages/integration/src/harness/HarnessIntegration.test.ts index 9014c0bb79..2d85204f16 100644 --- a/packages/integration/src/harness/HarnessIntegration.test.ts +++ b/packages/integration/src/harness/HarnessIntegration.test.ts @@ -25,8 +25,6 @@ describe('HarnessIntegration', () => { harness: [ { host: 'app.harness.io', - username: 'git', - baseUrl: 'https://app.harness.io/route', token: '1234', }, ], @@ -35,9 +33,6 @@ describe('HarnessIntegration', () => { }); expect(integrations.list().length).toBe(1); expect(integrations.list()[0].config.host).toBe('app.harness.io'); - expect(integrations.list()[0].config.baseUrl).toBe( - 'https://app.harness.io/route', - ); }); it('returns the basics', () => { diff --git a/packages/integration/src/harness/config.test.ts b/packages/integration/src/harness/config.test.ts index 6482e89de8..4f6d8496e3 100644 --- a/packages/integration/src/harness/config.test.ts +++ b/packages/integration/src/harness/config.test.ts @@ -51,16 +51,14 @@ describe('readHarnessConfig', () => { const output = readHarnessConfig( buildConfig({ host: 'a.com', - baseUrl: 'https://a.com/route/api', - username: 'u', token: 'p', + apiKey: 'a', }), ); expect(output).toEqual({ host: 'a.com', - baseUrl: 'https://a.com/route/api', - username: 'u', token: 'p', + apiKey: 'a', }); }); @@ -72,8 +70,6 @@ describe('readHarnessConfig', () => { ); expect(output).toEqual({ host: 'a.com', - baseUrl: 'https://a.com', - username: undefined, token: undefined, }); }); @@ -95,14 +91,11 @@ describe('readHarnessConfig', () => { readHarnessConfig( await buildFrontendConfig({ host: 'a.com', - baseUrl: 'https://a.com/route', - username: 'u', token: 'p', }), ), ).toEqual({ host: 'a.com', - baseUrl: 'https://a.com/route', }); }); }); diff --git a/packages/integration/src/harness/config.ts b/packages/integration/src/harness/config.ts index 75482a9b39..748cd141c5 100644 --- a/packages/integration/src/harness/config.ts +++ b/packages/integration/src/harness/config.ts @@ -15,11 +15,10 @@ */ import { Config } from '@backstage/config'; -import { trimEnd } from 'lodash'; import { isValidHost } from '../helpers'; /** - * The configuration for a single Gitea integration. + * The configuration for a single Harness integration. * * @public */ @@ -28,23 +27,14 @@ export type HarnessIntegrationConfig = { * The host of the target that this matches on, e.g. "app.harness.io" */ host: string; - /** - * The optional base URL of the Harness code instance. It is assumed that https - * is used and that the base path is "/" on the host. If that is not the - * case set the complete base url to the Harness code instance, e.g. - * "https://harnesscode.website.com/". This is the url that you would open - * in a browser. - */ - baseUrl?: string; - /** - * The username to use for requests to harness code. - */ - username?: string; - /** * The password or http token to use for authentication. */ token?: string; + /** + * The API key to use for authentication. + */ + apiKey?: string; }; /** @@ -55,24 +45,20 @@ export type HarnessIntegrationConfig = { export function readHarnessConfig(config: Config): HarnessIntegrationConfig { const host = config.getString('host'); let baseUrl = config.getOptionalString('baseUrl'); - const username = config.getOptionalString('username'); const token = config.getOptionalString('token'); + const apiKey = config.getOptionalString('apiKey'); + if (!isValidHost(host)) { throw new Error( `Invalid Harness Code integration config, '${host}' is not a valid host`, ); } - if (baseUrl) { - baseUrl = trimEnd(baseUrl, '/'); - } else { - baseUrl = `https://${host}`; - } + baseUrl = `https://${host}`; return { host, - baseUrl, - username, + apiKey, token, }; } diff --git a/packages/integration/src/harness/core.test.ts b/packages/integration/src/harness/core.test.ts index 6502fd3e48..2a214cc06f 100644 --- a/packages/integration/src/harness/core.test.ts +++ b/packages/integration/src/harness/core.test.ts @@ -76,20 +76,16 @@ describe('Harness code core', () => { ).toBeUndefined(); }); - it('adds basic auth when username and token are specified', () => { + it('adds basic auth when apikey and token are specified', () => { const authRequest: HarnessIntegrationConfig = { host: 'gerrit.com', - username: 'username', token: 'P', + apiKey: 'a', }; - const basicAuthentication = `basic ${Buffer.from( - `${authRequest.username}:${authRequest.token}`, - ).toString('base64')}`; - expect( - (getHarnessRequestOptions(authRequest).headers as any).Authorization, - ).toEqual(basicAuthentication); + (getHarnessRequestOptions(authRequest).headers as any)['x-api-key'], + ).toEqual('a'); }); }); }); diff --git a/packages/integration/src/harness/core.ts b/packages/integration/src/harness/core.ts index 0c4fb01970..324a57071c 100644 --- a/packages/integration/src/harness/core.ts +++ b/packages/integration/src/harness/core.ts @@ -34,7 +34,7 @@ export function getHarnessEditContentsUrl( url: string, ) { try { - const baseUrl = config.baseUrl ?? `https://${config.host}`; + const baseUrl = `https://${config.host}`; const [ _blank, _ng, @@ -61,9 +61,8 @@ export function getHarnessEditContentsUrl( } /** - * Given a URL pointing to a file, returns an api URL - * for fetching the contents of the data. - * + * Given a file path URL, + * it returns an API URL which returns the contents of the file. * @remarks * * Converts @@ -79,7 +78,7 @@ export function getHarnessFileContentsUrl( url: string, ) { try { - const baseUrl = config.baseUrl ?? `https://${config.host}`; + const baseUrl = `https://${config.host}`; const [ _blank, _ng, @@ -115,16 +114,14 @@ export function getHarnessRequestOptions(config: HarnessIntegrationConfig): { headers?: Record; } { const headers: Record = {}; - const { username, token } = config; + const { token, apiKey } = config; if (!token) { return headers; } - if (username) { - headers.Authorization = `basic ${Buffer.from( - `${username}:${token}`, - ).toString('base64')}`; + if (apiKey) { + headers['x-api-key'] = apiKey; } else { headers.Authorization = `Bearer ${token}`; }