Skip to content

Commit

Permalink
docs: DOC-1501 security pagination support (#4897)
Browse files Browse the repository at this point in the history
* docs: security pagination support

* docs: DOC-1501
  • Loading branch information
karl-cardenas-coding authored Dec 6, 2024
1 parent 7d7d3ad commit 8a908ec
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions utils/cves/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,34 @@ const { generateMarkdownTable } = require("../helpers/affected-table");
const { generateRevisionHistory } = require("../helpers/revision-history");

async function getSecurityBulletins(payload) {
const limit = 100;
const maxIterations = 1000;
let results = [];

try {
return await callRateLimitAPI(() => api.post(`https://dso.teams.spectrocloud.com/v1/advisories`, payload));
let request = await callRateLimitAPI(() =>
api.post(`https://dso.teams.spectrocloud.com/v1/advisories?limit=${limit}`, payload)
);
results = request.data.advisories;
let iteration = 0;
while (request.data.continue && iteration < maxIterations) {
iteration++;
request = await callRateLimitAPI(() =>
api.post(
`https://dso.teams.spectrocloud.com/v1/advisories?${limit}&offset=${request.data.offset + limit}`,
payload
)
);
results = results.concat(request.data.advisories);
}

if (iteration === maxIterations) {
logger.warn("Max iterations reached. Verify the API response is setting the continue flag correctly.");
}

return { data: results };
} catch (error) {
logger.error(error);
logger.error("Error:", error.response ? error.response.data || error.response.status : error.message);
logger.error("Error:", error.response ? `${error.response.status} - ${error.response.data}` : error.message);
}
}

Expand Down Expand Up @@ -58,7 +81,7 @@ async function generateCVEs() {
},
{
field: "status.state",
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened"],
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened", "Resolved"],
operator: "in",
},
],
Expand All @@ -80,7 +103,7 @@ async function generateCVEs() {
},
{
field: "status.state",
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened"],
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened", "Resolved"],
operator: "in",
},
],
Expand All @@ -102,7 +125,7 @@ async function generateCVEs() {
},
{
field: "status.state",
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened"],
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened", "Resolved"],
operator: "in",
},
],
Expand All @@ -124,18 +147,23 @@ async function generateCVEs() {
},
{
field: "status.state",
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened"],
options: ["Analyzed", "Modified", "Awaiting Analyses", "Reopened", "Resolved"],
operator: "in",
},
],
});

// Debug logs
// logger.info(`Palette CVEs:", ${palette.data.length}`);
// logger.info(`Palette Airgap CVEs:", ${paletteAirgap.data.length}`);
// logger.info(`Vertex CVEs:", ${vertex.data.length}`);
// logger.info(`Vertex Airgap CVEs:", ${vertexAirgap.data.length}`);

securityBulletins.set("palette", palette);
securityBulletins.set("paletteAirgap", paletteAirgap);
securityBulletins.set("vertex", vertex);
securityBulletins.set("vertexAirgap", vertexAirgap);

// const plainObject = Object.fromEntries(securityBulletins);
const plainObject = Object.fromEntries(
Array.from(securityBulletins.entries()).map(([key, value]) => [key, value.data])
);
Expand Down Expand Up @@ -299,5 +327,8 @@ ${revisionHistory ? revisionHistory : "No revision history available."}
});
}

// Call the main function to generate CVEs
generateCVEs();
try {
generateCVEs();
} catch (error) {
process.exit(5);
}

0 comments on commit 8a908ec

Please sign in to comment.