Skip to content

Commit

Permalink
Merge pull request #109 from snyk-tech-services/feat/bump-per-page
Browse files Browse the repository at this point in the history
feat: call licenses & deps API in parallel
  • Loading branch information
lili2311 authored Oct 14, 2022
2 parents 1d2d43d + b76e177 commit 22d8f79
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/lib/api/org/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ async function getAllDependenciesData(
results: [],
total: undefined,
};
const perPage = 20; // this is a max on that endpoint
const perPage = 20; // 1000 is a max on that endpoint, however anything other than 20 is not working

let currentPage = page;

let hasMorePages = true;

while (hasMorePages) {
Expand Down
1 change: 0 additions & 1 deletion src/lib/api/org/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as snykApiSdk from 'snyk-api-ts-client';
import { getApiToken } from '../../get-api-token';
import { requestsManager } from 'snyk-request-manager';
import { GetLicenseDataOptions } from '../../types';
import { number } from 'yargs';

const debug = debugLib('snyk-licenses:getLicenseDataForOrg');

Expand Down
9 changes: 4 additions & 5 deletions src/lib/generate-org-license-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ export async function generateLicenseData(
debug(`ℹ️ Generating license data for Org:${orgPublicId}`);

try {
const licenseData = await getLicenseDataForOrg(orgPublicId, options);
const [licenseData, dependenciesDataRaw] = await Promise.all([
getLicenseDataForOrg(orgPublicId, options),
getDependenciesDataForOrg(orgPublicId, options),
]);
if (!licenseData.total) {
debug(`ℹ️ Detected 0 licenses`);
throw new Error(
'No licenses returned from /licenses Snyk API. Please make sure the org has licenses configured and try again.',
);
}
debug(`✅ Got license API data for Org:${orgPublicId}`);
const dependenciesDataRaw = await getDependenciesDataForOrg(
orgPublicId,
options,
);
if (!dependenciesDataRaw.total || dependenciesDataRaw.total === 0) {
debug(`ℹ️ API returned 0 dependencies`);
} else {
Expand Down

0 comments on commit 22d8f79

Please sign in to comment.