From 54c764c996381de5c5aa2dbc781061cf1b5ece82 Mon Sep 17 00:00:00 2001 From: Raul-Cristian Kele Date: Wed, 26 Jul 2023 19:23:48 +0300 Subject: [PATCH] patch: update cve api usage - updated CVEListForImage api calls - updated ImageListWithCVEFixed api calls - now cves are shown for specific tag - fixed tags now only shows tags that match platform with current digest - moved platform selector on tagdetails page Signed-off-by: Raul-Cristian Kele --- src/api.js | 18 ++++-- src/components/Shared/VulnerabilityCard.jsx | 9 ++- .../Tag/Tabs/VulnerabilitiesDetails.jsx | 10 +++- src/components/Tag/TagDetails.jsx | 59 ++++++++++--------- 4 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/api.js b/src/api.js index 111b2aaf..ea4a6531 100644 --- a/src/api.js +++ b/src/api.js @@ -1,11 +1,11 @@ import axios from 'axios'; import { isEmpty } from 'lodash'; import { sortByCriteria } from 'utilities/sortCriteria'; -import { logoutUser } from 'utilities/authUtilities'; +import { isAuthenticationEnabled, logoutUser } from 'utilities/authUtilities'; import { host } from 'host'; axios.interceptors.request.use((config) => { - if (config.url.includes(endpoints.authConfig)) { + if (config.url.includes(endpoints.authConfig) || !isAuthenticationEnabled()) { config.withCredentials = false; } else { config.headers['X-ZOT-API-CLIENT'] = 'zot-ui'; @@ -98,10 +98,18 @@ const endpoints = { } return `${query}){Tag Page {TotalCount ItemCount} CVEList {Id Title Description Severity PackageList {Name InstalledVersion FixedVersion}}}}`; }, - imageListWithCVEFixed: (cveId, repoName, { pageNumber = 1, pageSize = 3 }) => - `/v2/_zot/ext/search?query={ImageListWithCVEFixed(id:"${cveId}", image:"${repoName}", requestedPage: {limit:${pageSize} offset:${ + imageListWithCVEFixed: (cveId, repoName, { pageNumber = 1, pageSize = 3 }, filter = {}) => { + let filterParam = ''; + if (filter.Os || filter.Arch) { + filterParam = `,filter:{`; + if (filter.Os) filterParam += ` Os:${!isEmpty(filter.Os) ? `${JSON.stringify(filter.Os)}` : '""'}`; + if (filter.Arch) filterParam += ` Arch:${!isEmpty(filter.Arch) ? `${JSON.stringify(filter.Arch)}` : '""'}`; + filterParam += '}'; + } + return `/v2/_zot/ext/search?query={ImageListWithCVEFixed(id:"${cveId}", image:"${repoName}", requestedPage: {limit:${pageSize} offset:${ (pageNumber - 1) * pageSize - }}) {Page {TotalCount ItemCount} Results {Tag}}}`, + }}${filterParam}) {Page {TotalCount ItemCount} Results {Tag}}}`; + }, dependsOnForImage: (name, { pageNumber = 1, pageSize = 15 } = {}) => `/v2/_zot/ext/search?query={BaseImageList(image: "${name}", requestedPage: {limit:${pageSize} offset:${ (pageNumber - 1) * pageSize diff --git a/src/components/Shared/VulnerabilityCard.jsx b/src/components/Shared/VulnerabilityCard.jsx index 4a921516..0ee3b7cd 100644 --- a/src/components/Shared/VulnerabilityCard.jsx +++ b/src/components/Shared/VulnerabilityCard.jsx @@ -72,7 +72,7 @@ const useStyles = makeStyles((theme) => ({ })); function VulnerabilitiyCard(props) { const classes = useStyles(); - const { cve, name } = props; + const { cve, name, platform } = props; const [openDesc, setOpenDesc] = useState(false); const [openFixed, setOpenFixed] = useState(false); const [loadingFixed, setLoadingFixed] = useState(true); @@ -90,7 +90,12 @@ function VulnerabilitiyCard(props) { setLoadingFixed(true); api .get( - `${host()}${endpoints.imageListWithCVEFixed(cve.id, name, { pageNumber, pageSize: CVE_FIXEDIN_PAGE_SIZE })}`, + `${host()}${endpoints.imageListWithCVEFixed( + cve.id, + name, + { pageNumber, pageSize: CVE_FIXEDIN_PAGE_SIZE }, + platform ? { Os: platform.Os, Arch: platform.Arch } : {} + )}`, abortController.signal ) .then((response) => { diff --git a/src/components/Tag/Tabs/VulnerabilitiesDetails.jsx b/src/components/Tag/Tabs/VulnerabilitiesDetails.jsx index bddb6a1b..aa05ec86 100644 --- a/src/components/Tag/Tabs/VulnerabilitiesDetails.jsx +++ b/src/components/Tag/Tabs/VulnerabilitiesDetails.jsx @@ -73,7 +73,7 @@ function VulnerabilitiesDetails(props) { const [cveData, setCveData] = useState([]); const [isLoading, setIsLoading] = useState(true); const abortController = useMemo(() => new AbortController(), []); - const { name, tag } = props; + const { name, tag, digest, platform } = props; // pagination props const [cveFilter, setCveFilter] = useState(''); @@ -81,11 +81,15 @@ function VulnerabilitiesDetails(props) { const [isEndOfList, setIsEndOfList] = useState(false); const listBottom = useRef(null); + const getCVERequestName = () => { + return digest !== '' ? `${name}@${digest}` : `${name}:${tag}`; + }; + const getPaginatedCVEs = () => { api .get( `${host()}${endpoints.vulnerabilitiesForRepo( - `${name}:${tag}`, + getCVERequestName(), { pageNumber, pageSize: EXPLORE_PAGE_SIZE }, cveFilter )}`, @@ -171,7 +175,7 @@ function VulnerabilitiesDetails(props) { const renderCVEs = () => { return !isEmpty(cveData) ? ( cveData.map((cve, index) => { - return ; + return ; }) ) : (
{!isLoading && No Vulnerabilities }
diff --git a/src/components/Tag/TagDetails.jsx b/src/components/Tag/TagDetails.jsx index a43fb91a..a9cf0c6a 100644 --- a/src/components/Tag/TagDetails.jsx +++ b/src/components/Tag/TagDetails.jsx @@ -59,7 +59,6 @@ const useStyles = makeStyles((theme) => ({ fontSize: '1rem', lineHeight: '1.5rem', color: '#52637A', - padding: '1rem 0 0 0', maxWidth: '100%', [theme.breakpoints.down('md')]: { padding: '0.5rem 0 0 0', @@ -209,7 +208,14 @@ function TagDetails() { case 'IsDependentOn': return ; case 'Vulnerabilities': - return ; + return ( + + ); case 'ReferredBy': return ; default: @@ -227,10 +233,10 @@ function TagDetails() { - + @@ -256,30 +262,29 @@ function TagDetails() { /> - - - - OS/Arch - {!isEmpty(selectedManifest) && ( - - )} - - - - Digest: {selectedManifest?.digest} - + + + OS/Arch + {!isEmpty(selectedManifest) && ( + + )} + + + Digest: {selectedManifest?.digest} + +