@adamlonsdale/backstage-plugin-armorcode
Version:
Welcome to the `backstage-plugin-armorcode` plugin for Backstage!
152 lines (149 loc) • 3.94 kB
JavaScript
import React from 'react';
import { g as getProductAnnotation, i as isArmorcodeAvailable, A as ARMORCODE_PRODUCT_ANNOTATION, a as armorcodeApiRef } from './index-ccc0b497.esm.js';
import '@backstage/errors';
import { useEntity } from '@backstage/plugin-catalog-react';
import { useApi } from '@backstage/core-plugin-api';
import useAsync from 'react-use/lib/useAsync';
import { MissingAnnotationEmptyState, Progress, InfoCard, EmptyState } from '@backstage/core-components';
import Alert from '@material-ui/lab/Alert';
import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend } from 'chart.js';
import { Bar } from 'react-chartjs-2';
Chart.register(
CategoryScale,
LinearScale,
BarElement,
Title,
Tooltip,
Legend
);
const options = {
indexAxis: "y",
elements: {
bar: {
borderWidth: 1
}
},
responsive: true,
plugins: {
legend: {
display: false
},
title: {
display: true,
text: "Security Risk"
}
},
scales: {
x: {
grid: {
display: false
}
},
y: {
grid: {
display: false
}
}
}
};
const labels = ["Critical", "High", "Medium", "Low", "None"];
const getSecurityRiskCounts = (items) => {
const counter = {
CRITICAL: 0,
HIGH: 0,
MEDIUM: 0,
LOW: 0,
NONE: 0
};
items == null ? void 0 : items.map((item) => {
switch (item.vulnerabilityWithRemediation.severity) {
case "CRITICAL": {
counter.CRITICAL = counter.CRITICAL + 1;
break;
}
case "HIGH": {
counter.HIGH = counter.HIGH + 1;
break;
}
case "MEDIUM": {
counter.MEDIUM = counter.MEDIUM + 1;
break;
}
case "LOW": {
counter.LOW = counter.LOW + 1;
break;
}
default: {
counter.NONE = counter.NONE + 1;
break;
}
}
});
const counterData = [];
const counterValues = Object.values(counter);
counterValues.forEach((value) => {
counterData.push(value);
});
return counterData;
};
const CardContent = ({ productId }) => {
const armorcodeApi = useApi(armorcodeApiRef);
const { value, loading, error } = useAsync(async () => {
const data2 = await armorcodeApi.getCriticalProductFindings(productId);
return data2;
}, []);
if (loading) {
return /* @__PURE__ */ React.createElement(Progress, null);
} else if (!value) {
return /* @__PURE__ */ React.createElement(InfoCard, { title: "Armorcode" }, /* @__PURE__ */ React.createElement(
EmptyState,
{
missing: "info",
title: "No information to display",
description: `There is no Armorcode Product with id ${productId}!`
}
));
} else if (error) {
return /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, error.message);
}
const counterData = getSecurityRiskCounts(value.items);
const data = {
labels,
datasets: [
{
data: counterData,
borderColor: ["#5a100c", "#9c251f", "#e78c87", "#9a9b9c", "#dddddd"],
backgroundColor: [
"#5a100c",
"#9c251f",
"#e78c87",
"#9a9b9c",
"#dddddd"
]
}
]
};
return /* @__PURE__ */ React.createElement(
InfoCard,
{
title: "Armorcode",
deepLink: {
link: `${value._meta.href}?limit=999`,
title: "View Details"
}
},
/* @__PURE__ */ React.createElement(Bar, { options, data })
);
};
const ArmorcodeCardComponent = () => {
const { entity } = useEntity();
const { productId } = getProductAnnotation(entity);
return isArmorcodeAvailable(entity) ? /* @__PURE__ */ React.createElement(
CardContent,
{
productId
}
) : /* @__PURE__ */ React.createElement(MissingAnnotationEmptyState, { annotation: ARMORCODE_PRODUCT_ANNOTATION });
};
export { ArmorcodeCardComponent };
//# sourceMappingURL=index-57c1f017.esm.js.map