Skip to content

Commit

Permalink
feat: support multi-container
Browse files Browse the repository at this point in the history
  • Loading branch information
mziyabo committed Apr 13, 2024
1 parent df1474e commit c646ef9
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 51 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: release
on:
workflow_dispatch:
push:
branches:
- 'main'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: npm ci
- run: npm run build
3 changes: 0 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: release
on:
workflow_dispatch:
push:
branches:
- 'main'
jobs:
build:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
## v0.2.0 2024-04-13
- `Enhancement`: Allow reports display for pods with multiple containers
- Minor styling updates to improve dark theme visibility

## v0.1.0 2024-04-07
- Initial release
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ server:
- name: extension-trivy
env:
- name: EXTENSION_URL
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.1.0/extension-trivy.tar
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.2.0/extension-trivy.tar
- name: EXTENSION_CHECKSUM_URL
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.1.0/extension-trivy_checksums.txt
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.2.0/extension-trivy_checksums.txt
```
### Kustomize
Expand All @@ -49,9 +49,9 @@ spec:
image: quay.io/argoprojlabs/argocd-extension-installer:v0.0.1
env:
- name: EXTENSION_URL
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.1.0/extension-trivy.tar
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.2.0/extension-trivy.tar
- name: EXTENSION_CHECKSUM_URL
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.1.0/extension-trivy_checksums.txt
value: https://github.com/mziyabo/argocd-trivy-extension/releases/download/v0.2.0/extension-trivy_checksums.txt
volumeMounts:
- name: extensions
mountPath: /tmp/extensions/
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "argocd-trivy-extension",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.4",
Expand Down
12 changes: 12 additions & 0 deletions src/components/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ class Dashboard extends Component {
fetchData();
}

componentDidUpdate(prevProp, prevState){
if (prevProp.reportUrl !== this.props.reportUrl) {
const fetchData = async () => {
const res = await DashboardData(this.props.reportUrl).then(data => {
return data;
})
this.setState(res);
}
fetchData();
}
}

render() {
const { severityData, patchSummaryData, topVulnerableResourcesData, vulnerabilitiesByType, vulnerabilityAgeDistribution, noVulnerabilityData } = this.state;

Expand Down
44 changes: 29 additions & 15 deletions src/components/grid/vulnerability-report.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useRef, useEffect } from 'react';
import React, { useRef, useEffect, useState } from 'react';
import { Grid, html } from 'gridjs';
import { GridData } from '../../utils/data';
import "./vulnerability-report.scss";

function DataGrid({ reportUrl }) {
const tableRef = useRef(null);
let tableRef = useRef(null);

const c = [
"Resource",
Expand Down Expand Up @@ -44,20 +44,34 @@ function DataGrid({ reportUrl }) {
}
];

const [grid] = useState(new Grid({
columns: c,
data: [],
sort: true,
search: true,
pagination: {
limit: 25,
summary: false
}
}))

useEffect(() => {
new Grid({
columns: c,
data: () => {
return GridData(reportUrl) != null ? GridData(reportUrl) : []
},
sort: true,
search: true,
pagination: {
limit: 25,
summary: false
}
}).render(tableRef.current);
});
if (tableRef.current.childNodes.length === 0) {
grid.updateConfig({
data: () => {
return GridData(reportUrl)
},
}).render(tableRef.current)
}
else {
grid.updateConfig({
data: () => {
return GridData(reportUrl)
},
}).forceRender()
}
}
);

return (
<div className="vulnerability-report__wrapper" ref={tableRef} />
Expand Down
53 changes: 51 additions & 2 deletions src/components/grid/vulnerability-report.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,55 @@
border-radius: 7px;
box-shadow: 1px 2px 3px rgba(0, 0, 0, .1)
}

&__container_dropdown {
background-color: transparent;
border-left: none;
border-right: none;
border-top: none;
color: #363c4a;
font-size: 15px;
padding: 8px 0;
position: absolute;
right: 10px;
top: 15px;
width: 170px;
z-index: 1;
}

.theme-light &__container_dropdown {
color: #363c4a;
border-bottom: 2px solid #dee6eb
}

.theme-dark &__container_dropdown {
color: #fff;
border-bottom: 2px solid #495763
}

.theme-light &__container_dropdown:focus {
outline: 0;
border-color: #00a2b3
}

.theme-dark &__container_dropdown:focus {
outline: 0;
border-color: #33BDD0
}
}

.Mui-selected .theme-dark {
color: #fff;
border-color: #33BDD0
}

.Mui-selected .theme-light {
color: #363c4a;
border-color: #00a2b3
}

.theme-dark .MuiTab-textColorPrimary {
color: #1fbdd0;
}

.gridjs-sort {
Expand Down Expand Up @@ -80,12 +129,12 @@
}

.gridjs-pagination .gridjs-pages button {
padding: 0px 3px;
padding: 0 3px;
}

table {
border-collapse: collapse;
min-width: 1000px;
min-width: 100%;
}

tr {
Expand Down
55 changes: 32 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,48 @@ const Extension = (props) => {

const { resource, application } = props;
const appName = application?.metadata?.name || "";
let container = resource?.spec?.template?.spec?.containers[0]?.name || "";
let resourceName = resource?.metadata?.name || "";
let resourceNamespace = resource?.metadata?.namespace || "";
let resourceKind = resource?.kind?.toLowerCase() || "";
const resourceNamespace = resource?.metadata?.namespace || "";
const isPod = resource?.kind === "Pod"
const resourceName = isPod ? resource?.metadata?.ownerReferences[0].name.toLowerCase() : resource?.metadata?.name;
const resourceKind = isPod ? resource?.metadata?.ownerReferences[0].kind.toLowerCase() : resource?.kind?.toLowerCase();

let [container] = useState(isPod ? resource?.spec?.containers[0]?.name : resource?.spec?.template?.spec?.containers[0]?.name);

if (resource?.kind === "Pod") {
container = resource?.spec?.containers[0]?.name
resourceName = resource?.metadata?.ownerReferences[0].name.toLowerCase()
resourceKind = resource?.metadata?.ownerReferences[0].kind.toLowerCase()
}
const baseURI = `${window.location.origin}/api/v1/applications/${appName}/resource`
let [reportUrl, setReportUrl] = useState(`${baseURI}?name=${resourceKind}-${resourceName}-${container}&namespace=${resourceNamespace}&resourceName=${resourceKind}-${resourceName}-${container}&version=v1alpha1&kind=VulnerabilityReport&group=aquasecurity.github.io`);

const reportUrl = `${window.location.origin}/api/v1/applications/${appName}/resource?name=${resourceKind}-${resourceName}-${container}&namespace=${resourceNamespace}&resourceName=${resourceKind}-${resourceName}-${container}&version=v1alpha1&kind=VulnerabilityReport&group=aquasecurity.github.io`
const containers = isPod ? resource?.spec?.containers.map(c => c.name) : resource?.spec?.template?.spec?.containers.map(c => c.name)

const [currentTabIndex, setCurrentTabIndex] = useState(0);
const handleTabChange = (e, tabIndex) => {
console.log(tabIndex);
setCurrentTabIndex(tabIndex);
};

const onOptionChangeHandler = (event) => {
container = event.target.value
setReportUrl(`${baseURI}?name=${resourceKind}-${resourceName}-${container}&namespace=${resourceNamespace}&resourceName=${resourceKind}-${resourceName}-${container}&version=v1alpha1&kind=VulnerabilityReport&group=aquasecurity.github.io`)
};

return (
<React.Fragment>
<Tabs value={currentTabIndex} onChange={handleTabChange}>
<Tab label='Table' />
<Tab label='Dashboard' />
</Tabs>
{currentTabIndex === 0 && (
<DataGrid reportUrl={reportUrl} />
)}
{currentTabIndex === 1 && (
<Dashboard reportUrl={reportUrl} />
)}
</React.Fragment>
<div>
<React.Fragment>
<select class="vulnerability-report__container_dropdown" onChange={onOptionChangeHandler}>
{containers.map((container, index) => {
return (<option key={index} value={container}>{container}</option>)
})}
</select>
<Tabs value={currentTabIndex} onChange={handleTabChange}>
<Tab label='Table' />
<Tab label='Dashboard' />
</Tabs>
{currentTabIndex === 0 && (
<DataGrid reportUrl={reportUrl} />
)}
{currentTabIndex === 1 && (
<Dashboard reportUrl={reportUrl} />
)}
</React.Fragment>
</div>
);
};

Expand Down
3 changes: 2 additions & 1 deletion src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export async function DashboardData(reportUrl) {
patchSummaryData: patchSummaryData(),
topVulnerableResourcesData: topVulnerableResourcesData(15),
vulnerabilityAgeDistribution: vulnerabilityAgeDistribution(),
vulnerabilitiesByType: vulnerabilitiesByType()
vulnerabilitiesByType: vulnerabilitiesByType(),
noVulnerabilityData: false
}
}

Expand Down

0 comments on commit c646ef9

Please sign in to comment.