Allow configuration of base URL for Fossa links
Signed-off-by: Linda Navarette <linda.navarette@gmail.com>
This commit is contained in:
committed by
Linda Navarette
parent
06b6920a2c
commit
322d1ceeba
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-fossa': patch
|
||||
---
|
||||
|
||||
Allow configuration of base URL for Fossa links
|
||||
@@ -43,9 +43,12 @@ proxy:
|
||||
headers:
|
||||
Authorization: token ${FOSSA_API_TOKEN}
|
||||
|
||||
# if you have a fossa organization, configure your id here
|
||||
fossa:
|
||||
# if you have a fossa organization, configure your id here
|
||||
organizationId: <your-fossa-organization-id>
|
||||
# if you have a self-managed fossa instance,
|
||||
# configure the baseUrl to use for links to the fossa page here
|
||||
externalLinkBaseUrl: <your fossa url>
|
||||
```
|
||||
|
||||
4. Get an api-token and provide `FOSSA_AUTH_HEADER` as env variable (https://app.fossa.com/account/settings/integrations/api_tokens)
|
||||
|
||||
Vendored
+7
-1
@@ -20,6 +20,12 @@ export interface Config {
|
||||
* The organization id in fossa.
|
||||
* @visibility frontend
|
||||
*/
|
||||
organizationId: string;
|
||||
organizationId?: string;
|
||||
|
||||
/**
|
||||
* The base url to use for external links (from Backstage to Fossa).
|
||||
* @visibility frontend
|
||||
*/
|
||||
externalLinkBaseUrl?: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -175,6 +175,58 @@ describe('FossaClient', () => {
|
||||
expect(summary).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should allow custom external link base url', async () => {
|
||||
client = new FossaClient({
|
||||
discoveryApi,
|
||||
identityApi,
|
||||
organizationId: '8736',
|
||||
externalLinkBaseUrl: 'https://custom.fossa.com', // overrides the default app.fossa.com
|
||||
});
|
||||
server.use(
|
||||
rest.get(`${mockBaseUrl}/fossa/projects`, (req, res, ctx) => {
|
||||
const expectedQuery =
|
||||
'count=1000&page=0&sort=title%2B&organizationId=8736&title=our-service';
|
||||
if (req.url.searchParams.toString() !== expectedQuery) {
|
||||
return res(
|
||||
ctx.status(500),
|
||||
ctx.body(
|
||||
`${req.url.searchParams.toString()} !== ${expectedQuery}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return res(
|
||||
ctx.json([
|
||||
{
|
||||
locator: 'custom+8736/our-service',
|
||||
title: 'our-service',
|
||||
default_branch: 'develop',
|
||||
revisions: [
|
||||
{
|
||||
updatedAt: '2020-01-01T00:00:00Z',
|
||||
dependency_count: 160,
|
||||
unresolved_licensing_issue_count: 5,
|
||||
unresolved_issue_count: 100,
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
const summary = await client.getFindingSummary('our-service');
|
||||
|
||||
expect(summary).toEqual({
|
||||
timestamp: '2020-01-01T00:00:00Z',
|
||||
issueCount: 5,
|
||||
dependencyCount: 160,
|
||||
projectDefaultBranch: 'develop',
|
||||
projectUrl:
|
||||
'https://custom.fossa.com/projects/custom%2B8736%2Four-service',
|
||||
} as FindingSummary);
|
||||
});
|
||||
|
||||
it('should handle 404 status', async () => {
|
||||
server.use(
|
||||
rest.get(`${mockBaseUrl}/fossa/projects`, (_req, res, ctx) => {
|
||||
|
||||
@@ -36,20 +36,24 @@ export class FossaClient implements FossaApi {
|
||||
discoveryApi: DiscoveryApi;
|
||||
identityApi: IdentityApi;
|
||||
organizationId?: string;
|
||||
externalLinkBaseUrl: string;
|
||||
private readonly limit = pLimit(5);
|
||||
|
||||
constructor({
|
||||
discoveryApi,
|
||||
identityApi,
|
||||
organizationId,
|
||||
externalLinkBaseUrl = 'https://app.fossa.com',
|
||||
}: {
|
||||
discoveryApi: DiscoveryApi;
|
||||
identityApi: IdentityApi;
|
||||
organizationId?: string;
|
||||
externalLinkBaseUrl?: string;
|
||||
}) {
|
||||
this.discoveryApi = discoveryApi;
|
||||
this.identityApi = identityApi;
|
||||
this.organizationId = organizationId;
|
||||
this.externalLinkBaseUrl = externalLinkBaseUrl;
|
||||
}
|
||||
|
||||
private async callApi<T>(
|
||||
@@ -104,9 +108,9 @@ export class FossaClient implements FossaApi {
|
||||
revision.unresolved_issue_count,
|
||||
dependencyCount: revision.dependency_count,
|
||||
projectDefaultBranch: project.default_branch,
|
||||
projectUrl: `https://app.fossa.com/projects/${encodeURIComponent(
|
||||
project.locator,
|
||||
)}`,
|
||||
projectUrl: `${
|
||||
this.externalLinkBaseUrl
|
||||
}/projects/${encodeURIComponent(project.locator)}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ export const fossaPlugin = createPlugin({
|
||||
discoveryApi,
|
||||
identityApi,
|
||||
organizationId: configApi.getOptionalString('fossa.organizationId'),
|
||||
externalLinkBaseUrl: configApi.getOptionalString(
|
||||
'fossa.externalLinkBaseUrl',
|
||||
),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user