@socketsecurity/cli-with-sentry 1.18.1 → 1.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +5 -5
- package/dist/.config/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/cli.js +810 -484
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +5 -5
- package/dist/constants.js.map +1 -1
- package/dist/types/commands/ci/detect-ci-pull-request-context.d.mts +7 -0
- package/dist/types/commands/ci/handle-ci.d.mts +0 -7
- package/dist/types/commands/ci/publish-pr-comments.d.mts +12 -0
- package/dist/types/commands/ci/select-baseline-scan.d.mts +10 -0
- package/dist/types/commands/manifest/run-manifest-facts.d.mts +1 -0
- package/dist/types/commands/scan/fetch-diff-scan.d.mts +17 -2
- package/dist/types/commands/scan/fetch-list-scans.d.mts +1 -0
- package/dist/types/commands/scan/handle-create-new-scan.d.mts +2 -0
- package/dist/types/commands/scan/handle-diff-scan.d.mts +9 -1
- package/dist/types/commands/scan/output-create-new-scan.d.mts +1 -0
- package/dist/types/commands/scan/output-diff-scan.d.mts +3 -4
- package/dist/types/constants.d.mts +1 -1
- package/dist/types/sea/version.d.mts +1 -1
- package/dist/types/utils/ci-exit-code.d.mts +11 -0
- package/dist/types/utils/coana.d.mts +1 -0
- package/dist/types/utils/github.d.mts +7 -0
- package/dist/utils.js +365 -286
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +17555 -19029
- package/package.json +45 -42
- package/requirements.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -11,12 +11,12 @@ var flags = require('./flags.js');
|
|
|
11
11
|
var envHelpers = require('./env-helpers.js');
|
|
12
12
|
var u = require('node:fs');
|
|
13
13
|
var path = require('node:path');
|
|
14
|
+
var require$$1 = require('node:util');
|
|
14
15
|
var require$$0 = require('node:crypto');
|
|
15
16
|
var os = require('node:os');
|
|
16
17
|
var childProcess = require('node:child_process');
|
|
17
18
|
var require$$5 = require('node:timers/promises');
|
|
18
19
|
var require$$0$2 = require('node:events');
|
|
19
|
-
var require$$1 = require('node:util');
|
|
20
20
|
var require$$10 = require('node:stream/promises');
|
|
21
21
|
|
|
22
22
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -764,7 +764,7 @@ async function run$V(argv, importMeta, {
|
|
|
764
764
|
interactive: {
|
|
765
765
|
type: 'boolean',
|
|
766
766
|
default: true,
|
|
767
|
-
description: 'Allow for interactive elements, asking for input.\nUse --no-interactive to prevent any input questions
|
|
767
|
+
description: 'Allow for interactive elements, asking for input.\nUse --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
768
768
|
},
|
|
769
769
|
org: {
|
|
770
770
|
type: 'string',
|
|
@@ -875,6 +875,194 @@ async function run$V(argv, importMeta, {
|
|
|
875
875
|
});
|
|
876
876
|
}
|
|
877
877
|
|
|
878
|
+
async function detectCiPullRequestContext() {
|
|
879
|
+
const environment = process.env;
|
|
880
|
+
const githubMatch = /^refs\/pull\/(\d+)\//.exec(envHelpers.envAsString(environment['GITHUB_REF']));
|
|
881
|
+
if (githubMatch) {
|
|
882
|
+
let baseCommitHash = envHelpers.envAsString(environment['GITHUB_BASE_SHA']) || undefined;
|
|
883
|
+
const eventPath = envHelpers.envAsString(environment['GITHUB_EVENT_PATH']);
|
|
884
|
+
if (!baseCommitHash && eventPath) {
|
|
885
|
+
try {
|
|
886
|
+
const event = JSON.parse(await fs.readFile(eventPath, 'utf8'));
|
|
887
|
+
baseCommitHash = typeof event?.pull_request?.base?.sha === 'string' ? event.pull_request.base.sha : undefined;
|
|
888
|
+
} catch {
|
|
889
|
+
baseCommitHash = undefined;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return {
|
|
893
|
+
baseBranch: envHelpers.envAsString(environment['GITHUB_BASE_REF']) || undefined,
|
|
894
|
+
baseCommitHash,
|
|
895
|
+
number: Number(githubMatch[1]),
|
|
896
|
+
provider: 'github'
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
const gitlabNumber = Number(envHelpers.envAsString(environment['CI_MERGE_REQUEST_IID']));
|
|
900
|
+
if (Number.isSafeInteger(gitlabNumber) && gitlabNumber > 0) {
|
|
901
|
+
return {
|
|
902
|
+
baseBranch: envHelpers.envAsString(environment['CI_MERGE_REQUEST_TARGET_BRANCH_NAME']) || undefined,
|
|
903
|
+
baseCommitHash: envHelpers.envAsString(environment['CI_MERGE_REQUEST_DIFF_BASE_SHA']) || undefined,
|
|
904
|
+
number: gitlabNumber,
|
|
905
|
+
provider: 'gitlab'
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
const azureNumber = Number(envHelpers.envAsString(environment['SYSTEM_PULLREQUEST_PULLREQUESTNUMBER']) || envHelpers.envAsString(environment['SYSTEM_PULLREQUEST_PULLREQUESTID']));
|
|
909
|
+
if (Number.isSafeInteger(azureNumber) && azureNumber > 0) {
|
|
910
|
+
return {
|
|
911
|
+
baseBranch: envHelpers.envAsString(environment['SYSTEM_PULLREQUEST_TARGETBRANCH']).replace(/^refs\/heads\//u, '') || undefined,
|
|
912
|
+
baseCommitHash: undefined,
|
|
913
|
+
number: azureNumber,
|
|
914
|
+
provider: 'azure'
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
return {
|
|
918
|
+
baseBranch: undefined,
|
|
919
|
+
baseCommitHash: undefined,
|
|
920
|
+
number: 0,
|
|
921
|
+
provider: undefined
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
const PR_OVERVIEW_COMMENT_MARKER = '<!-- socket-overview-comment-actions -->';
|
|
926
|
+
const PR_SECURITY_COMMENT_MARKER = '<!-- socket-security-comment-actions -->';
|
|
927
|
+
async function publishPullRequestComments({
|
|
928
|
+
diffScanId,
|
|
929
|
+
disableOverview,
|
|
930
|
+
disableSecurity,
|
|
931
|
+
orgSlug,
|
|
932
|
+
owner,
|
|
933
|
+
pullRequest,
|
|
934
|
+
repo,
|
|
935
|
+
serverUrl
|
|
936
|
+
}) {
|
|
937
|
+
if (disableOverview && disableSecurity) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const pullRequestUrl = new URL(`/${owner}/${repo}/pull/${pullRequest}`, serverUrl);
|
|
941
|
+
const query = new URLSearchParams({
|
|
942
|
+
platform: 'github',
|
|
943
|
+
pull_request_url: pullRequestUrl.href,
|
|
944
|
+
bot_commands: 'false'
|
|
945
|
+
});
|
|
946
|
+
// SDK 4.3.0 does not expose this operation yet.
|
|
947
|
+
const result = await utils.queryApiSafeJson(`orgs/${encodeURIComponent(orgSlug)}/diff-scans/${encodeURIComponent(diffScanId)}/comments?${query}`, 'pull request comments');
|
|
948
|
+
if (!result.ok) {
|
|
949
|
+
throw new Error(result.cause || result.message);
|
|
950
|
+
}
|
|
951
|
+
const comments = result.data.diff_scan?.comments;
|
|
952
|
+
if (!comments) {
|
|
953
|
+
throw new Error('Socket did not return rendered pull request comments');
|
|
954
|
+
}
|
|
955
|
+
if (!disableOverview && comments.overview.trim()) {
|
|
956
|
+
await utils.upsertPullRequestComment({
|
|
957
|
+
body: `${PR_OVERVIEW_COMMENT_MARKER}\n${comments.overview}`,
|
|
958
|
+
marker: PR_OVERVIEW_COMMENT_MARKER,
|
|
959
|
+
owner,
|
|
960
|
+
pullRequest,
|
|
961
|
+
repo
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
if (!disableSecurity && comments.alerts.trim()) {
|
|
965
|
+
await utils.upsertPullRequestComment({
|
|
966
|
+
body: `${PR_SECURITY_COMMENT_MARKER}\n${comments.alerts}`,
|
|
967
|
+
marker: PR_SECURITY_COMMENT_MARKER,
|
|
968
|
+
owner,
|
|
969
|
+
pullRequest,
|
|
970
|
+
repo
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
async function fetchOrgFullScanList(config, options) {
|
|
976
|
+
const {
|
|
977
|
+
sdkOpts
|
|
978
|
+
} = {
|
|
979
|
+
__proto__: null,
|
|
980
|
+
...options
|
|
981
|
+
};
|
|
982
|
+
const sockSdkCResult = await utils.setupSdk(sdkOpts);
|
|
983
|
+
if (!sockSdkCResult.ok) {
|
|
984
|
+
return sockSdkCResult;
|
|
985
|
+
}
|
|
986
|
+
const sockSdk = sockSdkCResult.data;
|
|
987
|
+
const {
|
|
988
|
+
branch,
|
|
989
|
+
commitHash,
|
|
990
|
+
direction,
|
|
991
|
+
from_time,
|
|
992
|
+
orgSlug,
|
|
993
|
+
page,
|
|
994
|
+
perPage,
|
|
995
|
+
repo,
|
|
996
|
+
sort
|
|
997
|
+
} = {
|
|
998
|
+
__proto__: null,
|
|
999
|
+
...config
|
|
1000
|
+
};
|
|
1001
|
+
return await utils.handleApiCall(sockSdk.listFullScans(orgSlug, {
|
|
1002
|
+
...(branch ? {
|
|
1003
|
+
branch
|
|
1004
|
+
} : {}),
|
|
1005
|
+
...(commitHash ? {
|
|
1006
|
+
commit_hash: commitHash
|
|
1007
|
+
} : {}),
|
|
1008
|
+
...(repo ? {
|
|
1009
|
+
repo
|
|
1010
|
+
} : {}),
|
|
1011
|
+
...(sort ? {
|
|
1012
|
+
sort: sort
|
|
1013
|
+
} : {}),
|
|
1014
|
+
...(direction ? {
|
|
1015
|
+
direction: direction
|
|
1016
|
+
} : {}),
|
|
1017
|
+
from: from_time,
|
|
1018
|
+
page,
|
|
1019
|
+
per_page: perPage
|
|
1020
|
+
}), {
|
|
1021
|
+
description: 'list of scans'
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
function findBaselineScan(scans, commitHash) {
|
|
1026
|
+
return scans.find(scan => scan.commit_hash === commitHash);
|
|
1027
|
+
}
|
|
1028
|
+
async function selectBaselineScan({
|
|
1029
|
+
branch,
|
|
1030
|
+
commitHash,
|
|
1031
|
+
orgSlug,
|
|
1032
|
+
repo
|
|
1033
|
+
}) {
|
|
1034
|
+
if (!commitHash) {
|
|
1035
|
+
return {
|
|
1036
|
+
ok: false,
|
|
1037
|
+
message: 'Cannot select PR scan baseline',
|
|
1038
|
+
cause: 'The CI checkout does not provide a commit SHA.'
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
const scansCResult = await fetchOrgFullScanList({
|
|
1042
|
+
branch,
|
|
1043
|
+
commitHash,
|
|
1044
|
+
direction: 'desc',
|
|
1045
|
+
from_time: '',
|
|
1046
|
+
orgSlug,
|
|
1047
|
+
page: 1,
|
|
1048
|
+
perPage: 1,
|
|
1049
|
+
repo,
|
|
1050
|
+
sort: 'created_at'
|
|
1051
|
+
});
|
|
1052
|
+
if (!scansCResult.ok) {
|
|
1053
|
+
return scansCResult;
|
|
1054
|
+
}
|
|
1055
|
+
const scan = findBaselineScan(scansCResult.data.results, commitHash);
|
|
1056
|
+
return scan ? {
|
|
1057
|
+
ok: true,
|
|
1058
|
+
data: scan
|
|
1059
|
+
} : {
|
|
1060
|
+
ok: false,
|
|
1061
|
+
message: 'No matching PR scan baseline found',
|
|
1062
|
+
cause: `No scan exists for commit ${commitHash} on ${repo}/${branch}. Run a scan for the base commit first.`
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
|
|
878
1066
|
function normalizeProjectIgnorePath(path) {
|
|
879
1067
|
return utils.stripTrailingSlash(toPosixPath(path.startsWith('/') ? path.slice(1) : path));
|
|
880
1068
|
}
|
|
@@ -1185,6 +1373,351 @@ async function finalizeTier1Scan(tier1ReachabilityScanId, scanId) {
|
|
|
1185
1373
|
});
|
|
1186
1374
|
}
|
|
1187
1375
|
|
|
1376
|
+
// HTTP 202 Accepted: cached results are still being computed; poll again.
|
|
1377
|
+
const HTTP_STATUS_ACCEPTED$1 = 202;
|
|
1378
|
+
const CACHED_POLL_INITIAL_DELAY_MS = 1000;
|
|
1379
|
+
const CACHED_POLL_MAX_DELAY_MS = 10_000;
|
|
1380
|
+
const CACHED_POLL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
1381
|
+
function sleep$1(ms) {
|
|
1382
|
+
return new Promise(resolve => {
|
|
1383
|
+
setTimeout(resolve, ms);
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
async function fetchScan(orgSlug, scanId) {
|
|
1387
|
+
// Serve pre-computed results from the immutable store (`?cached=true`): a
|
|
1388
|
+
// 200 carries the ndjson body, a 202 means the server enqueued a background
|
|
1389
|
+
// job to compute them — poll with backoff until the results are ready, so
|
|
1390
|
+
// callers only ever observe the final scan.
|
|
1391
|
+
const path = `orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}?cached=true`;
|
|
1392
|
+
const deadline = Date.now() + CACHED_POLL_TIMEOUT_MS;
|
|
1393
|
+
let delayMs = CACHED_POLL_INITIAL_DELAY_MS;
|
|
1394
|
+
for (;;) {
|
|
1395
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1396
|
+
const result = await utils.queryApiSafeTextWithStatus(path, 'a scan');
|
|
1397
|
+
if (!result.ok) {
|
|
1398
|
+
return result;
|
|
1399
|
+
}
|
|
1400
|
+
if (result.data.status !== HTTP_STATUS_ACCEPTED$1) {
|
|
1401
|
+
return parseArtifactsNdjson(result.data.text);
|
|
1402
|
+
}
|
|
1403
|
+
if (Date.now() >= deadline) {
|
|
1404
|
+
return {
|
|
1405
|
+
ok: false,
|
|
1406
|
+
message: 'Scan results not ready',
|
|
1407
|
+
cause: `The Socket API is still computing cached results for scan ${scanId} after ${CACHED_POLL_TIMEOUT_MS / 60_000} minutes (path: ${path}). Retry in a few minutes — the server keeps computing in the background.`
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1411
|
+
await sleep$1(delayMs);
|
|
1412
|
+
delayMs = Math.min(delayMs * 2, CACHED_POLL_MAX_DELAY_MS);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
function parseArtifactsNdjson(jsonsString) {
|
|
1416
|
+
// This is nd-json; each line is a json object.
|
|
1417
|
+
const lines = jsonsString.split('\n').filter(Boolean);
|
|
1418
|
+
const data = [];
|
|
1419
|
+
for (let i = 0, {
|
|
1420
|
+
length
|
|
1421
|
+
} = lines; i < length; i += 1) {
|
|
1422
|
+
const line = lines[i];
|
|
1423
|
+
try {
|
|
1424
|
+
data.push(JSON.parse(line));
|
|
1425
|
+
} catch (e) {
|
|
1426
|
+
utils.debugFn('error', 'Failed to parse scan result line as JSON');
|
|
1427
|
+
utils.debugDir('error', {
|
|
1428
|
+
error: e,
|
|
1429
|
+
line
|
|
1430
|
+
});
|
|
1431
|
+
return {
|
|
1432
|
+
ok: false,
|
|
1433
|
+
message: 'Invalid Socket API response',
|
|
1434
|
+
cause: 'The Socket API responded with at least one line that was not valid JSON. Please report if this persists.'
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return {
|
|
1439
|
+
ok: true,
|
|
1440
|
+
data
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
const HTTP_STATUS_ACCEPTED = 202;
|
|
1445
|
+
function sleep(ms) {
|
|
1446
|
+
return new Promise(resolve => {
|
|
1447
|
+
setTimeout(resolve, ms);
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
async function fetchDiffScan({
|
|
1451
|
+
id1,
|
|
1452
|
+
id2,
|
|
1453
|
+
orgSlug
|
|
1454
|
+
}) {
|
|
1455
|
+
utils.logger.info('Scan ID 1:', id1);
|
|
1456
|
+
utils.logger.info('Scan ID 2:', id2);
|
|
1457
|
+
utils.logger.info('Note: this request may take some time if the scans are big');
|
|
1458
|
+
const createQuery = new URLSearchParams({
|
|
1459
|
+
before: id1,
|
|
1460
|
+
after: id2,
|
|
1461
|
+
on_duplicate: 'update'
|
|
1462
|
+
});
|
|
1463
|
+
const createResult = await utils.sendApiRequest(`orgs/${encodeURIComponent(orgSlug)}/diff-scans/from-ids?${createQuery}`, {
|
|
1464
|
+
method: 'POST',
|
|
1465
|
+
description: 'a scan diff creation'
|
|
1466
|
+
});
|
|
1467
|
+
if (!createResult.ok) {
|
|
1468
|
+
return createResult;
|
|
1469
|
+
}
|
|
1470
|
+
const diffScanId = createResult.data.diff_scan.id;
|
|
1471
|
+
const path = `orgs/${encodeURIComponent(orgSlug)}/diff-scans/${encodeURIComponent(diffScanId)}?cached=true`;
|
|
1472
|
+
const deadline = Date.now() + CACHED_POLL_TIMEOUT_MS;
|
|
1473
|
+
let delayMs = CACHED_POLL_INITIAL_DELAY_MS;
|
|
1474
|
+
for (;;) {
|
|
1475
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1476
|
+
const result = await utils.queryApiSafeTextWithStatus(path, 'a scan diff');
|
|
1477
|
+
if (!result.ok) {
|
|
1478
|
+
return result;
|
|
1479
|
+
}
|
|
1480
|
+
if (result.data.status !== HTTP_STATUS_ACCEPTED) {
|
|
1481
|
+
try {
|
|
1482
|
+
return {
|
|
1483
|
+
ok: true,
|
|
1484
|
+
data: JSON.parse(result.data.text)
|
|
1485
|
+
};
|
|
1486
|
+
} catch {
|
|
1487
|
+
return {
|
|
1488
|
+
ok: false,
|
|
1489
|
+
message: 'Server returned invalid JSON',
|
|
1490
|
+
cause: `Unexpected error parsing response JSON (path: ${path})`
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if (Date.now() >= deadline) {
|
|
1495
|
+
return {
|
|
1496
|
+
ok: false,
|
|
1497
|
+
message: 'Diff scan results not ready',
|
|
1498
|
+
cause: `The Socket API is still computing this diff scan after ${CACHED_POLL_TIMEOUT_MS / 60_000} minutes (path: ${path}). Retry in a few minutes — the server keeps computing in the background.`
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1501
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1502
|
+
await sleep(delayMs);
|
|
1503
|
+
delayMs = Math.min(delayMs * 2, CACHED_POLL_MAX_DELAY_MS);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
async function outputDiffScan(result, {
|
|
1508
|
+
depth,
|
|
1509
|
+
file,
|
|
1510
|
+
outputKind,
|
|
1511
|
+
strictBlocking
|
|
1512
|
+
}) {
|
|
1513
|
+
if (!result.ok) {
|
|
1514
|
+
utils.setCiExitCode('api', result.code ?? 1);
|
|
1515
|
+
if (outputKind === 'json') {
|
|
1516
|
+
utils.logger.log(utils.serializeResultJson(result));
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
utils.logger.fail(utils.failMsgWithBadge(result.message, result.cause));
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
const diffScan = result.data.diff_scan;
|
|
1523
|
+
const changedArtifacts = [...diffScan.artifacts.added, ...diffScan.artifacts.updated, ...diffScan.artifacts.replaced];
|
|
1524
|
+
if (changedArtifacts.some(artifact => artifact.alerts?.some(alert => alert.action === 'error'))) {
|
|
1525
|
+
utils.setCiExitCode('blocking');
|
|
1526
|
+
}
|
|
1527
|
+
if (strictBlocking && diffScan.artifacts.unchanged?.some(artifact => artifact.alerts?.some(alert => alert.action === 'error'))) {
|
|
1528
|
+
utils.setCiExitCode('blocking');
|
|
1529
|
+
}
|
|
1530
|
+
const dashboardUrl = diffScan.html_url;
|
|
1531
|
+
const dashboardMessage = dashboardUrl ? `\n View this diff scan in the Socket dashboard: ${vendor.yoctocolorsCjsExports.cyan(dashboardUrl)}` : '';
|
|
1532
|
+
|
|
1533
|
+
// When forcing json, or dumping to file, serialize to string such that it
|
|
1534
|
+
// won't get truncated. The only way to dump the full raw JSON to stdout is
|
|
1535
|
+
// to use `--json --file -` (the dash is a standard notation for stdout)
|
|
1536
|
+
if (outputKind === 'json' || file) {
|
|
1537
|
+
await handleJson(result, file, dashboardMessage);
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
if (outputKind === 'markdown') {
|
|
1541
|
+
await handleMarkdown(result.data);
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
// In this case neither the --json nor the --file flag was passed
|
|
1546
|
+
// Dump the JSON to CLI and let NodeJS deal with truncation
|
|
1547
|
+
|
|
1548
|
+
utils.logger.log('Diff scan result:');
|
|
1549
|
+
utils.logger.log(require$$1.inspect(result.data, {
|
|
1550
|
+
showHidden: false,
|
|
1551
|
+
depth: depth > 0 ? depth : null,
|
|
1552
|
+
colors: true,
|
|
1553
|
+
maxArrayLength: null
|
|
1554
|
+
}));
|
|
1555
|
+
utils.logger.info(`\n 📝 To display the detailed report in the terminal, use the --json flag. For a friendlier report, use the --markdown flag.\n`);
|
|
1556
|
+
utils.logger.info(dashboardMessage);
|
|
1557
|
+
}
|
|
1558
|
+
async function handleJson(data, file, dashboardMessage) {
|
|
1559
|
+
const json = utils.serializeResultJson(data);
|
|
1560
|
+
if (file && file !== '-') {
|
|
1561
|
+
utils.logger.log(`Writing json to \`${file}\``);
|
|
1562
|
+
u.writeFile(file, json, err => {
|
|
1563
|
+
if (err) {
|
|
1564
|
+
utils.logger.fail(`Writing to \`${file}\` failed...`);
|
|
1565
|
+
utils.logger.error(err);
|
|
1566
|
+
} else {
|
|
1567
|
+
utils.logger.success(`Data successfully written to \`${utils.fileLink(file)}\``);
|
|
1568
|
+
}
|
|
1569
|
+
utils.logger.error(dashboardMessage);
|
|
1570
|
+
});
|
|
1571
|
+
} else {
|
|
1572
|
+
// only .log goes to stdout
|
|
1573
|
+
utils.logger.info(`\n Diff scan result: \n`);
|
|
1574
|
+
utils.logger.log(json);
|
|
1575
|
+
utils.logger.info(dashboardMessage);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
async function handleMarkdown(data) {
|
|
1579
|
+
const SOCKET_SBOM_URL_PREFIX = `${constants.default.SOCKET_WEBSITE_URL}/dashboard/org/SocketDev/sbom/`;
|
|
1580
|
+
const diffScan = data.diff_scan;
|
|
1581
|
+
const beforeScan = diffScan.before_full_scan;
|
|
1582
|
+
const afterScan = diffScan.after_full_scan;
|
|
1583
|
+
utils.logger.log('# Scan diff result');
|
|
1584
|
+
utils.logger.log('');
|
|
1585
|
+
utils.logger.log('This Socket.dev report shows the changes between two scans:');
|
|
1586
|
+
utils.logger.log(`- [${beforeScan.id}](${SOCKET_SBOM_URL_PREFIX}${beforeScan.id})`);
|
|
1587
|
+
utils.logger.log(`- [${afterScan.id}](${SOCKET_SBOM_URL_PREFIX}${afterScan.id})`);
|
|
1588
|
+
utils.logger.log('');
|
|
1589
|
+
utils.logger.log(`You can [view this report in your dashboard](${diffScan.html_url})`);
|
|
1590
|
+
utils.logger.log('');
|
|
1591
|
+
utils.logger.log('## Changes');
|
|
1592
|
+
utils.logger.log('');
|
|
1593
|
+
utils.logger.log(`- Added packages: ${diffScan.artifacts.added.length}`);
|
|
1594
|
+
if (diffScan.artifacts.added.length > 0) {
|
|
1595
|
+
diffScan.artifacts.added.slice(0, 10).forEach(artifact => {
|
|
1596
|
+
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
1597
|
+
});
|
|
1598
|
+
if (diffScan.artifacts.added.length > 10) {
|
|
1599
|
+
utils.logger.log(` ... and ${diffScan.artifacts.added.length - 10} more`);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
utils.logger.log(`- Removed packages: ${diffScan.artifacts.removed.length}`);
|
|
1603
|
+
if (diffScan.artifacts.removed.length > 0) {
|
|
1604
|
+
diffScan.artifacts.removed.slice(0, 10).forEach(artifact => {
|
|
1605
|
+
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
1606
|
+
});
|
|
1607
|
+
if (diffScan.artifacts.removed.length > 10) {
|
|
1608
|
+
utils.logger.log(` ... and ${diffScan.artifacts.removed.length - 10} more`);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
utils.logger.log(`- Replaced packages: ${diffScan.artifacts.replaced.length}`);
|
|
1612
|
+
if (diffScan.artifacts.replaced.length > 0) {
|
|
1613
|
+
diffScan.artifacts.replaced.slice(0, 10).forEach(artifact => {
|
|
1614
|
+
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
1615
|
+
});
|
|
1616
|
+
if (diffScan.artifacts.replaced.length > 10) {
|
|
1617
|
+
utils.logger.log(` ... and ${diffScan.artifacts.replaced.length - 10} more`);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
utils.logger.log(`- Updated packages: ${diffScan.artifacts.updated.length}`);
|
|
1621
|
+
if (diffScan.artifacts.updated.length > 0) {
|
|
1622
|
+
diffScan.artifacts.updated.slice(0, 10).forEach(artifact => {
|
|
1623
|
+
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
1624
|
+
});
|
|
1625
|
+
if (diffScan.artifacts.updated.length > 10) {
|
|
1626
|
+
utils.logger.log(` ... and ${diffScan.artifacts.updated.length - 10} more`);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
const unchanged = diffScan.artifacts.unchanged ?? [];
|
|
1630
|
+
utils.logger.log(`- Unchanged packages: ${unchanged.length}`);
|
|
1631
|
+
if (unchanged.length > 0) {
|
|
1632
|
+
const firstUpToTen = unchanged.slice(0, 10);
|
|
1633
|
+
for (const artifact of firstUpToTen) {
|
|
1634
|
+
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
1635
|
+
}
|
|
1636
|
+
if (unchanged.length > 10) {
|
|
1637
|
+
utils.logger.log(` ... and ${unchanged.length - 10} more`);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
utils.logger.log('');
|
|
1641
|
+
utils.logger.log(`## Scan ${beforeScan.id}`);
|
|
1642
|
+
utils.logger.log('');
|
|
1643
|
+
utils.logger.log('This Scan was considered to be the "base" / "from" / "before" Scan.');
|
|
1644
|
+
utils.logger.log('');
|
|
1645
|
+
for (const {
|
|
1646
|
+
0: key,
|
|
1647
|
+
1: value
|
|
1648
|
+
} of Object.entries(beforeScan)) {
|
|
1649
|
+
if (key === 'pull_request' && !value) {
|
|
1650
|
+
continue;
|
|
1651
|
+
}
|
|
1652
|
+
if (!['id', 'organization_id', 'repository_id'].includes(key)) {
|
|
1653
|
+
utils.logger.group(`- ${key === 'repository_slug' ? 'repo' : key === 'organization_slug' ? 'org' : key}: ${value}`);
|
|
1654
|
+
utils.logger.groupEnd();
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
utils.logger.log('');
|
|
1658
|
+
utils.logger.log(`## Scan ${afterScan.id}`);
|
|
1659
|
+
utils.logger.log('');
|
|
1660
|
+
utils.logger.log('This Scan was considered to be the "head" / "to" / "after" Scan.');
|
|
1661
|
+
utils.logger.log('');
|
|
1662
|
+
for (const {
|
|
1663
|
+
0: key,
|
|
1664
|
+
1: value
|
|
1665
|
+
} of Object.entries(afterScan)) {
|
|
1666
|
+
if (key === 'pull_request' && !value) {
|
|
1667
|
+
continue;
|
|
1668
|
+
}
|
|
1669
|
+
if (!['id', 'organization_id', 'repository_id'].includes(key)) {
|
|
1670
|
+
utils.logger.group(`- ${key === 'repository_slug' ? 'repo' : key === 'organization_slug' ? 'org' : key}: ${value}`);
|
|
1671
|
+
utils.logger.groupEnd();
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
utils.logger.log('');
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
async function handleDiffScan({
|
|
1678
|
+
depth,
|
|
1679
|
+
file,
|
|
1680
|
+
id1,
|
|
1681
|
+
id2,
|
|
1682
|
+
orgSlug,
|
|
1683
|
+
outputKind,
|
|
1684
|
+
strictBlocking
|
|
1685
|
+
}) {
|
|
1686
|
+
const data = await fetchDiffScan({
|
|
1687
|
+
id1,
|
|
1688
|
+
id2,
|
|
1689
|
+
orgSlug
|
|
1690
|
+
});
|
|
1691
|
+
await outputDiffScan(data, {
|
|
1692
|
+
depth,
|
|
1693
|
+
file,
|
|
1694
|
+
outputKind,
|
|
1695
|
+
strictBlocking
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
async function handlePrDiffScan({
|
|
1699
|
+
id1,
|
|
1700
|
+
id2,
|
|
1701
|
+
onDiffReport,
|
|
1702
|
+
orgSlug,
|
|
1703
|
+
outputKind
|
|
1704
|
+
}) {
|
|
1705
|
+
const result = await fetchDiffScan({
|
|
1706
|
+
id1,
|
|
1707
|
+
id2,
|
|
1708
|
+
orgSlug
|
|
1709
|
+
});
|
|
1710
|
+
await outputDiffScan(result, {
|
|
1711
|
+
depth: 2,
|
|
1712
|
+
file: '',
|
|
1713
|
+
outputKind,
|
|
1714
|
+
strictBlocking: false
|
|
1715
|
+
});
|
|
1716
|
+
if (result.ok) {
|
|
1717
|
+
await onDiffReport?.(result.data.diff_scan.id);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1188
1721
|
/** Fetch the scan data needed to generate a report. */
|
|
1189
1722
|
async function fetchScanData(orgSlug, scanId, options) {
|
|
1190
1723
|
const {
|
|
@@ -1506,7 +2039,7 @@ async function outputScanReport(result, {
|
|
|
1506
2039
|
short
|
|
1507
2040
|
}) {
|
|
1508
2041
|
if (!result.ok) {
|
|
1509
|
-
|
|
2042
|
+
utils.setCiExitCode('api', result.code ?? 1);
|
|
1510
2043
|
}
|
|
1511
2044
|
if (!result.ok) {
|
|
1512
2045
|
if (outputKind === constants.OUTPUT_JSON) {
|
|
@@ -1526,7 +2059,7 @@ async function outputScanReport(result, {
|
|
|
1526
2059
|
});
|
|
1527
2060
|
if (!scanReport.ok) {
|
|
1528
2061
|
// Note: This means generation failed, it does not reflect the healthy state.
|
|
1529
|
-
|
|
2062
|
+
utils.setCiExitCode('infrastructure', scanReport.code ?? 1);
|
|
1530
2063
|
|
|
1531
2064
|
// If report generation somehow failed then .data should not be set.
|
|
1532
2065
|
if (outputKind === constants.OUTPUT_JSON) {
|
|
@@ -1538,7 +2071,7 @@ async function outputScanReport(result, {
|
|
|
1538
2071
|
}
|
|
1539
2072
|
if (!scanReport.data.healthy) {
|
|
1540
2073
|
// When report contains healthy: false, process should exit with non-zero code.
|
|
1541
|
-
|
|
2074
|
+
utils.setCiExitCode('blocking');
|
|
1542
2075
|
}
|
|
1543
2076
|
|
|
1544
2077
|
// I don't think we emit the default error message with banner for an unhealthy report, do we?
|
|
@@ -1674,6 +2207,7 @@ async function handleScanReport({
|
|
|
1674
2207
|
|
|
1675
2208
|
async function outputCreateNewScan(result, options) {
|
|
1676
2209
|
const {
|
|
2210
|
+
failureKind = 'infrastructure',
|
|
1677
2211
|
interactive = false,
|
|
1678
2212
|
outputKind = 'text',
|
|
1679
2213
|
reachabilityFallback,
|
|
@@ -1683,7 +2217,7 @@ async function outputCreateNewScan(result, options) {
|
|
|
1683
2217
|
...options
|
|
1684
2218
|
};
|
|
1685
2219
|
if (!result.ok) {
|
|
1686
|
-
|
|
2220
|
+
utils.setCiExitCode(failureKind, result.code ?? 1);
|
|
1687
2221
|
}
|
|
1688
2222
|
const wasSpinning = !!spinner?.isSpinning;
|
|
1689
2223
|
spinner?.stop();
|
|
@@ -1707,7 +2241,7 @@ async function outputCreateNewScan(result, options) {
|
|
|
1707
2241
|
}
|
|
1708
2242
|
if (!result.data.id) {
|
|
1709
2243
|
utils.logger.fail('Did not receive a scan ID from the API.');
|
|
1710
|
-
|
|
2244
|
+
utils.setCiExitCode('api');
|
|
1711
2245
|
}
|
|
1712
2246
|
if (outputKind === 'markdown') {
|
|
1713
2247
|
utils.logger.log('# Create New Scan');
|
|
@@ -1887,7 +2421,7 @@ async function performReachabilityAnalysis(options) {
|
|
|
1887
2421
|
}
|
|
1888
2422
|
|
|
1889
2423
|
// Build Coana arguments.
|
|
1890
|
-
const coanaArgs = ['run', analysisTarget, '--output-dir', path.dirname(outputFilePath), '--socket-mode', outputFilePath, '--disable-report-submission', ...(isOmittedReachValue(reachabilityOptions.reachAnalysisTimeout) ? [] : ['--analysis-timeout', reachabilityOptions.reachAnalysisTimeout]), ...(isOmittedReachValue(reachabilityOptions.reachAnalysisMemoryLimit) ? [] : ['--memory-limit', reachabilityOptions.reachAnalysisMemoryLimit]), ...(reachabilityOptions.reachConcurrency ? ['--concurrency', `${reachabilityOptions.reachConcurrency}`] : []), ...(reachabilityOptions.reachContinueOnAnalysisErrors ? ['--reach-continue-on-analysis-errors'] : []), ...(reachabilityOptions.reachContinueOnInstallErrors ? ['--reach-continue-on-install-errors'] : []), ...(reachabilityOptions.reachContinueOnMissingLockFiles ? ['--reach-continue-on-missing-lock-files'] : []), ...(reachabilityOptions.reachContinueOnNoSourceFiles ? ['--reach-continue-on-no-source-files'] : []), ...(reachabilityOptions.reachDebug ? ['--debug'] : []), ...(reachabilityOptions.reachDetailedAnalysisLogFile ? ['--print-analysis-log-file'] : []), ...(reachabilityOptions.reachDisableAnalytics ? ['--disable-analytics-sharing'] : []), ...(reachabilityOptions.reachDisableDependencyDownloads ? [
|
|
2424
|
+
const coanaArgs = ['run', analysisTarget, '--output-dir', path.dirname(outputFilePath), '--socket-mode', outputFilePath, '--disable-report-submission', ...(isOmittedReachValue(reachabilityOptions.reachAnalysisTimeout) ? [] : ['--analysis-timeout', reachabilityOptions.reachAnalysisTimeout]), ...(isOmittedReachValue(reachabilityOptions.reachAnalysisMemoryLimit) ? [] : ['--memory-limit', reachabilityOptions.reachAnalysisMemoryLimit]), ...(reachabilityOptions.reachConcurrency ? ['--concurrency', `${reachabilityOptions.reachConcurrency}`] : []), ...(reachabilityOptions.reachContinueOnAnalysisErrors ? ['--reach-continue-on-analysis-errors'] : []), ...(reachabilityOptions.reachContinueOnInstallErrors ? ['--reach-continue-on-install-errors'] : []), ...(reachabilityOptions.reachContinueOnMissingLockFiles ? ['--reach-continue-on-missing-lock-files'] : []), ...(reachabilityOptions.reachContinueOnNoSourceFiles ? ['--reach-continue-on-no-source-files'] : []), ...(reachabilityOptions.reachDebug ? ['--debug'] : []), ...(reachabilityOptions.reachDetailedAnalysisLogFile ? ['--print-analysis-log-file'] : []), ...(reachabilityOptions.reachDisableAnalytics ? ['--disable-analytics-sharing'] : []), ...(reachabilityOptions.reachDisableDependencyDownloads ? [utils.DISABLE_DEPENDENCY_DOWNLOADS_FLAG] : []), ...(reachabilityOptions.reachDisableExternalToolChecks ? ['--disable-external-tool-checks'] : []),
|
|
1891
2425
|
// Older Coana versions split analyses unless this is passed.
|
|
1892
2426
|
'--disable-analysis-splitting', '--run-without-docker', '--manifests-tar-hash', tarHash,
|
|
1893
2427
|
// Empty reachEcosystems implies scanning all ecosystems.
|
|
@@ -1955,6 +2489,10 @@ async function performReachabilityAnalysis(options) {
|
|
|
1955
2489
|
|
|
1956
2490
|
// The first Coana release with `generate-socket-facts`.
|
|
1957
2491
|
const SOCKET_FACTS_MIN_COANA_VERSION = '15.15.4';
|
|
2492
|
+
|
|
2493
|
+
// The first Coana release whose `generate-socket-facts` takes
|
|
2494
|
+
// `--disable-dependency-downloads`.
|
|
2495
|
+
const OFFLINE_SOCKET_FACTS_MIN_COANA_VERSION = '15.15.8';
|
|
1958
2496
|
const DSI_SETUP_COMMAND = 'socket manifest setup --dynamic-sbom-inference';
|
|
1959
2497
|
const EXCLUDE_PATHS_FLAG = '--exclude-paths';
|
|
1960
2498
|
const REACH_CONTINUE_ON_INSTALL_ERRORS_FLAG = '--reach-continue-on-install-errors';
|
|
@@ -2020,13 +2558,14 @@ async function readResult(resultFile) {
|
|
|
2020
2558
|
}
|
|
2021
2559
|
}
|
|
2022
2560
|
async function runGenerateSocketFacts(request, flags, context) {
|
|
2561
|
+
const offline = !!context.disableDependencyDownloads;
|
|
2023
2562
|
return await utils.withTmpDir('socket-facts-request-', async tmpDir => {
|
|
2024
2563
|
const requestFile = path.join(tmpDir, 'request.json');
|
|
2025
2564
|
const resultFile = path.join(tmpDir, 'result.json');
|
|
2026
2565
|
await u.promises.writeFile(requestFile, JSON.stringify(request), 'utf8');
|
|
2027
|
-
const spawned = await utils.spawnCoana(['generate-socket-facts', '--request', requestFile, '--output-file', resultFile, ...flags], context.orgSlug, {
|
|
2566
|
+
const spawned = await utils.spawnCoana(['generate-socket-facts', '--request', requestFile, '--output-file', resultFile, ...flags, ...(offline ? [utils.DISABLE_DEPENDENCY_DOWNLOADS_FLAG] : [])], context.orgSlug, {
|
|
2028
2567
|
coanaVersion: context.coanaVersion,
|
|
2029
|
-
minimumVersion: SOCKET_FACTS_MIN_COANA_VERSION,
|
|
2568
|
+
minimumVersion: offline ? OFFLINE_SOCKET_FACTS_MIN_COANA_VERSION : SOCKET_FACTS_MIN_COANA_VERSION,
|
|
2030
2569
|
// Redirect Coana's logs to stderr to keep the command's stdout
|
|
2031
2570
|
// machine-readable.
|
|
2032
2571
|
stdio: ['inherit', 2, 'inherit']
|
|
@@ -6937,12 +7476,12 @@ const AUTO_MANIFEST_HINTS = {
|
|
|
6937
7476
|
// others only change the exit code.
|
|
6938
7477
|
function abortFactsRunIfFailed(ecosystem, outcome) {
|
|
6939
7478
|
if (outcome === null) {
|
|
6940
|
-
throw new
|
|
7479
|
+
throw new Error(`Auto-manifest generation failed for the ${ecosystem} project; aborting (see the errors above).`);
|
|
6941
7480
|
}
|
|
6942
7481
|
}
|
|
6943
7482
|
function abortManifestRunIfFailed(ecosystem, beforeExitCode) {
|
|
6944
7483
|
if (process.exitCode && process.exitCode !== beforeExitCode) {
|
|
6945
|
-
throw new
|
|
7484
|
+
throw new Error(`Auto-manifest generation failed for the ${ecosystem} project; aborting (see the errors above).`);
|
|
6946
7485
|
}
|
|
6947
7486
|
}
|
|
6948
7487
|
async function generateAutoManifest({
|
|
@@ -7113,6 +7652,7 @@ function filterToPregeneratedSboms(filepaths, supportedFiles) {
|
|
|
7113
7652
|
}
|
|
7114
7653
|
async function createNewScan({
|
|
7115
7654
|
autoManifest,
|
|
7655
|
+
baselineScanId,
|
|
7116
7656
|
branchName,
|
|
7117
7657
|
commitHash,
|
|
7118
7658
|
commitMessage,
|
|
@@ -7123,6 +7663,7 @@ async function createNewScan({
|
|
|
7123
7663
|
flags: new Set()
|
|
7124
7664
|
},
|
|
7125
7665
|
interactive,
|
|
7666
|
+
onDiffReport,
|
|
7126
7667
|
orgSlug,
|
|
7127
7668
|
outputKind,
|
|
7128
7669
|
pendingHead,
|
|
@@ -7161,6 +7702,7 @@ async function createNewScan({
|
|
|
7161
7702
|
await utils.withTmpDir('socket-auto-manifest-', async manifestTmpDir => {
|
|
7162
7703
|
const factsContext = {
|
|
7163
7704
|
coanaVersion: reach.reachVersion,
|
|
7705
|
+
disableDependencyDownloads: reach.reachDisableDependencyDownloads,
|
|
7164
7706
|
orgSlug,
|
|
7165
7707
|
workDir: reach.runReachabilityAnalysis ? await createSocketFactsWorkDir(path.join(manifestTmpDir, 'socket-facts-work'), 'reachability') : undefined
|
|
7166
7708
|
};
|
|
@@ -7224,6 +7766,7 @@ async function createNewScan({
|
|
|
7224
7766
|
supportedFilesCResult
|
|
7225
7767
|
});
|
|
7226
7768
|
await outputCreateNewScan(supportedFilesCResult, {
|
|
7769
|
+
failureKind: 'api',
|
|
7227
7770
|
interactive,
|
|
7228
7771
|
outputKind
|
|
7229
7772
|
});
|
|
@@ -7384,16 +7927,26 @@ async function createNewScan({
|
|
|
7384
7927
|
}
|
|
7385
7928
|
if (report && fullScanCResult.ok) {
|
|
7386
7929
|
if (scanId) {
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7930
|
+
if (baselineScanId) {
|
|
7931
|
+
await handlePrDiffScan({
|
|
7932
|
+
id1: baselineScanId,
|
|
7933
|
+
id2: scanId,
|
|
7934
|
+
onDiffReport,
|
|
7935
|
+
orgSlug,
|
|
7936
|
+
outputKind
|
|
7937
|
+
});
|
|
7938
|
+
} else {
|
|
7939
|
+
await handleScanReport({
|
|
7940
|
+
filepath: '-',
|
|
7941
|
+
fold: constants.default.FOLD_SETTING_VERSION,
|
|
7942
|
+
includeLicensePolicy: true,
|
|
7943
|
+
orgSlug,
|
|
7944
|
+
outputKind,
|
|
7945
|
+
reportLevel,
|
|
7946
|
+
scanId,
|
|
7947
|
+
short: false
|
|
7948
|
+
});
|
|
7949
|
+
}
|
|
7397
7950
|
} else {
|
|
7398
7951
|
await outputCreateNewScan({
|
|
7399
7952
|
ok: false,
|
|
@@ -7401,6 +7954,7 @@ async function createNewScan({
|
|
|
7401
7954
|
cause: 'Server did not respond with a scan ID',
|
|
7402
7955
|
data: fullScanCResult.data
|
|
7403
7956
|
}, {
|
|
7957
|
+
failureKind: 'api',
|
|
7404
7958
|
interactive,
|
|
7405
7959
|
outputKind,
|
|
7406
7960
|
reachabilityFallback
|
|
@@ -7409,6 +7963,7 @@ async function createNewScan({
|
|
|
7409
7963
|
} else {
|
|
7410
7964
|
spinner.stop();
|
|
7411
7965
|
await outputCreateNewScan(fullScanCResult, {
|
|
7966
|
+
failureKind: 'api',
|
|
7412
7967
|
interactive,
|
|
7413
7968
|
outputKind,
|
|
7414
7969
|
reachabilityFallback
|
|
@@ -7425,16 +7980,6 @@ async function handleCreateNewScan(config) {
|
|
|
7425
7980
|
}
|
|
7426
7981
|
}
|
|
7427
7982
|
|
|
7428
|
-
/**
|
|
7429
|
-
* Derive the pull request number from the CI environment. GitHub Actions
|
|
7430
|
-
* pull_request events check out `refs/pull/<n>/merge`, so the number is
|
|
7431
|
-
* recoverable from GITHUB_REF; returns 0 outside a PR run (the API omits
|
|
7432
|
-
* `pull_request` for falsy values).
|
|
7433
|
-
*/
|
|
7434
|
-
function detectCiPullRequestNumber() {
|
|
7435
|
-
const match = /^refs\/pull\/(\d+)\//.exec(envHelpers.envAsString(process.env['GITHUB_REF']));
|
|
7436
|
-
return match ? Number(match[1]) : 0;
|
|
7437
|
-
}
|
|
7438
7983
|
async function handleCi(autoManifest) {
|
|
7439
7984
|
utils.debugFn('notice', 'Starting CI scan');
|
|
7440
7985
|
utils.debugDir('inspect', {
|
|
@@ -7446,15 +7991,35 @@ async function handleCi(autoManifest) {
|
|
|
7446
7991
|
utils.debugDir('inspect', {
|
|
7447
7992
|
orgSlugCResult
|
|
7448
7993
|
});
|
|
7449
|
-
|
|
7994
|
+
utils.setCiExitCode('api', orgSlugCResult.code ?? 1);
|
|
7450
7995
|
// Always assume json mode.
|
|
7451
7996
|
utils.logger.log(utils.serializeResultJson(orgSlugCResult));
|
|
7452
7997
|
return;
|
|
7453
7998
|
}
|
|
7454
7999
|
const orgSlug = orgSlugCResult.data;
|
|
8000
|
+
const pullRequestContext = await detectCiPullRequestContext();
|
|
8001
|
+
const {
|
|
8002
|
+
number: pullRequest
|
|
8003
|
+
} = pullRequestContext;
|
|
7455
8004
|
const cwd = process.cwd();
|
|
7456
8005
|
const branchName = (await utils.gitBranch(cwd)) || (await utils.detectDefaultBranch(cwd));
|
|
7457
8006
|
const repoName = await utils.getRepoName(cwd);
|
|
8007
|
+
let baselineScanId;
|
|
8008
|
+
if (pullRequest) {
|
|
8009
|
+
const baselineCResult = await selectBaselineScan({
|
|
8010
|
+
branch: pullRequestContext.baseBranch ?? '',
|
|
8011
|
+
commitHash: pullRequestContext.baseCommitHash ?? '',
|
|
8012
|
+
orgSlug,
|
|
8013
|
+
repo: repoName
|
|
8014
|
+
});
|
|
8015
|
+
if (!baselineCResult.ok) {
|
|
8016
|
+
process.exitCode = baselineCResult.code ?? 1;
|
|
8017
|
+
utils.logger.log(utils.serializeResultJson(baselineCResult));
|
|
8018
|
+
return;
|
|
8019
|
+
}
|
|
8020
|
+
baselineScanId = baselineCResult.data.id;
|
|
8021
|
+
utils.debugFn('notice', `Selected PR baseline scan ${baselineScanId}`);
|
|
8022
|
+
}
|
|
7458
8023
|
utils.debugFn('notice', `CI scan for ${orgSlug}/${repoName} on branch ${branchName}`);
|
|
7459
8024
|
utils.debugDir('inspect', {
|
|
7460
8025
|
orgSlug,
|
|
@@ -7462,6 +8027,7 @@ async function handleCi(autoManifest) {
|
|
|
7462
8027
|
branchName,
|
|
7463
8028
|
repoName
|
|
7464
8029
|
});
|
|
8030
|
+
const [owner, repo] = constants.default.ENV.GITHUB_REPOSITORY.split('/');
|
|
7465
8031
|
await handleCreateNewScan({
|
|
7466
8032
|
autoManifest,
|
|
7467
8033
|
branchName,
|
|
@@ -7475,7 +8041,28 @@ async function handleCi(autoManifest) {
|
|
|
7475
8041
|
outputKind: 'json',
|
|
7476
8042
|
// When 'pendingHead' is true, it requires 'branchName' set and 'tmp' false.
|
|
7477
8043
|
pendingHead: true,
|
|
7478
|
-
pullRequest
|
|
8044
|
+
pullRequest,
|
|
8045
|
+
baselineScanId,
|
|
8046
|
+
onDiffReport: async diffScanId => {
|
|
8047
|
+
if (pullRequestContext.provider !== 'github' || !owner || !repo || !constants.default.ENV.SOCKET_CLI_GITHUB_TOKEN) {
|
|
8048
|
+
return;
|
|
8049
|
+
}
|
|
8050
|
+
try {
|
|
8051
|
+
await publishPullRequestComments({
|
|
8052
|
+
diffScanId,
|
|
8053
|
+
disableOverview: envHelpers.envAsBoolean(process.env['SOCKET_CLI_DISABLE_OVERVIEW_COMMENT']),
|
|
8054
|
+
disableSecurity: envHelpers.envAsBoolean(process.env['SOCKET_CLI_DISABLE_SECURITY_COMMENT']),
|
|
8055
|
+
orgSlug,
|
|
8056
|
+
owner,
|
|
8057
|
+
pullRequest,
|
|
8058
|
+
repo,
|
|
8059
|
+
serverUrl: constants.default.ENV.GITHUB_SERVER_URL
|
|
8060
|
+
});
|
|
8061
|
+
} catch (error) {
|
|
8062
|
+
utils.debugFn('warn', 'Could not publish pull request comments', error);
|
|
8063
|
+
process.stderr.write('Socket could not publish the scan comments. Check the Socket API scopes and GitHub pull request write permission.\n');
|
|
8064
|
+
}
|
|
8065
|
+
},
|
|
7479
8066
|
reach: {
|
|
7480
8067
|
dynamicSbomInference: undefined,
|
|
7481
8068
|
excludePaths: [],
|
|
@@ -7522,6 +8109,16 @@ const config$o = {
|
|
|
7522
8109
|
// Dev tools in CI environments are not likely to be set up, so this is safer.
|
|
7523
8110
|
default: false,
|
|
7524
8111
|
description: 'Auto generate manifest files where detected? See autoManifest flag in `socket scan create`'
|
|
8112
|
+
},
|
|
8113
|
+
disableBlocking: {
|
|
8114
|
+
type: 'boolean',
|
|
8115
|
+
default: false,
|
|
8116
|
+
description: 'Return success for findings and infrastructure failures, but keep usage errors non-zero.'
|
|
8117
|
+
},
|
|
8118
|
+
exitCodeOnApiError: {
|
|
8119
|
+
type: 'number',
|
|
8120
|
+
default: 3,
|
|
8121
|
+
description: 'Exit code for Socket API errors (default: 3). Ignored with --disable-blocking.'
|
|
7525
8122
|
}
|
|
7526
8123
|
},
|
|
7527
8124
|
help: (command, _config) => `
|
|
@@ -7533,8 +8130,10 @@ const config$o = {
|
|
|
7533
8130
|
|
|
7534
8131
|
This command is intended to use in CI runs to allow automated systems to
|
|
7535
8132
|
accept or reject a current build. It will use the default org of the
|
|
7536
|
-
Socket API token.
|
|
7537
|
-
|
|
8133
|
+
Socket API token. Exit codes are 0 for success, 1 for blocking findings, 2
|
|
8134
|
+
for usage errors, 3 for infrastructure errors, and 130 for interruption.
|
|
8135
|
+
--disable-blocking returns 0 for findings and runtime failures, but not
|
|
8136
|
+
usage errors. --exit-code-on-api-error changes the API failure code.
|
|
7538
8137
|
|
|
7539
8138
|
The --auto-manifest flag does the same as the one from \`socket scan create\`
|
|
7540
8139
|
but is not enabled by default since the CI is less likely to be set up with
|
|
@@ -7544,6 +8143,8 @@ const config$o = {
|
|
|
7544
8143
|
Examples
|
|
7545
8144
|
$ ${command}
|
|
7546
8145
|
$ ${command} --auto-manifest
|
|
8146
|
+
$ ${command} --disable-blocking
|
|
8147
|
+
$ ${command} --exit-code-on-api-error 5
|
|
7547
8148
|
`
|
|
7548
8149
|
};
|
|
7549
8150
|
const cmdCI = {
|
|
@@ -7565,6 +8166,16 @@ async function run$U(argv, importMeta, {
|
|
|
7565
8166
|
utils.logger.log(constants.default.DRY_RUN_BAILING_NOW);
|
|
7566
8167
|
return;
|
|
7567
8168
|
}
|
|
8169
|
+
const exitCodeOnApiError = Number(cli.flags['exitCodeOnApiError']);
|
|
8170
|
+
utils.setCiExitCodePolicy({
|
|
8171
|
+
disableBlocking: Boolean(cli.flags['disableBlocking']),
|
|
8172
|
+
exitCodeOnApiError
|
|
8173
|
+
});
|
|
8174
|
+
if (!Number.isInteger(exitCodeOnApiError) || exitCodeOnApiError < 0 || exitCodeOnApiError > 255) {
|
|
8175
|
+
utils.logger.fail('--exit-code-on-api-error must be an integer from 0 to 255.');
|
|
8176
|
+
utils.setCiExitCode('usage');
|
|
8177
|
+
return;
|
|
8178
|
+
}
|
|
7568
8179
|
await handleCi(Boolean(cli.flags['autoManifest']));
|
|
7569
8180
|
}
|
|
7570
8181
|
|
|
@@ -11376,13 +11987,6 @@ async function runCdxgen(argvObj) {
|
|
|
11376
11987
|
u.rmSync(`./${PACKAGE_LOCK_JSON}`);
|
|
11377
11988
|
} catch {}
|
|
11378
11989
|
}
|
|
11379
|
-
const outputPath = argvMutable['output'];
|
|
11380
|
-
if (outputPath) {
|
|
11381
|
-
const fullOutputPath = path.join(process.cwd(), outputPath);
|
|
11382
|
-
if (u.existsSync(fullOutputPath)) {
|
|
11383
|
-
utils.logger.log(vendor.yoctocolorsCjsExports.cyanBright(`${outputPath} created!`));
|
|
11384
|
-
}
|
|
11385
|
-
}
|
|
11386
11990
|
});
|
|
11387
11991
|
return shadowResult;
|
|
11388
11992
|
}
|
|
@@ -11692,8 +12296,8 @@ Only one npm project is supported in this standalone build. Other cdxgen modes a
|
|
|
11692
12296
|
process.exitCode = 128 + (os.constants.signals[result.signal] ?? 1);
|
|
11693
12297
|
} else {
|
|
11694
12298
|
process.exitCode = typeof result.code === 'number' ? result.code : 1;
|
|
11695
|
-
if (result.code === 0
|
|
11696
|
-
|
|
12299
|
+
if (result.code === 0) {
|
|
12300
|
+
await reportOutput(yargv.output);
|
|
11697
12301
|
}
|
|
11698
12302
|
}
|
|
11699
12303
|
return;
|
|
@@ -11703,12 +12307,36 @@ Only one npm project is supported in this standalone build. Other cdxgen modes a
|
|
|
11703
12307
|
spawnPromise.process.on('exit', (code, signalName) => {
|
|
11704
12308
|
if (signalName) {
|
|
11705
12309
|
process.kill(process.pid, signalName);
|
|
11706
|
-
} else if (
|
|
12310
|
+
} else if (code) {
|
|
11707
12311
|
// eslint-disable-next-line n/no-process-exit
|
|
11708
12312
|
process.exit(code);
|
|
11709
12313
|
}
|
|
11710
12314
|
});
|
|
11711
12315
|
await spawnPromise;
|
|
12316
|
+
process.exitCode = 0;
|
|
12317
|
+
if (!yargv.help && !yargv.version && !yargv.server) {
|
|
12318
|
+
await reportOutput(yargv.output);
|
|
12319
|
+
}
|
|
12320
|
+
}
|
|
12321
|
+
async function reportOutput(output) {
|
|
12322
|
+
if (typeof output !== 'string' || !output || output === '-') {
|
|
12323
|
+
return;
|
|
12324
|
+
}
|
|
12325
|
+
const outputPath = path.resolve(output);
|
|
12326
|
+
if (!u.existsSync(outputPath)) {
|
|
12327
|
+
return;
|
|
12328
|
+
}
|
|
12329
|
+
utils.logger.log(vendor.yoctocolorsCjsExports.cyanBright(`${output} created!`));
|
|
12330
|
+
let bom;
|
|
12331
|
+
try {
|
|
12332
|
+
bom = JSON.parse(await fs.readFile(outputPath, 'utf8'));
|
|
12333
|
+
} catch {
|
|
12334
|
+
return;
|
|
12335
|
+
}
|
|
12336
|
+
if (Array.isArray(bom?.components) && bom.components.length === 0) {
|
|
12337
|
+
const fix = utils.isSea() ? 'Check whether the project lockfile lists the expected dependencies, then rerun.' : 'Fix any dependency errors shown by cdxgen, then rerun.\n In CI, pass --fail-on-error to stop on dependency extraction errors.';
|
|
12338
|
+
utils.logger.warn(`Empty SBOM in ${JSON.stringify(output)}. The "components" array has 0 entries.\n ${fix}`);
|
|
12339
|
+
}
|
|
11712
12340
|
}
|
|
11713
12341
|
|
|
11714
12342
|
function canonicalizeForContainment(filePath) {
|
|
@@ -18245,7 +18873,7 @@ async function run$s(argv, importMeta, {
|
|
|
18245
18873
|
interactive: {
|
|
18246
18874
|
type: 'boolean',
|
|
18247
18875
|
default: true,
|
|
18248
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
18876
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
18249
18877
|
},
|
|
18250
18878
|
org: {
|
|
18251
18879
|
type: 'string',
|
|
@@ -18381,7 +19009,7 @@ async function run$r(argv, importMeta, {
|
|
|
18381
19009
|
interactive: {
|
|
18382
19010
|
type: 'boolean',
|
|
18383
19011
|
default: true,
|
|
18384
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
19012
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
18385
19013
|
},
|
|
18386
19014
|
org: {
|
|
18387
19015
|
type: 'string',
|
|
@@ -19943,7 +20571,7 @@ async function run$i(argv, importMeta, {
|
|
|
19943
20571
|
interactive: {
|
|
19944
20572
|
type: 'boolean',
|
|
19945
20573
|
default: true,
|
|
19946
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
20574
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
19947
20575
|
},
|
|
19948
20576
|
org: {
|
|
19949
20577
|
type: 'string',
|
|
@@ -20092,7 +20720,7 @@ async function run$h(argv, importMeta, {
|
|
|
20092
20720
|
interactive: {
|
|
20093
20721
|
type: 'boolean',
|
|
20094
20722
|
default: true,
|
|
20095
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
20723
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
20096
20724
|
},
|
|
20097
20725
|
org: {
|
|
20098
20726
|
type: 'string',
|
|
@@ -20375,7 +21003,7 @@ async function run$g(argv, importMeta, {
|
|
|
20375
21003
|
interactive: {
|
|
20376
21004
|
type: 'boolean',
|
|
20377
21005
|
default: true,
|
|
20378
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
21006
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
20379
21007
|
},
|
|
20380
21008
|
org: {
|
|
20381
21009
|
type: 'string',
|
|
@@ -20580,7 +21208,7 @@ async function run$f(argv, importMeta, {
|
|
|
20580
21208
|
interactive: {
|
|
20581
21209
|
type: 'boolean',
|
|
20582
21210
|
default: true,
|
|
20583
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
21211
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
20584
21212
|
},
|
|
20585
21213
|
org: {
|
|
20586
21214
|
type: 'string',
|
|
@@ -20754,7 +21382,7 @@ async function run$e(argv, importMeta, {
|
|
|
20754
21382
|
interactive: {
|
|
20755
21383
|
type: 'boolean',
|
|
20756
21384
|
default: true,
|
|
20757
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
21385
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
20758
21386
|
},
|
|
20759
21387
|
org: {
|
|
20760
21388
|
type: 'string',
|
|
@@ -21149,7 +21777,7 @@ const generalFlags$1 = {
|
|
|
21149
21777
|
interactive: {
|
|
21150
21778
|
type: 'boolean',
|
|
21151
21779
|
default: true,
|
|
21152
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
21780
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
21153
21781
|
},
|
|
21154
21782
|
pullRequest: {
|
|
21155
21783
|
type: 'number',
|
|
@@ -21614,318 +22242,118 @@ async function fetchDeleteOrgFullScan(orgSlug, scanId, options) {
|
|
|
21614
22242
|
...options
|
|
21615
22243
|
};
|
|
21616
22244
|
const sockSdkCResult = await utils.setupSdk(sdkOpts);
|
|
21617
|
-
if (!sockSdkCResult.ok) {
|
|
21618
|
-
return sockSdkCResult;
|
|
21619
|
-
}
|
|
21620
|
-
const sockSdk = sockSdkCResult.data;
|
|
21621
|
-
return await utils.handleApiCall(sockSdk.deleteFullScan(orgSlug, scanId), {
|
|
21622
|
-
description: 'to delete a scan'
|
|
21623
|
-
});
|
|
21624
|
-
}
|
|
21625
|
-
|
|
21626
|
-
async function outputDeleteScan(result, outputKind) {
|
|
21627
|
-
if (!result.ok) {
|
|
21628
|
-
process.exitCode = result.code ?? 1;
|
|
21629
|
-
}
|
|
21630
|
-
if (outputKind === 'json') {
|
|
21631
|
-
utils.logger.log(utils.serializeResultJson(result));
|
|
21632
|
-
return;
|
|
21633
|
-
}
|
|
21634
|
-
if (!result.ok) {
|
|
21635
|
-
utils.logger.fail(utils.failMsgWithBadge(result.message, result.cause));
|
|
21636
|
-
return;
|
|
21637
|
-
}
|
|
21638
|
-
utils.logger.success('Scan deleted successfully');
|
|
21639
|
-
}
|
|
21640
|
-
|
|
21641
|
-
async function handleDeleteScan(orgSlug, scanId, outputKind) {
|
|
21642
|
-
const data = await fetchDeleteOrgFullScan(orgSlug, scanId);
|
|
21643
|
-
await outputDeleteScan(data, outputKind);
|
|
21644
|
-
}
|
|
21645
|
-
|
|
21646
|
-
const CMD_NAME$9 = 'del';
|
|
21647
|
-
const description$b = 'Delete a scan';
|
|
21648
|
-
const hidden$9 = false;
|
|
21649
|
-
const cmdScanDel = {
|
|
21650
|
-
description: description$b,
|
|
21651
|
-
hidden: hidden$9,
|
|
21652
|
-
run: run$c
|
|
21653
|
-
};
|
|
21654
|
-
async function run$c(argv, importMeta, {
|
|
21655
|
-
parentName
|
|
21656
|
-
}) {
|
|
21657
|
-
const config = {
|
|
21658
|
-
commandName: CMD_NAME$9,
|
|
21659
|
-
description: description$b,
|
|
21660
|
-
hidden: hidden$9,
|
|
21661
|
-
flags: {
|
|
21662
|
-
...flags.commonFlags,
|
|
21663
|
-
...flags.outputFlags,
|
|
21664
|
-
interactive: {
|
|
21665
|
-
type: 'boolean',
|
|
21666
|
-
default: true,
|
|
21667
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no.'
|
|
21668
|
-
},
|
|
21669
|
-
org: {
|
|
21670
|
-
type: 'string',
|
|
21671
|
-
description: 'Force override the organization slug, overrides the default org from config'
|
|
21672
|
-
}
|
|
21673
|
-
},
|
|
21674
|
-
help: (command, config) => `
|
|
21675
|
-
Usage
|
|
21676
|
-
$ ${command} [options] <SCAN_ID>
|
|
21677
|
-
|
|
21678
|
-
API Token Requirements
|
|
21679
|
-
${utils.getFlagApiRequirementsOutput(`${parentName}:${CMD_NAME$9}`)}
|
|
21680
|
-
|
|
21681
|
-
Options
|
|
21682
|
-
${utils.getFlagListOutput(config.flags)}
|
|
21683
|
-
|
|
21684
|
-
Examples
|
|
21685
|
-
$ ${command} 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
21686
|
-
$ ${command} 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json
|
|
21687
|
-
`
|
|
21688
|
-
};
|
|
21689
|
-
const cli = utils.meowOrExit({
|
|
21690
|
-
argv,
|
|
21691
|
-
config,
|
|
21692
|
-
importMeta,
|
|
21693
|
-
parentName
|
|
21694
|
-
});
|
|
21695
|
-
const {
|
|
21696
|
-
json,
|
|
21697
|
-
markdown,
|
|
21698
|
-
org: orgFlag
|
|
21699
|
-
} = cli.flags;
|
|
21700
|
-
const dryRun = !!cli.flags['dryRun'];
|
|
21701
|
-
const interactive = !!cli.flags['interactive'];
|
|
21702
|
-
const [scanId = ''] = cli.input;
|
|
21703
|
-
const hasApiToken = utils.hasDefaultApiToken();
|
|
21704
|
-
const [orgSlug, defaultOrgSlug] = await utils.determineOrgSlug(String(orgFlag || ''), interactive, dryRun);
|
|
21705
|
-
const outputKind = utils.getOutputKind(json, markdown);
|
|
21706
|
-
const wasValidInput = utils.checkCommandInput(outputKind, {
|
|
21707
|
-
nook: !!defaultOrgSlug,
|
|
21708
|
-
test: !!orgSlug,
|
|
21709
|
-
message: 'Org name by default setting, --org, or auto-discovered',
|
|
21710
|
-
fail: 'missing'
|
|
21711
|
-
}, {
|
|
21712
|
-
test: !!scanId,
|
|
21713
|
-
message: 'Scan ID to delete',
|
|
21714
|
-
fail: 'missing'
|
|
21715
|
-
}, {
|
|
21716
|
-
nook: true,
|
|
21717
|
-
test: dryRun || hasApiToken,
|
|
21718
|
-
message: 'This command requires a Socket API token for access',
|
|
21719
|
-
fail: 'try `socket login`'
|
|
21720
|
-
});
|
|
21721
|
-
if (!wasValidInput) {
|
|
21722
|
-
return;
|
|
21723
|
-
}
|
|
21724
|
-
if (dryRun) {
|
|
21725
|
-
utils.logger.log(constants.default.DRY_RUN_BAILING_NOW);
|
|
21726
|
-
return;
|
|
21727
|
-
}
|
|
21728
|
-
await handleDeleteScan(orgSlug, scanId, outputKind);
|
|
21729
|
-
}
|
|
21730
|
-
|
|
21731
|
-
async function fetchDiffScan({
|
|
21732
|
-
id1,
|
|
21733
|
-
id2,
|
|
21734
|
-
orgSlug
|
|
21735
|
-
}) {
|
|
21736
|
-
utils.logger.info('Scan ID 1:', id1);
|
|
21737
|
-
utils.logger.info('Scan ID 2:', id2);
|
|
21738
|
-
utils.logger.info('Note: this request may take some time if the scans are big');
|
|
21739
|
-
return await utils.queryApiSafeJson(`orgs/${orgSlug}/full-scans/diff?before=${encodeURIComponent(id1)}&after=${encodeURIComponent(id2)}`, 'a scan diff');
|
|
21740
|
-
}
|
|
21741
|
-
|
|
21742
|
-
async function outputDiffScan(result, {
|
|
21743
|
-
depth,
|
|
21744
|
-
file,
|
|
21745
|
-
outputKind
|
|
21746
|
-
}) {
|
|
21747
|
-
if (!result.ok) {
|
|
21748
|
-
process.exitCode = result.code ?? 1;
|
|
21749
|
-
}
|
|
21750
|
-
if (!result.ok) {
|
|
21751
|
-
if (outputKind === 'json') {
|
|
21752
|
-
utils.logger.log(utils.serializeResultJson(result));
|
|
21753
|
-
return;
|
|
21754
|
-
}
|
|
21755
|
-
utils.logger.fail(utils.failMsgWithBadge(result.message, result.cause));
|
|
21756
|
-
return;
|
|
21757
|
-
}
|
|
21758
|
-
if (!('before' in result.data)) {
|
|
21759
|
-
if (outputKind === 'json' || file) {
|
|
21760
|
-
await handleJson(result, file, '');
|
|
21761
|
-
} else {
|
|
21762
|
-
utils.logger.info(`Diff scan ${result.data.id} is ${result.data.status}. Run this command again when it completes.`);
|
|
21763
|
-
}
|
|
21764
|
-
return;
|
|
21765
|
-
}
|
|
21766
|
-
const dashboardUrl = result.data.diff_report_url;
|
|
21767
|
-
const dashboardMessage = dashboardUrl ? `\n View this diff scan in the Socket dashboard: ${vendor.yoctocolorsCjsExports.cyan(dashboardUrl)}` : '';
|
|
21768
|
-
|
|
21769
|
-
// When forcing json, or dumping to file, serialize to string such that it
|
|
21770
|
-
// won't get truncated. The only way to dump the full raw JSON to stdout is
|
|
21771
|
-
// to use `--json --file -` (the dash is a standard notation for stdout)
|
|
21772
|
-
if (outputKind === 'json' || file) {
|
|
21773
|
-
await handleJson(result, file, dashboardMessage);
|
|
21774
|
-
return;
|
|
21775
|
-
}
|
|
21776
|
-
if (outputKind === 'markdown') {
|
|
21777
|
-
await handleMarkdown(result.data);
|
|
21778
|
-
return;
|
|
21779
|
-
}
|
|
21780
|
-
|
|
21781
|
-
// In this case neither the --json nor the --file flag was passed
|
|
21782
|
-
// Dump the JSON to CLI and let NodeJS deal with truncation
|
|
21783
|
-
|
|
21784
|
-
utils.logger.log('Diff scan result:');
|
|
21785
|
-
utils.logger.log(require$$1.inspect(result.data, {
|
|
21786
|
-
showHidden: false,
|
|
21787
|
-
depth: depth > 0 ? depth : null,
|
|
21788
|
-
colors: true,
|
|
21789
|
-
maxArrayLength: null
|
|
21790
|
-
}));
|
|
21791
|
-
utils.logger.info(`\n 📝 To display the detailed report in the terminal, use the --json flag. For a friendlier report, use the --markdown flag.\n`);
|
|
21792
|
-
utils.logger.info(dashboardMessage);
|
|
21793
|
-
}
|
|
21794
|
-
async function handleJson(data, file, dashboardMessage) {
|
|
21795
|
-
const json = utils.serializeResultJson(data);
|
|
21796
|
-
if (file && file !== '-') {
|
|
21797
|
-
utils.logger.log(`Writing json to \`${file}\``);
|
|
21798
|
-
u.writeFile(file, json, err => {
|
|
21799
|
-
if (err) {
|
|
21800
|
-
utils.logger.fail(`Writing to \`${file}\` failed...`);
|
|
21801
|
-
utils.logger.error(err);
|
|
21802
|
-
} else {
|
|
21803
|
-
utils.logger.success(`Data successfully written to \`${utils.fileLink(file)}\``);
|
|
21804
|
-
}
|
|
21805
|
-
utils.logger.error(dashboardMessage);
|
|
21806
|
-
});
|
|
21807
|
-
} else {
|
|
21808
|
-
// only .log goes to stdout
|
|
21809
|
-
utils.logger.info(`\n Diff scan result: \n`);
|
|
21810
|
-
utils.logger.log(json);
|
|
21811
|
-
utils.logger.info(dashboardMessage);
|
|
21812
|
-
}
|
|
21813
|
-
}
|
|
21814
|
-
async function handleMarkdown(data) {
|
|
21815
|
-
const SOCKET_SBOM_URL_PREFIX = `${constants.default.SOCKET_WEBSITE_URL}/dashboard/org/SocketDev/sbom/`;
|
|
21816
|
-
utils.logger.log('# Scan diff result');
|
|
21817
|
-
utils.logger.log('');
|
|
21818
|
-
utils.logger.log('This Socket.dev report shows the changes between two scans:');
|
|
21819
|
-
utils.logger.log(`- [${data.before.id}](${SOCKET_SBOM_URL_PREFIX}${data.before.id})`);
|
|
21820
|
-
utils.logger.log(`- [${data.after.id}](${SOCKET_SBOM_URL_PREFIX}${data.after.id})`);
|
|
21821
|
-
utils.logger.log('');
|
|
21822
|
-
utils.logger.log(`You can [view this report in your dashboard](${data.diff_report_url})`);
|
|
21823
|
-
utils.logger.log('');
|
|
21824
|
-
utils.logger.log('## Changes');
|
|
21825
|
-
utils.logger.log('');
|
|
21826
|
-
utils.logger.log(`- directDependenciesChanged: ${data.directDependenciesChanged}`);
|
|
21827
|
-
utils.logger.log(`- Added packages: ${data.artifacts.added.length}`);
|
|
21828
|
-
if (data.artifacts.added.length > 0) {
|
|
21829
|
-
data.artifacts.added.slice(0, 10).forEach(artifact => {
|
|
21830
|
-
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
21831
|
-
});
|
|
21832
|
-
if (data.artifacts.added.length > 10) {
|
|
21833
|
-
utils.logger.log(` ... and ${data.artifacts.added.length - 10} more`);
|
|
21834
|
-
}
|
|
21835
|
-
}
|
|
21836
|
-
utils.logger.log(`- Removed packages: ${data.artifacts.removed.length}`);
|
|
21837
|
-
if (data.artifacts.removed.length > 0) {
|
|
21838
|
-
data.artifacts.removed.slice(0, 10).forEach(artifact => {
|
|
21839
|
-
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
21840
|
-
});
|
|
21841
|
-
if (data.artifacts.removed.length > 10) {
|
|
21842
|
-
utils.logger.log(` ... and ${data.artifacts.removed.length - 10} more`);
|
|
21843
|
-
}
|
|
21844
|
-
}
|
|
21845
|
-
utils.logger.log(`- Replaced packages: ${data.artifacts.replaced.length}`);
|
|
21846
|
-
if (data.artifacts.replaced.length > 0) {
|
|
21847
|
-
data.artifacts.replaced.slice(0, 10).forEach(artifact => {
|
|
21848
|
-
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
21849
|
-
});
|
|
21850
|
-
if (data.artifacts.replaced.length > 10) {
|
|
21851
|
-
utils.logger.log(` ... and ${data.artifacts.replaced.length - 10} more`);
|
|
21852
|
-
}
|
|
21853
|
-
}
|
|
21854
|
-
utils.logger.log(`- Updated packages: ${data.artifacts.updated.length}`);
|
|
21855
|
-
if (data.artifacts.updated.length > 0) {
|
|
21856
|
-
data.artifacts.updated.slice(0, 10).forEach(artifact => {
|
|
21857
|
-
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
21858
|
-
});
|
|
21859
|
-
if (data.artifacts.updated.length > 10) {
|
|
21860
|
-
utils.logger.log(` ... and ${data.artifacts.updated.length - 10} more`);
|
|
21861
|
-
}
|
|
21862
|
-
}
|
|
21863
|
-
const unchanged = data.artifacts.unchanged ?? [];
|
|
21864
|
-
utils.logger.log(`- Unchanged packages: ${unchanged.length}`);
|
|
21865
|
-
if (unchanged.length > 0) {
|
|
21866
|
-
const firstUpToTen = unchanged.slice(0, 10);
|
|
21867
|
-
for (const artifact of firstUpToTen) {
|
|
21868
|
-
utils.logger.log(` - ${artifact.type} ${artifact.name}@${artifact.version}`);
|
|
21869
|
-
}
|
|
21870
|
-
if (unchanged.length > 10) {
|
|
21871
|
-
utils.logger.log(` ... and ${unchanged.length - 10} more`);
|
|
21872
|
-
}
|
|
21873
|
-
}
|
|
21874
|
-
utils.logger.log('');
|
|
21875
|
-
utils.logger.log(`## Scan ${data.before.id}`);
|
|
21876
|
-
utils.logger.log('');
|
|
21877
|
-
utils.logger.log('This Scan was considered to be the "base" / "from" / "before" Scan.');
|
|
21878
|
-
utils.logger.log('');
|
|
21879
|
-
for (const {
|
|
21880
|
-
0: key,
|
|
21881
|
-
1: value
|
|
21882
|
-
} of Object.entries(data.before)) {
|
|
21883
|
-
if (key === 'pull_request' && !value) {
|
|
21884
|
-
continue;
|
|
21885
|
-
}
|
|
21886
|
-
if (!['id', 'organization_id', 'repository_id'].includes(key)) {
|
|
21887
|
-
utils.logger.group(`- ${key === 'repository_slug' ? 'repo' : key === 'organization_slug' ? 'org' : key}: ${value}`);
|
|
21888
|
-
utils.logger.groupEnd();
|
|
21889
|
-
}
|
|
22245
|
+
if (!sockSdkCResult.ok) {
|
|
22246
|
+
return sockSdkCResult;
|
|
21890
22247
|
}
|
|
21891
|
-
|
|
21892
|
-
utils.
|
|
21893
|
-
|
|
21894
|
-
|
|
21895
|
-
|
|
21896
|
-
|
|
21897
|
-
|
|
21898
|
-
|
|
21899
|
-
|
|
21900
|
-
if (key === 'pull_request' && !value) {
|
|
21901
|
-
continue;
|
|
21902
|
-
}
|
|
21903
|
-
if (!['id', 'organization_id', 'repository_id'].includes(key)) {
|
|
21904
|
-
utils.logger.group(`- ${key === 'repository_slug' ? 'repo' : key === 'organization_slug' ? 'org' : key}: ${value}`);
|
|
21905
|
-
utils.logger.groupEnd();
|
|
21906
|
-
}
|
|
22248
|
+
const sockSdk = sockSdkCResult.data;
|
|
22249
|
+
return await utils.handleApiCall(sockSdk.deleteFullScan(orgSlug, scanId), {
|
|
22250
|
+
description: 'to delete a scan'
|
|
22251
|
+
});
|
|
22252
|
+
}
|
|
22253
|
+
|
|
22254
|
+
async function outputDeleteScan(result, outputKind) {
|
|
22255
|
+
if (!result.ok) {
|
|
22256
|
+
process.exitCode = result.code ?? 1;
|
|
21907
22257
|
}
|
|
21908
|
-
|
|
22258
|
+
if (outputKind === 'json') {
|
|
22259
|
+
utils.logger.log(utils.serializeResultJson(result));
|
|
22260
|
+
return;
|
|
22261
|
+
}
|
|
22262
|
+
if (!result.ok) {
|
|
22263
|
+
utils.logger.fail(utils.failMsgWithBadge(result.message, result.cause));
|
|
22264
|
+
return;
|
|
22265
|
+
}
|
|
22266
|
+
utils.logger.success('Scan deleted successfully');
|
|
21909
22267
|
}
|
|
21910
22268
|
|
|
21911
|
-
async function
|
|
21912
|
-
|
|
21913
|
-
|
|
21914
|
-
|
|
21915
|
-
|
|
21916
|
-
|
|
21917
|
-
|
|
22269
|
+
async function handleDeleteScan(orgSlug, scanId, outputKind) {
|
|
22270
|
+
const data = await fetchDeleteOrgFullScan(orgSlug, scanId);
|
|
22271
|
+
await outputDeleteScan(data, outputKind);
|
|
22272
|
+
}
|
|
22273
|
+
|
|
22274
|
+
const CMD_NAME$9 = 'del';
|
|
22275
|
+
const description$b = 'Delete a scan';
|
|
22276
|
+
const hidden$9 = false;
|
|
22277
|
+
const cmdScanDel = {
|
|
22278
|
+
description: description$b,
|
|
22279
|
+
hidden: hidden$9,
|
|
22280
|
+
run: run$c
|
|
22281
|
+
};
|
|
22282
|
+
async function run$c(argv, importMeta, {
|
|
22283
|
+
parentName
|
|
21918
22284
|
}) {
|
|
21919
|
-
const
|
|
21920
|
-
|
|
21921
|
-
|
|
21922
|
-
|
|
22285
|
+
const config = {
|
|
22286
|
+
commandName: CMD_NAME$9,
|
|
22287
|
+
description: description$b,
|
|
22288
|
+
hidden: hidden$9,
|
|
22289
|
+
flags: {
|
|
22290
|
+
...flags.commonFlags,
|
|
22291
|
+
...flags.outputFlags,
|
|
22292
|
+
interactive: {
|
|
22293
|
+
type: 'boolean',
|
|
22294
|
+
default: true,
|
|
22295
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
22296
|
+
},
|
|
22297
|
+
org: {
|
|
22298
|
+
type: 'string',
|
|
22299
|
+
description: 'Force override the organization slug, overrides the default org from config'
|
|
22300
|
+
}
|
|
22301
|
+
},
|
|
22302
|
+
help: (command, config) => `
|
|
22303
|
+
Usage
|
|
22304
|
+
$ ${command} [options] <SCAN_ID>
|
|
22305
|
+
|
|
22306
|
+
API Token Requirements
|
|
22307
|
+
${utils.getFlagApiRequirementsOutput(`${parentName}:${CMD_NAME$9}`)}
|
|
22308
|
+
|
|
22309
|
+
Options
|
|
22310
|
+
${utils.getFlagListOutput(config.flags)}
|
|
22311
|
+
|
|
22312
|
+
Examples
|
|
22313
|
+
$ ${command} 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
22314
|
+
$ ${command} 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json
|
|
22315
|
+
`
|
|
22316
|
+
};
|
|
22317
|
+
const cli = utils.meowOrExit({
|
|
22318
|
+
argv,
|
|
22319
|
+
config,
|
|
22320
|
+
importMeta,
|
|
22321
|
+
parentName
|
|
21923
22322
|
});
|
|
21924
|
-
|
|
21925
|
-
|
|
21926
|
-
|
|
21927
|
-
|
|
22323
|
+
const {
|
|
22324
|
+
json,
|
|
22325
|
+
markdown,
|
|
22326
|
+
org: orgFlag
|
|
22327
|
+
} = cli.flags;
|
|
22328
|
+
const dryRun = !!cli.flags['dryRun'];
|
|
22329
|
+
const interactive = !!cli.flags['interactive'];
|
|
22330
|
+
const [scanId = ''] = cli.input;
|
|
22331
|
+
const hasApiToken = utils.hasDefaultApiToken();
|
|
22332
|
+
const [orgSlug, defaultOrgSlug] = await utils.determineOrgSlug(String(orgFlag || ''), interactive, dryRun);
|
|
22333
|
+
const outputKind = utils.getOutputKind(json, markdown);
|
|
22334
|
+
const wasValidInput = utils.checkCommandInput(outputKind, {
|
|
22335
|
+
nook: !!defaultOrgSlug,
|
|
22336
|
+
test: !!orgSlug,
|
|
22337
|
+
message: 'Org name by default setting, --org, or auto-discovered',
|
|
22338
|
+
fail: 'missing'
|
|
22339
|
+
}, {
|
|
22340
|
+
test: !!scanId,
|
|
22341
|
+
message: 'Scan ID to delete',
|
|
22342
|
+
fail: 'missing'
|
|
22343
|
+
}, {
|
|
22344
|
+
nook: true,
|
|
22345
|
+
test: dryRun || hasApiToken,
|
|
22346
|
+
message: 'This command requires a Socket API token for access',
|
|
22347
|
+
fail: 'try `socket login`'
|
|
21928
22348
|
});
|
|
22349
|
+
if (!wasValidInput) {
|
|
22350
|
+
return;
|
|
22351
|
+
}
|
|
22352
|
+
if (dryRun) {
|
|
22353
|
+
utils.logger.log(constants.default.DRY_RUN_BAILING_NOW);
|
|
22354
|
+
return;
|
|
22355
|
+
}
|
|
22356
|
+
await handleDeleteScan(orgSlug, scanId, outputKind);
|
|
21929
22357
|
}
|
|
21930
22358
|
|
|
21931
22359
|
const CMD_NAME$8 = 'diff';
|
|
@@ -21960,11 +22388,16 @@ async function run$b(argv, importMeta, {
|
|
|
21960
22388
|
interactive: {
|
|
21961
22389
|
type: 'boolean',
|
|
21962
22390
|
default: true,
|
|
21963
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
22391
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
21964
22392
|
},
|
|
21965
22393
|
org: {
|
|
21966
22394
|
type: 'string',
|
|
21967
22395
|
description: 'Force override the organization slug, overrides the default org from config'
|
|
22396
|
+
},
|
|
22397
|
+
strictBlocking: {
|
|
22398
|
+
type: 'boolean',
|
|
22399
|
+
default: false,
|
|
22400
|
+
description: 'Fail when unchanged blocking alerts are present in the scan diff'
|
|
21968
22401
|
}
|
|
21969
22402
|
},
|
|
21970
22403
|
help: (command, config) => `
|
|
@@ -21988,6 +22421,7 @@ async function run$b(argv, importMeta, {
|
|
|
21988
22421
|
Examples
|
|
21989
22422
|
$ ${command} aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
|
|
21990
22423
|
$ ${command} aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 aaa1aa1a-aaaa-1111-1a1a-1111111a11a1 --json
|
|
22424
|
+
$ ${command} aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 aaa1aa1a-aaaa-1111-1a1a-1111111a11a1 --strict-blocking
|
|
21991
22425
|
`
|
|
21992
22426
|
};
|
|
21993
22427
|
const cli = utils.meowOrExit({
|
|
@@ -22004,7 +22438,8 @@ async function run$b(argv, importMeta, {
|
|
|
22004
22438
|
file,
|
|
22005
22439
|
json,
|
|
22006
22440
|
markdown,
|
|
22007
|
-
org: orgFlag
|
|
22441
|
+
org: orgFlag,
|
|
22442
|
+
strictBlocking
|
|
22008
22443
|
} = cli.flags;
|
|
22009
22444
|
const interactive = !!cli.flags['interactive'];
|
|
22010
22445
|
let [id1 = '', id2 = ''] = cli.input;
|
|
@@ -22053,7 +22488,8 @@ async function run$b(argv, importMeta, {
|
|
|
22053
22488
|
depth,
|
|
22054
22489
|
orgSlug,
|
|
22055
22490
|
outputKind,
|
|
22056
|
-
file
|
|
22491
|
+
file,
|
|
22492
|
+
strictBlocking
|
|
22057
22493
|
});
|
|
22058
22494
|
}
|
|
22059
22495
|
|
|
@@ -22866,7 +23302,7 @@ async function run$a(argv, importMeta, {
|
|
|
22866
23302
|
interactive: {
|
|
22867
23303
|
type: 'boolean',
|
|
22868
23304
|
default: true,
|
|
22869
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
23305
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
22870
23306
|
},
|
|
22871
23307
|
org: {
|
|
22872
23308
|
type: 'string',
|
|
@@ -23033,52 +23469,6 @@ async function run$a(argv, importMeta, {
|
|
|
23033
23469
|
});
|
|
23034
23470
|
}
|
|
23035
23471
|
|
|
23036
|
-
async function fetchOrgFullScanList(config, options) {
|
|
23037
|
-
const {
|
|
23038
|
-
sdkOpts
|
|
23039
|
-
} = {
|
|
23040
|
-
__proto__: null,
|
|
23041
|
-
...options
|
|
23042
|
-
};
|
|
23043
|
-
const sockSdkCResult = await utils.setupSdk(sdkOpts);
|
|
23044
|
-
if (!sockSdkCResult.ok) {
|
|
23045
|
-
return sockSdkCResult;
|
|
23046
|
-
}
|
|
23047
|
-
const sockSdk = sockSdkCResult.data;
|
|
23048
|
-
const {
|
|
23049
|
-
branch,
|
|
23050
|
-
direction,
|
|
23051
|
-
from_time,
|
|
23052
|
-
orgSlug,
|
|
23053
|
-
page,
|
|
23054
|
-
perPage,
|
|
23055
|
-
repo,
|
|
23056
|
-
sort
|
|
23057
|
-
} = {
|
|
23058
|
-
__proto__: null,
|
|
23059
|
-
...config
|
|
23060
|
-
};
|
|
23061
|
-
return await utils.handleApiCall(sockSdk.listFullScans(orgSlug, {
|
|
23062
|
-
...(branch ? {
|
|
23063
|
-
branch
|
|
23064
|
-
} : {}),
|
|
23065
|
-
...(repo ? {
|
|
23066
|
-
repo
|
|
23067
|
-
} : {}),
|
|
23068
|
-
...(sort ? {
|
|
23069
|
-
sort: sort
|
|
23070
|
-
} : {}),
|
|
23071
|
-
...(direction ? {
|
|
23072
|
-
direction: direction
|
|
23073
|
-
} : {}),
|
|
23074
|
-
from: from_time,
|
|
23075
|
-
page,
|
|
23076
|
-
per_page: perPage
|
|
23077
|
-
}), {
|
|
23078
|
-
description: 'list of scans'
|
|
23079
|
-
});
|
|
23080
|
-
}
|
|
23081
|
-
|
|
23082
23472
|
// @ts-ignore
|
|
23083
23473
|
async function outputListScans(result, outputKind) {
|
|
23084
23474
|
if (!result.ok) {
|
|
@@ -23187,7 +23577,7 @@ async function run$9(argv, importMeta, {
|
|
|
23187
23577
|
interactive: {
|
|
23188
23578
|
type: 'boolean',
|
|
23189
23579
|
default: true,
|
|
23190
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
23580
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
23191
23581
|
},
|
|
23192
23582
|
page: {
|
|
23193
23583
|
type: 'number',
|
|
@@ -23380,7 +23770,7 @@ async function run$8(argv, importMeta, {
|
|
|
23380
23770
|
interactive: {
|
|
23381
23771
|
type: 'boolean',
|
|
23382
23772
|
default: true,
|
|
23383
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
23773
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
23384
23774
|
},
|
|
23385
23775
|
org: {
|
|
23386
23776
|
type: 'string',
|
|
@@ -23512,6 +23902,7 @@ dsi) {
|
|
|
23512
23902
|
dynamicResult = await runDynamicSbomInference({
|
|
23513
23903
|
context: {
|
|
23514
23904
|
coanaVersion: reachabilityOptions.reachVersion,
|
|
23905
|
+
disableDependencyDownloads: reachabilityOptions.reachDisableDependencyDownloads,
|
|
23515
23906
|
orgSlug,
|
|
23516
23907
|
workDir: dsi.workDir
|
|
23517
23908
|
},
|
|
@@ -23871,7 +24262,7 @@ async function run$6(argv, importMeta, {
|
|
|
23871
24262
|
interactive: {
|
|
23872
24263
|
type: 'boolean',
|
|
23873
24264
|
default: true,
|
|
23874
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
24265
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
23875
24266
|
},
|
|
23876
24267
|
org: {
|
|
23877
24268
|
type: 'string',
|
|
@@ -24367,74 +24758,6 @@ async function run$5(argv, importMeta, {
|
|
|
24367
24758
|
await handleScanConfig(cwd, Boolean(defaultOnReadError));
|
|
24368
24759
|
}
|
|
24369
24760
|
|
|
24370
|
-
// HTTP 202 Accepted: cached results are still being computed; poll again.
|
|
24371
|
-
const HTTP_STATUS_ACCEPTED = 202;
|
|
24372
|
-
const CACHED_POLL_INITIAL_DELAY_MS = 1000;
|
|
24373
|
-
const CACHED_POLL_MAX_DELAY_MS = 10_000;
|
|
24374
|
-
const CACHED_POLL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
24375
|
-
function sleep(ms) {
|
|
24376
|
-
return new Promise(resolve => {
|
|
24377
|
-
setTimeout(resolve, ms);
|
|
24378
|
-
});
|
|
24379
|
-
}
|
|
24380
|
-
async function fetchScan(orgSlug, scanId) {
|
|
24381
|
-
// Serve pre-computed results from the immutable store (`?cached=true`): a
|
|
24382
|
-
// 200 carries the ndjson body, a 202 means the server enqueued a background
|
|
24383
|
-
// job to compute them — poll with backoff until the results are ready, so
|
|
24384
|
-
// callers only ever observe the final scan.
|
|
24385
|
-
const path = `orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}?cached=true`;
|
|
24386
|
-
const deadline = Date.now() + CACHED_POLL_TIMEOUT_MS;
|
|
24387
|
-
let delayMs = CACHED_POLL_INITIAL_DELAY_MS;
|
|
24388
|
-
for (;;) {
|
|
24389
|
-
// eslint-disable-next-line no-await-in-loop
|
|
24390
|
-
const result = await utils.queryApiSafeTextWithStatus(path, 'a scan');
|
|
24391
|
-
if (!result.ok) {
|
|
24392
|
-
return result;
|
|
24393
|
-
}
|
|
24394
|
-
if (result.data.status !== HTTP_STATUS_ACCEPTED) {
|
|
24395
|
-
return parseArtifactsNdjson(result.data.text);
|
|
24396
|
-
}
|
|
24397
|
-
if (Date.now() >= deadline) {
|
|
24398
|
-
return {
|
|
24399
|
-
ok: false,
|
|
24400
|
-
message: 'Scan results not ready',
|
|
24401
|
-
cause: `The Socket API is still computing cached results for scan ${scanId} after ${CACHED_POLL_TIMEOUT_MS / 60_000} minutes (path: ${path}). Retry in a few minutes — the server keeps computing in the background.`
|
|
24402
|
-
};
|
|
24403
|
-
}
|
|
24404
|
-
// eslint-disable-next-line no-await-in-loop
|
|
24405
|
-
await sleep(delayMs);
|
|
24406
|
-
delayMs = Math.min(delayMs * 2, CACHED_POLL_MAX_DELAY_MS);
|
|
24407
|
-
}
|
|
24408
|
-
}
|
|
24409
|
-
function parseArtifactsNdjson(jsonsString) {
|
|
24410
|
-
// This is nd-json; each line is a json object.
|
|
24411
|
-
const lines = jsonsString.split('\n').filter(Boolean);
|
|
24412
|
-
const data = [];
|
|
24413
|
-
for (let i = 0, {
|
|
24414
|
-
length
|
|
24415
|
-
} = lines; i < length; i += 1) {
|
|
24416
|
-
const line = lines[i];
|
|
24417
|
-
try {
|
|
24418
|
-
data.push(JSON.parse(line));
|
|
24419
|
-
} catch (e) {
|
|
24420
|
-
utils.debugFn('error', 'Failed to parse scan result line as JSON');
|
|
24421
|
-
utils.debugDir('error', {
|
|
24422
|
-
error: e,
|
|
24423
|
-
line
|
|
24424
|
-
});
|
|
24425
|
-
return {
|
|
24426
|
-
ok: false,
|
|
24427
|
-
message: 'Invalid Socket API response',
|
|
24428
|
-
cause: 'The Socket API responded with at least one line that was not valid JSON. Please report if this persists.'
|
|
24429
|
-
};
|
|
24430
|
-
}
|
|
24431
|
-
}
|
|
24432
|
-
return {
|
|
24433
|
-
ok: true,
|
|
24434
|
-
data
|
|
24435
|
-
};
|
|
24436
|
-
}
|
|
24437
|
-
|
|
24438
24761
|
async function outputScanView(result, orgSlug, scanId, filePath, outputKind) {
|
|
24439
24762
|
if (!result.ok) {
|
|
24440
24763
|
process.exitCode = result.code ?? 1;
|
|
@@ -24559,7 +24882,7 @@ async function run$4(argv, importMeta, {
|
|
|
24559
24882
|
interactive: {
|
|
24560
24883
|
type: 'boolean',
|
|
24561
24884
|
default: true,
|
|
24562
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
24885
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
24563
24886
|
},
|
|
24564
24887
|
org: {
|
|
24565
24888
|
type: 'string',
|
|
@@ -24900,7 +25223,7 @@ async function run$3(argv, importMeta, {
|
|
|
24900
25223
|
interactive: {
|
|
24901
25224
|
type: 'boolean',
|
|
24902
25225
|
default: true,
|
|
24903
|
-
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions
|
|
25226
|
+
description: 'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions,\ndefaulting them to cancel/no.'
|
|
24904
25227
|
},
|
|
24905
25228
|
org: {
|
|
24906
25229
|
type: 'string',
|
|
@@ -25687,11 +26010,14 @@ void (async () => {
|
|
|
25687
26010
|
}, {
|
|
25688
26011
|
aliases: rootAliases
|
|
25689
26012
|
});
|
|
26013
|
+
if (constants.default.abortSignal.aborted && utils.hasCiExitCodePolicy()) {
|
|
26014
|
+
utils.setCiExitCode('interrupted');
|
|
26015
|
+
}
|
|
25690
26016
|
|
|
25691
26017
|
// Track successful CLI completion.
|
|
25692
26018
|
await utils.trackCliComplete(process.argv, cliStartTime, process.exitCode);
|
|
25693
26019
|
} catch (e) {
|
|
25694
|
-
|
|
26020
|
+
utils.setCiExitCode(e instanceof utils.InputError ? 'usage' : constants.default.abortSignal.aborted ? 'interrupted' : 'infrastructure');
|
|
25695
26021
|
|
|
25696
26022
|
// Track CLI error for telemetry.
|
|
25697
26023
|
await utils.trackCliError(process.argv, cliStartTime, e, process.exitCode);
|
|
@@ -25789,5 +26115,5 @@ process.on('unhandledRejection', async (reason, promise) => {
|
|
|
25789
26115
|
// eslint-disable-next-line n/no-process-exit
|
|
25790
26116
|
process.exit(1);
|
|
25791
26117
|
});
|
|
25792
|
-
//# debugId=
|
|
26118
|
+
//# debugId=d5b06296-80b7-4ae9-ad19-fd2237d217ac
|
|
25793
26119
|
//# sourceMappingURL=cli.js.map
|