Skip to content

Commit

Permalink
fix(plugins): snyk issue fix (#171)
Browse files Browse the repository at this point in the history
snyk issue fix

ARC-149

## Description

Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.

Fixes # (issue)

## Type of change

Please delete options that are not relevant.

- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Intermediate change (work in progress)

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration

- [ ] Test A
- [ ] Test B

## Checklist:

- [ ] Performed a self-review of my own code
- [ ] npm test passes on your machine
- [ ] New tests added or existing tests modified to cover all changes
- [ ] Code conforms with the style guide
- [ ] API Documentation in code was updated
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
sadarunnisa-sf authored Jul 3, 2024
1 parent 4f63084 commit 343afa2
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions patches/backstage-plugin-snyk+2.0.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/node_modules/backstage-plugin-snyk/dist/api/index.d.ts b/node_modules/backstage-plugin-snyk/dist/api/index.d.ts
index 1b0ec3c..0b89901 100644
--- a/node_modules/backstage-plugin-snyk/dist/api/index.d.ts
+++ b/node_modules/backstage-plugin-snyk/dist/api/index.d.ts
@@ -14,6 +14,7 @@ export interface SnykApi {
ProjectsList(orgName: string, repoName: string): Promise<any>;
GetDependencyGraph(orgName: string, projectId: string): Promise<any>;
GetSnykAppHost(): string;
+ GetSnykOrgId(): Promise<any>;
GetOrgSlug(orgId: string): Promise<string>;
}
export declare class SnykApiClient implements SnykApi {
@@ -24,6 +25,7 @@ export declare class SnykApiClient implements SnykApi {
constructor(options: Options);
private getApiUrl;
GetSnykAppHost(): string;
+ GetSnykOrgId(): Promise<any>;
ListAllAggregatedIssues(orgId: string, projectId: string): Promise<any>;
ProjectDetails(orgName: string, projectId: string): Promise<any>;
GetOrgSlug(orgId: string): Promise<string>;
diff --git a/node_modules/backstage-plugin-snyk/dist/api/index.js b/node_modules/backstage-plugin-snyk/dist/api/index.js
index 88d2fdb..b908f80 100644
--- a/node_modules/backstage-plugin-snyk/dist/api/index.js
+++ b/node_modules/backstage-plugin-snyk/dist/api/index.js
@@ -134,5 +134,20 @@ export class SnykApiClient {
const jsonResponse = await response.json();
return jsonResponse;
}
+ async GetSnykOrgId() {
+ const backendBaseUrl = await this.getApiUrl();
+ const apiUrl = `${backendBaseUrl}/v1/orgs`;
+ const response = await fetch(`${apiUrl}`, {
+ headers: this.headers,
+ });
+ if (response.status >= 400 && response.status < 600) {
+ throw new Error(`Error ${response.status} - Failed fetching ProjectDetails snyk data`);
+ }
+
+ const jsonResponse = await response.json();
+ const orgs = jsonResponse.orgs;
+ const org = orgs.find(o => o.name === 'sourcefuse');
+ return (org && org.id) ? org.id : '';
+ }
}
//# sourceMappingURL=index.js.map
diff --git a/node_modules/backstage-plugin-snyk/dist/components/SnykEntityComponent/SnykOverviewComponent.js b/node_modules/backstage-plugin-snyk/dist/components/SnykEntityComponent/SnykOverviewComponent.js
index ec32168..34ee03d 100644
--- a/node_modules/backstage-plugin-snyk/dist/components/SnykEntityComponent/SnykOverviewComponent.js
+++ b/node_modules/backstage-plugin-snyk/dist/components/SnykEntityComponent/SnykOverviewComponent.js
@@ -28,7 +28,7 @@ export const SnykOverviewComponent = ({ entity }) => {
React.createElement("img", { src: "https://i.gifer.com/yH.gif" }))));
}
const snykApi = useApi(snykApiRef);
- const orgId = ((_d = entity === null || entity === void 0 ? void 0 : entity.metadata.annotations) === null || _d === void 0 ? void 0 : _d[SNYK_ANNOTATION_ORG]) || "null";
+ // const orgId = ((_d = entity === null || entity === void 0 ? void 0 : entity.metadata.annotations) === null || _d === void 0 ? void 0 : _d[SNYK_ANNOTATION_ORG]) || "null";
const { value, loading, error } = useAsync(async () => {
var _a, _b;
let aggregatedIssuesCount = {
@@ -37,6 +37,7 @@ export const SnykOverviewComponent = ({ entity }) => {
medium: 0,
low: 0,
};
+ const orgId = await snykApi.GetSnykOrgId();
const fullProjectList = await snykApi.ProjectsList(orgId, ((_a = entity.metadata.annotations) === null || _a === void 0 ? void 0 : _a[SNYK_ANNOTATION_TARGETNAME]) || ((_b = entity.metadata.annotations) === null || _b === void 0 ? void 0 : _b[SNYK_ANNOTATION_TARGETID]) || '');
const projectList = fullProjectList;
let projectsCount = 0;

0 comments on commit 343afa2

Please sign in to comment.