Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins): snyk issue fix #171

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading