From 921c4aea9f5ea5344d9a731bfc9d6e0f33305680 Mon Sep 17 00:00:00 2001 From: Oren Saldanha Date: Fri, 6 Oct 2023 17:23:49 +0530 Subject: [PATCH] update inventory workflow --- .github/scripts/akto-inventory.js | 42 ++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/.github/scripts/akto-inventory.js b/.github/scripts/akto-inventory.js index 974f54ddb1..959f22562f 100644 --- a/.github/scripts/akto-inventory.js +++ b/.github/scripts/akto-inventory.js @@ -1,5 +1,6 @@ const axios = require("axios") const fs = require("fs") +const { exec } = require("child_process"); const AKTO_DASHBOARD_URL = process.env.AKTO_DASHBOARD_URL const AKTO_API_KEY = process.env.AKTO_API_KEY @@ -78,23 +79,34 @@ async function saveOpenAPIfile(openAPIObject) { } function generateAktoEndpointsSummary(processedOpenAPIObject) { - let sourceAktoEndpoints - - const sourceData = fs.readFileSync("../../apps/dashboard/web/polaris_web/web/src", 'utf8') - sourceAktoEndpoints = sourceData.split('\n') - - const openAPIAktoEndpoints = Object.keys(processedOpenAPIObject.paths) - - logGithubStepSummary(`Akto endpoints count (source): ${sourceAktoEndpoints.length}`) - logGithubStepSummary(`Akto endpoints count (OpenAPI file): ${openAPIAktoEndpoints.length}`) - logGithubStepSummary(`#### Endpoints missing in OpenAPI file`) - - sourceAktoEndpoints.forEach(sourceEndpoint => { - if (!openAPIAktoEndpoints.includes(sourceEndpoint)) { - logGithubStepSummary(`| ${sourceEndpoint} |`) + let sourceAktoEndpoints + + exec('cd ../../apps/dashboard/web/polaris_web/web/src; grep -r --include "*.js" "api/" . | awk -F"\'" \'/url:/ {print $2}\'', (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; } - }); + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + + sourceAktoEndpoints = stdout.split('\n') + sourceAktoEndpoints.pop() + sourceAktoEndpoints.forEach(endpoint => console.log(endpoint)) + const openAPIAktoEndpoints = Object.keys(processedOpenAPIObject.paths) + + logGithubStepSummary(`Akto endpoints count (source): ${sourceAktoEndpoints.length}`) + logGithubStepSummary(`Akto endpoints count (OpenAPI file): ${openAPIAktoEndpoints.length}`) + logGithubStepSummary(`#### Endpoints missing in OpenAPI file`) + + sourceAktoEndpoints.forEach(sourceEndpoint => { + if (!openAPIAktoEndpoints.includes(sourceEndpoint)) { + logGithubStepSummary(`| ${sourceEndpoint} |`) + } + }); + }); } async function main() {