Skip to content

Commit b68a9a4

Browse files
committed
feat: setup sysdig api interface and sysdigApiClient
1 parent 8bf817a commit b68a9a4

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/api/SysdigApi.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* src/api.ts */
2+
import { createApiRef } from "@backstage/core-plugin-api";
3+
4+
export interface SysdigApi {
5+
fetchVulnRuntime: <T = any>(filters?: string, init?: RequestInit) => Promise<T>;
6+
fetchVulnRegistry: <T = any>(
7+
filters?: string,
8+
init?: RequestInit,
9+
) => Promise<T>;
10+
fetchVulnPipeline: <T = any>(
11+
fitlers?: string,
12+
init?: RequestInit,
13+
) => Promise<T>;
14+
fetchInventory: <T = any>(filters?: string, init?: RequestInit) => Promise<T>;
15+
}
16+
17+
export const sysdigApiRef = createApiRef<SysdigApi>({
18+
id: "plugin.sysdig.service",
19+
});

src/api/SysdigApiClient.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { ConfigApi, FetchApi } from "@backstage/core-plugin-api";
2+
import { SysdigApi } from "./SysdigApi";
3+
import {
4+
API_INVENTORY,
5+
API_PROXY_BASE_PATH,
6+
API_VULN_PIPELINE,
7+
API_VULN_REGISTRY,
8+
API_VULN_RUNTIME,
9+
} from "../lib";
10+
11+
export class SysdigApiClient implements SysdigApi {
12+
private readonly fetchApi: FetchApi;
13+
private readonly configApi: ConfigApi;
14+
private readonly baseUrl: string;
15+
16+
constructor(options: { configApi: ConfigApi; fetchApi: FetchApi }) {
17+
this.configApi = options.configApi;
18+
this.fetchApi = options.fetchApi;
19+
this.baseUrl = this.configApi.getString("backend.baseUrl");
20+
}
21+
22+
private async fetch<T>(endpoint: string, init?: RequestInit): Promise<T> {
23+
const uri = `${this.baseUrl}${API_PROXY_BASE_PATH}${endpoint}`;
24+
25+
const response = await this.fetchApi.fetch(uri, init);
26+
27+
if (!response.ok) throw new Error(response.statusText);
28+
29+
return await response.json();
30+
}
31+
32+
async fetchVulnRuntime<T = any>(
33+
filters?: string,
34+
init?: RequestInit,
35+
): Promise<T> {
36+
return await this.fetch<T>(`${API_VULN_RUNTIME}${filters}`, init);
37+
}
38+
39+
async fetchVulnRegistry<T = any>(
40+
filters?: string,
41+
init?: RequestInit,
42+
): Promise<T> {
43+
return await this.fetch<T>(`${API_VULN_REGISTRY}${filters}`, init);
44+
}
45+
46+
async fetchVulnPipeline<T = any>(
47+
filters?: string,
48+
init?: RequestInit,
49+
): Promise<T> {
50+
return await this.fetch<T>(`${API_VULN_PIPELINE}${filters}`, init);
51+
}
52+
53+
async fetchInventory<T = any>(
54+
filters?: string,
55+
init?: RequestInit,
56+
): Promise<T> {
57+
return await this.fetch<T>(`${API_INVENTORY}${filters}`, init);
58+
}
59+
}

src/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./SysdigApi";
2+
export * from "./SysdigApiClient";

0 commit comments

Comments
 (0)