@adamlonsdale/backstage-plugin-armorcode
Version:
Welcome to the `backstage-plugin-armorcode` plugin for Backstage!
100 lines (93 loc) • 3.22 kB
JavaScript
import { createRouteRef, createApiRef, createPlugin, createApiFactory, discoveryApiRef, identityApiRef, createRoutableExtension } from '@backstage/core-plugin-api';
import { ResponseError } from '@backstage/errors';
const rootRouteRef = createRouteRef({
id: "armorcode"
});
const armorcodeApiRef = createApiRef({
id: "plugin.armorcode.service"
});
class ArmorcodeClient {
constructor(options) {
this.discoveryApi = options.discoveryApi;
this.identityApi = options.identityApi;
}
async getCriticalProductFindings(productId) {
const baseUrl = `${await this.discoveryApi.getBaseUrl("armorcode")}`;
const endpointUrl = `${baseUrl}/products/${productId}/findings/critical`;
const { token: idToken } = await this.identityApi.getCredentials();
const response = await fetch(endpointUrl, {
headers: {
"Content-Type": "application/json",
...idToken && { Authorization: `Bearer ${idToken}` }
}
});
if (!response.ok) {
throw await ResponseError.fromResponse(response);
}
return response.json();
}
async getProducts() {
const baseUrl = `${await this.discoveryApi.getBaseUrl("armorcode")}`;
const endpointUrl = `${baseUrl}/products`;
const { token: idToken } = await this.identityApi.getCredentials();
const response = await fetch(endpointUrl, {
headers: {
"Content-Type": "application/json",
...idToken && { Authorization: `Bearer ${idToken}` }
}
});
if (!response.ok) {
throw await ResponseError.fromResponse(response);
}
return response.json();
}
}
const armorcodePlugin = createPlugin({
id: "armorcode",
apis: [
createApiFactory({
api: armorcodeApiRef,
deps: {
discoveryApi: discoveryApiRef,
identityApi: identityApiRef
},
factory: ({ discoveryApi, identityApi }) => new ArmorcodeClient({
discoveryApi,
identityApi
})
})
],
routes: {
root: rootRouteRef
}
});
const ArmorcodePage = armorcodePlugin.provide(
createRoutableExtension({
name: "ArmorcodePage",
component: () => import('./index-009f5424.esm.js').then((m) => m.ArmorcodePageComponent),
mountPoint: rootRouteRef
})
);
const ArmorcodeCard = armorcodePlugin.provide(
createRoutableExtension({
name: "ArmorcodeCard",
component: () => import('./index-57c1f017.esm.js').then((m) => m.ArmorcodeCardComponent),
mountPoint: rootRouteRef
})
);
const ARMORCODE_PRODUCT_ANNOTATION = "armorcode/product";
const isArmorcodeAvailable = (entity) => {
var _a;
return Boolean((_a = entity.metadata.annotations) == null ? void 0 : _a[ARMORCODE_PRODUCT_ANNOTATION]);
};
const getProductAnnotation = (entity) => {
var _a;
let productId = void 0;
const annotation = (_a = entity == null ? void 0 : entity.metadata.annotations) == null ? void 0 : _a[ARMORCODE_PRODUCT_ANNOTATION];
if (annotation) {
[productId] = annotation.split("/");
}
return { productId };
};
export { ARMORCODE_PRODUCT_ANNOTATION as A, armorcodeApiRef as a, armorcodePlugin as b, ArmorcodePage as c, ArmorcodeCard as d, getProductAnnotation as g, isArmorcodeAvailable as i };
//# sourceMappingURL=index-ccc0b497.esm.js.map