@socketsecurity/cli-with-sentry 0.14.49 → 0.14.51
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/dist/constants.d.ts +2 -0
- package/dist/constants.js +6 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +372 -152
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/index.d.ts +1 -1
- package/dist/module-sync/index.js +32 -24
- package/dist/module-sync/index.js.map +1 -1
- package/dist/module-sync/npm-paths.js +3 -43
- package/dist/module-sync/npm-paths.js.map +1 -1
- package/dist/require/cli.js +372 -152
- package/dist/require/cli.js.map +1 -1
- package/package.json +7 -7
- package/dist/module-sync/logging.d.ts +0 -16
package/dist/require/cli.js
CHANGED
|
@@ -15,6 +15,7 @@ var require$$0 = require('node:url');
|
|
|
15
15
|
var ponyCause = _socketInterop(require('pony-cause'));
|
|
16
16
|
var vendor = require('./vendor.js');
|
|
17
17
|
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
18
|
+
var logger = require('@socketsecurity/registry/lib/logger');
|
|
18
19
|
var micromatch = _socketInterop(require('micromatch'));
|
|
19
20
|
var simpleGit = _socketInterop(require('simple-git'));
|
|
20
21
|
var sdk = require('@socketsecurity/sdk');
|
|
@@ -56,7 +57,9 @@ var npmPaths = require('./npm-paths.js');
|
|
|
56
57
|
var npm$1 = require('./npm.js');
|
|
57
58
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
58
59
|
var config$A = require('@socketsecurity/config');
|
|
60
|
+
var assert = require('node:assert');
|
|
59
61
|
var readline = require('node:readline/promises');
|
|
62
|
+
var childProcess = require('node:child_process');
|
|
60
63
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
61
64
|
var readline$1 = require('node:readline');
|
|
62
65
|
|
|
@@ -1293,7 +1296,7 @@ function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
|
1293
1296
|
spinner.stop();
|
|
1294
1297
|
throw new index.AuthError(message);
|
|
1295
1298
|
}
|
|
1296
|
-
spinner.
|
|
1299
|
+
spinner.errorAndStop(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
1297
1300
|
process$1.exit(1);
|
|
1298
1301
|
}
|
|
1299
1302
|
async function handleApiCall(value, description) {
|
|
@@ -1512,7 +1515,7 @@ function meowOrExit({
|
|
|
1512
1515
|
}
|
|
1513
1516
|
function getAsciiHeader(command) {
|
|
1514
1517
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
|
|
1515
|
-
"0.14.
|
|
1518
|
+
"0.14.51:8252840:e7069cc4:pub";
|
|
1516
1519
|
const nodeVersion = process.version;
|
|
1517
1520
|
const apiToken = index.getSetting('apiToken');
|
|
1518
1521
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -2332,15 +2335,13 @@ async function getDiffScan({
|
|
|
2332
2335
|
orgSlug,
|
|
2333
2336
|
outputJson
|
|
2334
2337
|
}, apiToken) {
|
|
2335
|
-
const
|
|
2336
|
-
|
|
2337
|
-
text: spinnerText
|
|
2338
|
-
}).start();
|
|
2338
|
+
const spinner$1 = new spinner.Spinner();
|
|
2339
|
+
spinner$1.start('Getting diff scan...');
|
|
2339
2340
|
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiToken);
|
|
2340
2341
|
const data = await response.json();
|
|
2341
2342
|
if (!response.ok) {
|
|
2342
2343
|
const err = await handleAPIError(response.status);
|
|
2343
|
-
spinner$1.
|
|
2344
|
+
spinner$1.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
2344
2345
|
return;
|
|
2345
2346
|
}
|
|
2346
2347
|
spinner$1.stop();
|
|
@@ -2512,9 +2513,7 @@ async function runFix() {
|
|
|
2512
2513
|
const tree = arb.idealTree;
|
|
2513
2514
|
const hasUpgrade = !!registry.getManifestData(NPM$d, name);
|
|
2514
2515
|
if (hasUpgrade) {
|
|
2515
|
-
spinner$1.
|
|
2516
|
-
console.log(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2517
|
-
spinner$1.start();
|
|
2516
|
+
spinner$1.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2518
2517
|
continue;
|
|
2519
2518
|
}
|
|
2520
2519
|
const nodes = index.findPackageNodes(tree, name);
|
|
@@ -2540,10 +2539,10 @@ async function runFix() {
|
|
|
2540
2539
|
try {
|
|
2541
2540
|
// eslint-disable-next-line no-await-in-loop
|
|
2542
2541
|
await npm.runScript('test', [], {
|
|
2543
|
-
|
|
2542
|
+
spinner: spinner$1,
|
|
2543
|
+
stdio: 'ignore'
|
|
2544
2544
|
});
|
|
2545
2545
|
spinner$1.info(`Patched ${name} ${oldVersion} -> ${node.version}`);
|
|
2546
|
-
spinner$1.start();
|
|
2547
2546
|
if (isTopLevel(tree, node)) {
|
|
2548
2547
|
for (const depField of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
2549
2548
|
const oldVersion = editablePkgJson.content[depField]?.[name];
|
|
@@ -2557,13 +2556,10 @@ async function runFix() {
|
|
|
2557
2556
|
await editablePkgJson.save();
|
|
2558
2557
|
} catch {
|
|
2559
2558
|
spinner$1.error(`Reverting ${name} to ${oldVersion}`);
|
|
2560
|
-
spinner$1.start();
|
|
2561
2559
|
arb.idealTree = revertToIdealTree;
|
|
2562
2560
|
}
|
|
2563
2561
|
} else {
|
|
2564
|
-
spinner$1.
|
|
2565
|
-
console.log(`Could not patch ${name} ${oldVersion}`);
|
|
2566
|
-
spinner$1.start();
|
|
2562
|
+
spinner$1.error(`Could not patch ${name} ${oldVersion}`);
|
|
2567
2563
|
}
|
|
2568
2564
|
}
|
|
2569
2565
|
}
|
|
@@ -2736,7 +2732,7 @@ function formatPackageInfo({
|
|
|
2736
2732
|
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
2737
2733
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
2738
2734
|
} else {
|
|
2739
|
-
spinner.
|
|
2735
|
+
spinner.successAndStop('Package has no issues');
|
|
2740
2736
|
}
|
|
2741
2737
|
const format = new index.ColorOrMarkdown(!!outputMarkdown);
|
|
2742
2738
|
const url = index.getSocketDevPackageOverviewUrl(NPM$c, pkgName, pkgVersion);
|
|
@@ -2904,9 +2900,8 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2904
2900
|
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
2905
2901
|
apiBaseUrl ??= index.getSetting('apiBaseUrl') ?? undefined;
|
|
2906
2902
|
apiProxy ??= index.getSetting('apiProxy') ?? undefined;
|
|
2907
|
-
const spinner$1 = new spinner.Spinner(
|
|
2908
|
-
|
|
2909
|
-
}).start();
|
|
2903
|
+
const spinner$1 = new spinner.Spinner();
|
|
2904
|
+
spinner$1.start('Verifying API key...');
|
|
2910
2905
|
let orgs;
|
|
2911
2906
|
try {
|
|
2912
2907
|
const sdk = await index.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
@@ -2917,7 +2912,7 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2917
2912
|
orgs = result.data;
|
|
2918
2913
|
spinner$1.success('API key verified');
|
|
2919
2914
|
} catch {
|
|
2920
|
-
spinner$1.
|
|
2915
|
+
spinner$1.errorAndStop('Invalid API key');
|
|
2921
2916
|
return;
|
|
2922
2917
|
}
|
|
2923
2918
|
const enforcedChoices = Object.values(orgs.organizations).filter(org => org?.plan === 'enterprise').map(org => ({
|
|
@@ -2933,6 +2928,8 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2933
2928
|
value: '',
|
|
2934
2929
|
description: 'Pick "None" if this is a personal device'
|
|
2935
2930
|
})
|
|
2931
|
+
}, {
|
|
2932
|
+
spinner: spinner$1
|
|
2936
2933
|
});
|
|
2937
2934
|
if (id) {
|
|
2938
2935
|
enforcedOrgs = [id];
|
|
@@ -2941,6 +2938,8 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2941
2938
|
const confirmOrg = await prompts.confirm({
|
|
2942
2939
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
2943
2940
|
default: true
|
|
2941
|
+
}, {
|
|
2942
|
+
spinner: spinner$1
|
|
2944
2943
|
});
|
|
2945
2944
|
if (confirmOrg) {
|
|
2946
2945
|
const existing = enforcedChoices[0];
|
|
@@ -2952,9 +2951,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2952
2951
|
const oldToken = index.getSetting('apiToken');
|
|
2953
2952
|
try {
|
|
2954
2953
|
applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy);
|
|
2955
|
-
spinner$1.
|
|
2954
|
+
spinner$1.successAndStop(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
2956
2955
|
} catch {
|
|
2957
|
-
spinner$1.
|
|
2956
|
+
spinner$1.errorAndStop(`API login failed`);
|
|
2958
2957
|
}
|
|
2959
2958
|
}
|
|
2960
2959
|
|
|
@@ -3022,9 +3021,9 @@ function applyLogout() {
|
|
|
3022
3021
|
function attemptLogout() {
|
|
3023
3022
|
try {
|
|
3024
3023
|
applyLogout();
|
|
3025
|
-
|
|
3024
|
+
logger.logger.success('Successfully logged out');
|
|
3026
3025
|
} catch {
|
|
3027
|
-
|
|
3026
|
+
logger.logger.error('Failed to complete logout steps');
|
|
3028
3027
|
}
|
|
3029
3028
|
}
|
|
3030
3029
|
|
|
@@ -3091,19 +3090,18 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3091
3090
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
3092
3091
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
3093
3092
|
if (verbose) {
|
|
3094
|
-
|
|
3093
|
+
spinner$1.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
3095
3094
|
}
|
|
3096
3095
|
const output = await spawn(bin, commandArgs, {
|
|
3097
3096
|
cwd: target || '.'
|
|
3098
3097
|
});
|
|
3099
|
-
spinner$1.success();
|
|
3100
3098
|
if (verbose) {
|
|
3101
3099
|
console.group('[VERBOSE] gradle stdout:');
|
|
3102
3100
|
console.log(output);
|
|
3103
3101
|
console.groupEnd();
|
|
3104
3102
|
}
|
|
3105
3103
|
if (output.stderr) {
|
|
3106
|
-
spinner$1.
|
|
3104
|
+
spinner$1.errorAndStop('There were errors while running gradle');
|
|
3107
3105
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3108
3106
|
if (!verbose) {
|
|
3109
3107
|
console.group('[VERBOSE] stderr:');
|
|
@@ -3112,6 +3110,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3112
3110
|
}
|
|
3113
3111
|
process.exit(1);
|
|
3114
3112
|
}
|
|
3113
|
+
spinner$1.successAndStop('Executed gradle successfully');
|
|
3115
3114
|
console.log('Reported exports:');
|
|
3116
3115
|
output.stdout.replace(/^POM file copied to: (.*)/gm, (_all, fn) => {
|
|
3117
3116
|
console.log('- ', fn);
|
|
@@ -3120,7 +3119,7 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3120
3119
|
|
|
3121
3120
|
// const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
|
|
3122
3121
|
// if (!loc) {
|
|
3123
|
-
//
|
|
3122
|
+
// console.error(
|
|
3124
3123
|
// 'There were no errors from sbt but could not find the location of resulting .pom file either'
|
|
3125
3124
|
// )
|
|
3126
3125
|
// process.exit(1)
|
|
@@ -3128,25 +3127,25 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3128
3127
|
//
|
|
3129
3128
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3130
3129
|
// if (out === '-') {
|
|
3131
|
-
// spinner.start('Result:\n```')
|
|
3130
|
+
// spinner.start('Result:\n```')
|
|
3132
3131
|
// console.log(await safeReadFile(loc, 'utf8'))
|
|
3133
3132
|
// console.log('```')
|
|
3134
|
-
// spinner.
|
|
3133
|
+
// spinner.successAndStop(`OK`)
|
|
3135
3134
|
// } else {
|
|
3135
|
+
// spinner.start()
|
|
3136
3136
|
// if (verbose) {
|
|
3137
|
-
// spinner.
|
|
3137
|
+
// spinner.log(
|
|
3138
3138
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3139
3139
|
// )
|
|
3140
3140
|
// } else {
|
|
3141
|
-
// spinner.
|
|
3141
|
+
// spinner.log('Moving output pom file')
|
|
3142
3142
|
// }
|
|
3143
3143
|
// // TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3144
3144
|
// await renamep(loc, out)
|
|
3145
|
-
// spinner.
|
|
3146
|
-
// spinner.start().success(`OK. File should be available in \`${out}\``)
|
|
3145
|
+
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
|
|
3147
3146
|
// }
|
|
3148
3147
|
} catch (e) {
|
|
3149
|
-
spinner$1.
|
|
3148
|
+
spinner$1.errorAndStop('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3150
3149
|
if (verbose) {
|
|
3151
3150
|
console.group('[VERBOSE] error:');
|
|
3152
3151
|
console.log(e);
|
|
@@ -3314,21 +3313,22 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3314
3313
|
const spinner$1 = new spinner.Spinner();
|
|
3315
3314
|
spinner$1.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3316
3315
|
try {
|
|
3317
|
-
// Run sbt with the init script we provide which should yield zero or more
|
|
3318
|
-
// We have to figure out where to store those pom files such that
|
|
3319
|
-
//
|
|
3320
|
-
|
|
3316
|
+
// Run sbt with the init script we provide which should yield zero or more
|
|
3317
|
+
// pom files. We have to figure out where to store those pom files such that
|
|
3318
|
+
// we can upload them and predict them through the GitHub API. We could do a
|
|
3319
|
+
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3320
|
+
// I'd prefer something plain-text if it is to be committed.
|
|
3321
3321
|
const output = await spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3322
3322
|
cwd: target || '.'
|
|
3323
3323
|
});
|
|
3324
|
-
spinner$1.
|
|
3324
|
+
spinner$1.stop();
|
|
3325
3325
|
if (verbose) {
|
|
3326
3326
|
console.group('[VERBOSE] sbt stdout:');
|
|
3327
3327
|
console.log(output);
|
|
3328
3328
|
console.groupEnd();
|
|
3329
3329
|
}
|
|
3330
3330
|
if (output.stderr) {
|
|
3331
|
-
|
|
3331
|
+
logger.logger.error('There were errors while running sbt');
|
|
3332
3332
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3333
3333
|
if (!verbose) {
|
|
3334
3334
|
console.group('[VERBOSE] stderr:');
|
|
@@ -3343,39 +3343,38 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3343
3343
|
return fn;
|
|
3344
3344
|
});
|
|
3345
3345
|
if (!poms.length) {
|
|
3346
|
-
|
|
3346
|
+
logger.logger.error('There were no errors from sbt but it seems to not have generated any poms either');
|
|
3347
3347
|
process.exit(1);
|
|
3348
3348
|
}
|
|
3349
|
-
|
|
3350
3349
|
// Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3351
3350
|
// TODO: what to do with multiple output files? Do we want to dump them to stdout? Raw or with separators or ?
|
|
3352
3351
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
3353
3352
|
if (out === '-' && poms.length === 1) {
|
|
3354
|
-
|
|
3353
|
+
logger.logger.log('Result:\n```');
|
|
3355
3354
|
console.log(await index.safeReadFile(poms[0], 'utf8'));
|
|
3356
|
-
|
|
3357
|
-
|
|
3355
|
+
logger.logger.log('```');
|
|
3356
|
+
logger.logger.success(`OK`);
|
|
3358
3357
|
} else if (out === '-') {
|
|
3359
|
-
|
|
3358
|
+
logger.logger.error('Requested out target was stdout but there are multiple generated files');
|
|
3360
3359
|
poms.forEach(fn => console.error('-', fn));
|
|
3361
3360
|
console.error('Exiting now...');
|
|
3362
3361
|
process.exit(1);
|
|
3363
3362
|
} else {
|
|
3364
3363
|
// if (verbose) {
|
|
3365
|
-
//
|
|
3364
|
+
// console.log(
|
|
3366
3365
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3367
3366
|
// )
|
|
3368
3367
|
// } else {
|
|
3369
|
-
//
|
|
3368
|
+
// console.log('Moving output pom file')
|
|
3370
3369
|
// }
|
|
3371
3370
|
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3372
3371
|
// await renamep(loc, out)
|
|
3373
|
-
|
|
3372
|
+
logger.logger.success(`Generated ${poms.length} pom files`);
|
|
3374
3373
|
poms.forEach(fn => console.log('-', fn));
|
|
3375
|
-
|
|
3374
|
+
logger.logger.success(`OK`);
|
|
3376
3375
|
}
|
|
3377
3376
|
} catch (e) {
|
|
3378
|
-
spinner$1.
|
|
3377
|
+
spinner$1.errorAndStop('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3379
3378
|
if (verbose) {
|
|
3380
3379
|
console.group('[VERBOSE] error:');
|
|
3381
3380
|
console.log(e);
|
|
@@ -4797,9 +4796,7 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4797
4796
|
} else {
|
|
4798
4797
|
overridesDataObjects.push(overridesDataByAgent.get(NPM$1)(pkgJson), overridesDataByAgent.get(YARN_CLASSIC)(pkgJson));
|
|
4799
4798
|
}
|
|
4800
|
-
|
|
4801
|
-
spinner.text = `Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`;
|
|
4802
|
-
}
|
|
4799
|
+
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
4803
4800
|
const depAliasMap = new Map();
|
|
4804
4801
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
4805
4802
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
@@ -4976,9 +4973,8 @@ async function getOrganization(format = 'text') {
|
|
|
4976
4973
|
await printOrganizationsFromToken(apiToken, format);
|
|
4977
4974
|
}
|
|
4978
4975
|
async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
4979
|
-
const spinner$1 = new spinner.Spinner(
|
|
4980
|
-
|
|
4981
|
-
}).start();
|
|
4976
|
+
const spinner$1 = new spinner.Spinner();
|
|
4977
|
+
spinner$1.start('Fetching organizations...');
|
|
4982
4978
|
const socketSdk = await index.setupSdk(apiToken);
|
|
4983
4979
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4984
4980
|
if (!result.success) {
|
|
@@ -5220,24 +5216,28 @@ async function createReport(socketConfig, inputPaths, {
|
|
|
5220
5216
|
});
|
|
5221
5217
|
});
|
|
5222
5218
|
const packagePaths = await npmPaths.getPackageFiles(cwd, inputPaths, socketConfig, supportedFiles);
|
|
5223
|
-
|
|
5219
|
+
const {
|
|
5220
|
+
length: packagePathsCount
|
|
5221
|
+
} = packagePaths;
|
|
5222
|
+
if (packagePathsCount && npmPaths.isDebug()) {
|
|
5223
|
+
for (const pkgPath of packagePaths) {
|
|
5224
|
+
npmPaths.debugLog(`Uploading: ${pkgPath}`);
|
|
5225
|
+
}
|
|
5226
|
+
}
|
|
5224
5227
|
if (dryRun) {
|
|
5225
5228
|
npmPaths.debugLog('[dryRun] Skipped actual upload');
|
|
5226
5229
|
return undefined;
|
|
5227
|
-
} else {
|
|
5228
|
-
const socketSdk = await index.setupSdk();
|
|
5229
|
-
const spinner$1 = new spinner.Spinner({
|
|
5230
|
-
text: `Creating report with ${packagePaths.length} package files`
|
|
5231
|
-
}).start();
|
|
5232
|
-
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5233
|
-
const result = await handleApiCall(apiCall, 'creating report');
|
|
5234
|
-
if (!result.success) {
|
|
5235
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner$1);
|
|
5236
|
-
return undefined;
|
|
5237
|
-
}
|
|
5238
|
-
spinner$1.success();
|
|
5239
|
-
return result;
|
|
5240
5230
|
}
|
|
5231
|
+
const spinner$1 = new spinner.Spinner();
|
|
5232
|
+
spinner$1.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5233
|
+
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5234
|
+
const result = await handleApiCall(apiCall, 'creating report');
|
|
5235
|
+
if (!result.success) {
|
|
5236
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner$1);
|
|
5237
|
+
return undefined;
|
|
5238
|
+
}
|
|
5239
|
+
spinner$1.successAndStop();
|
|
5240
|
+
return result;
|
|
5241
5241
|
}
|
|
5242
5242
|
|
|
5243
5243
|
async function getSocketConfig(absoluteConfigPath) {
|
|
@@ -5264,10 +5264,9 @@ async function getSocketConfig(absoluteConfigPath) {
|
|
|
5264
5264
|
const MAX_TIMEOUT_RETRY = 5;
|
|
5265
5265
|
const HTTP_CODE_TIMEOUT = 524;
|
|
5266
5266
|
async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
5267
|
+
const spinner$1 = new spinner.Spinner();
|
|
5268
|
+
spinner$1.start(`Fetching report with ID ${reportId} (this could take a while)`);
|
|
5267
5269
|
const socketSdk = await index.setupSdk();
|
|
5268
|
-
const spinner$1 = new spinner.Spinner({
|
|
5269
|
-
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
5270
|
-
}).start();
|
|
5271
5270
|
let result;
|
|
5272
5271
|
for (let retry = 1; !result; ++retry) {
|
|
5273
5272
|
try {
|
|
@@ -5275,6 +5274,7 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5275
5274
|
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
5276
5275
|
} catch (err) {
|
|
5277
5276
|
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof Error) || err.cause?.cause?.response?.statusCode !== HTTP_CODE_TIMEOUT) {
|
|
5277
|
+
spinner$1.stop();
|
|
5278
5278
|
throw err;
|
|
5279
5279
|
}
|
|
5280
5280
|
}
|
|
@@ -5283,8 +5283,7 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5283
5283
|
return handleUnsuccessfulApiResponse('getReport', result, spinner$1);
|
|
5284
5284
|
}
|
|
5285
5285
|
|
|
5286
|
-
// Conclude the status of the API call
|
|
5287
|
-
|
|
5286
|
+
// Conclude the status of the API call.
|
|
5288
5287
|
if (strict) {
|
|
5289
5288
|
if (result.data.healthy) {
|
|
5290
5289
|
spinner$1.success('Report result is healthy and great!');
|
|
@@ -5298,6 +5297,7 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5298
5297
|
} else {
|
|
5299
5298
|
spinner$1.success('Report has no issues');
|
|
5300
5299
|
}
|
|
5300
|
+
spinner$1.stop();
|
|
5301
5301
|
return result.data;
|
|
5302
5302
|
}
|
|
5303
5303
|
|
|
@@ -5519,10 +5519,8 @@ async function createRepo({
|
|
|
5519
5519
|
repoName,
|
|
5520
5520
|
visibility
|
|
5521
5521
|
}) {
|
|
5522
|
-
const
|
|
5523
|
-
|
|
5524
|
-
text: spinnerText
|
|
5525
|
-
}).start();
|
|
5522
|
+
const spinner$1 = new spinner.Spinner();
|
|
5523
|
+
spinner$1.start('Creating repository...');
|
|
5526
5524
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5527
5525
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5528
5526
|
outputJson,
|
|
@@ -5535,7 +5533,7 @@ async function createRepo({
|
|
|
5535
5533
|
visibility
|
|
5536
5534
|
}), 'creating repository');
|
|
5537
5535
|
if (result.success) {
|
|
5538
|
-
spinner$1.
|
|
5536
|
+
spinner$1.successAndStop('Repository created successfully');
|
|
5539
5537
|
} else {
|
|
5540
5538
|
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner$1);
|
|
5541
5539
|
}
|
|
@@ -5637,14 +5635,12 @@ async function run$b(argv, importMeta, {
|
|
|
5637
5635
|
}
|
|
5638
5636
|
|
|
5639
5637
|
async function deleteRepo(orgSlug, repoName, apiToken) {
|
|
5640
|
-
const
|
|
5641
|
-
|
|
5642
|
-
text: spinnerText
|
|
5643
|
-
}).start();
|
|
5638
|
+
const spinner$1 = new spinner.Spinner();
|
|
5639
|
+
spinner$1.start('Deleting repository...');
|
|
5644
5640
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5645
5641
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
5646
5642
|
if (result.success) {
|
|
5647
|
-
spinner$1.
|
|
5643
|
+
spinner$1.successAndStop('Repository deleted successfully');
|
|
5648
5644
|
} else {
|
|
5649
5645
|
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner$1);
|
|
5650
5646
|
}
|
|
@@ -5733,6 +5729,18 @@ async function listRepos({
|
|
|
5733
5729
|
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner$1);
|
|
5734
5730
|
return;
|
|
5735
5731
|
}
|
|
5732
|
+
spinner$1.stop();
|
|
5733
|
+
if (outputJson) {
|
|
5734
|
+
const data = result.data.results.map(o => ({
|
|
5735
|
+
id: o.id,
|
|
5736
|
+
name: o.name,
|
|
5737
|
+
visibility: o.visibility,
|
|
5738
|
+
defaultBranch: o.default_branch,
|
|
5739
|
+
archived: o.archived
|
|
5740
|
+
}));
|
|
5741
|
+
console.log(JSON.stringify(data, null, 2));
|
|
5742
|
+
return;
|
|
5743
|
+
}
|
|
5736
5744
|
const options = {
|
|
5737
5745
|
columns: [{
|
|
5738
5746
|
field: 'id',
|
|
@@ -5751,7 +5759,7 @@ async function listRepos({
|
|
|
5751
5759
|
name: colors.magenta('Archived')
|
|
5752
5760
|
}]
|
|
5753
5761
|
};
|
|
5754
|
-
|
|
5762
|
+
console.log(chalkTable(options, result.data.results));
|
|
5755
5763
|
}
|
|
5756
5764
|
|
|
5757
5765
|
const config$9 = {
|
|
@@ -5867,7 +5875,7 @@ async function updateRepo({
|
|
|
5867
5875
|
visibility
|
|
5868
5876
|
}), 'updating repository');
|
|
5869
5877
|
if (result.success) {
|
|
5870
|
-
spinner$1.
|
|
5878
|
+
spinner$1.successAndStop('Repository updated successfully');
|
|
5871
5879
|
} else {
|
|
5872
5880
|
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner$1);
|
|
5873
5881
|
}
|
|
@@ -6084,8 +6092,149 @@ const cmdRepos = {
|
|
|
6084
6092
|
}
|
|
6085
6093
|
};
|
|
6086
6094
|
|
|
6095
|
+
async function suggestOrgSlug(socketSdk) {
|
|
6096
|
+
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
6097
|
+
// Ignore a failed request here. It was not the primary goal of
|
|
6098
|
+
// running this command and reporting it only leads to end-user confusion.
|
|
6099
|
+
if (result.success) {
|
|
6100
|
+
const proceed = await prompts.select({
|
|
6101
|
+
message: 'Missing org name; do you want to use any of these orgs for this scan?',
|
|
6102
|
+
choices: Array.from(Object.values(result.data.organizations)).map(({
|
|
6103
|
+
name: slug
|
|
6104
|
+
}) => ({
|
|
6105
|
+
name: 'Yes [' + slug + ']',
|
|
6106
|
+
value: slug,
|
|
6107
|
+
description: `Use "${slug}" as the organization`
|
|
6108
|
+
})).concat({
|
|
6109
|
+
name: 'No',
|
|
6110
|
+
value: '',
|
|
6111
|
+
description: 'Do not use any of these organizations (will end in a no-op)'
|
|
6112
|
+
})
|
|
6113
|
+
});
|
|
6114
|
+
if (proceed) {
|
|
6115
|
+
return proceed;
|
|
6116
|
+
}
|
|
6117
|
+
}
|
|
6118
|
+
}
|
|
6119
|
+
|
|
6120
|
+
async function suggestRepoSlug(socketSdk, orgSlug) {
|
|
6121
|
+
// Same as above, but if there's a repo with the same name as cwd then
|
|
6122
|
+
// default the selection to that name.
|
|
6123
|
+
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
6124
|
+
orgSlug,
|
|
6125
|
+
sort: 'name',
|
|
6126
|
+
direction: 'asc',
|
|
6127
|
+
// There's no guarantee that the cwd is part of this page. If it's not
|
|
6128
|
+
// then do an additional request and specific search for it instead.
|
|
6129
|
+
// This way we can offer the tip of "do you want to create [cwd]?".
|
|
6130
|
+
perPage: 10,
|
|
6131
|
+
page: 0
|
|
6132
|
+
}), 'looking up known repos');
|
|
6133
|
+
// Ignore a failed request here. It was not the primary goal of
|
|
6134
|
+
// running this command and reporting it only leads to end-user confusion.
|
|
6135
|
+
if (result.success) {
|
|
6136
|
+
const currentDirName = dirNameToSlug(path.basename(process$1.cwd()));
|
|
6137
|
+
let cwdIsKnown = !!currentDirName && result.data.results.some(obj => obj.slug === currentDirName);
|
|
6138
|
+
if (!cwdIsKnown && currentDirName) {
|
|
6139
|
+
// Do an explicit request so we can assert that the cwd exists or not
|
|
6140
|
+
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, currentDirName), 'checking if current cwd is a known repo');
|
|
6141
|
+
if (result.success) {
|
|
6142
|
+
cwdIsKnown = true;
|
|
6143
|
+
}
|
|
6144
|
+
}
|
|
6145
|
+
const proceed = await prompts.select({
|
|
6146
|
+
message: 'Missing repo name; do you want to use any of these known repo names for this scan?',
|
|
6147
|
+
choices:
|
|
6148
|
+
// Put the CWD suggestion at the top, whether it exists or not
|
|
6149
|
+
(currentDirName ? [{
|
|
6150
|
+
name: `Yes, current dir [${cwdIsKnown ? currentDirName : `create repo for ${currentDirName}`}]`,
|
|
6151
|
+
value: currentDirName,
|
|
6152
|
+
description: cwdIsKnown ? 'Register a new repo name under the given org and use it' : 'Use current dir as repo'
|
|
6153
|
+
}] : []).concat(result.data.results.filter(({
|
|
6154
|
+
slug
|
|
6155
|
+
}) => !!slug && slug !== currentDirName).map(({
|
|
6156
|
+
slug
|
|
6157
|
+
}) => ({
|
|
6158
|
+
name: 'Yes [' + slug + ']',
|
|
6159
|
+
value: slug || '',
|
|
6160
|
+
// Filtered above but TS is like nah.
|
|
6161
|
+
description: `Use "${slug}" as the repo name`
|
|
6162
|
+
})), {
|
|
6163
|
+
name: 'No',
|
|
6164
|
+
value: '',
|
|
6165
|
+
description: 'Do not use any of these repos (will end in a no-op)'
|
|
6166
|
+
})
|
|
6167
|
+
});
|
|
6168
|
+
if (proceed) {
|
|
6169
|
+
const repoName = proceed;
|
|
6170
|
+
let repoDefaultBranch = '';
|
|
6171
|
+
// Store the default branch to help with the branch name question next
|
|
6172
|
+
result.data.results.some(obj => {
|
|
6173
|
+
if (obj.slug === proceed && obj.default_branch) {
|
|
6174
|
+
repoDefaultBranch = obj.default_branch;
|
|
6175
|
+
return;
|
|
6176
|
+
}
|
|
6177
|
+
});
|
|
6178
|
+
return {
|
|
6179
|
+
slug: repoName,
|
|
6180
|
+
defaultBranch: repoDefaultBranch
|
|
6181
|
+
};
|
|
6182
|
+
}
|
|
6183
|
+
}
|
|
6184
|
+
}
|
|
6185
|
+
function dirNameToSlug(name) {
|
|
6186
|
+
// Uses slug specs asserted by our servers
|
|
6187
|
+
// Note: this can lead to collisions; eg. slug for `x--y` and `x---y` is `x-y`
|
|
6188
|
+
return name.toLowerCase().replace(/[^[a-zA-Z0-9_.-]/g, '_').replace(/--+/g, '-').replace(/__+/g, '_').replace(/\.\.+/g, '.').replace(/[._-]+$/, '');
|
|
6189
|
+
}
|
|
6190
|
+
|
|
6191
|
+
async function suggestBranchSlug(repoDefaultBranch) {
|
|
6192
|
+
const spawnResult = childProcess.spawnSync('git', ['branch', '--show-current']);
|
|
6193
|
+
const currentBranch = spawnResult.stdout.toString('utf8').trim();
|
|
6194
|
+
if (currentBranch && spawnResult.status === 0) {
|
|
6195
|
+
const proceed = await prompts.select({
|
|
6196
|
+
message: 'Use the current git branch as target branch name?',
|
|
6197
|
+
choices: [{
|
|
6198
|
+
name: `Yes [${currentBranch}]`,
|
|
6199
|
+
value: currentBranch,
|
|
6200
|
+
description: 'Use the current git branch for branch name'
|
|
6201
|
+
}, ...(repoDefaultBranch && repoDefaultBranch !== currentBranch ? [{
|
|
6202
|
+
name: `No, use the default branch [${repoDefaultBranch}]`,
|
|
6203
|
+
value: repoDefaultBranch,
|
|
6204
|
+
description: 'Use the default branch for target repo as the target branch name'
|
|
6205
|
+
}] : []), {
|
|
6206
|
+
name: 'No',
|
|
6207
|
+
value: '',
|
|
6208
|
+
description: 'Do not use the current git branch as name (will end in a no-op)'
|
|
6209
|
+
}].filter(Boolean)
|
|
6210
|
+
});
|
|
6211
|
+
if (proceed) {
|
|
6212
|
+
return proceed;
|
|
6213
|
+
}
|
|
6214
|
+
}
|
|
6215
|
+
}
|
|
6216
|
+
|
|
6217
|
+
async function suggestTarget() {
|
|
6218
|
+
// We could prefill this with sub-dirs of the current
|
|
6219
|
+
// dir ... but is that going to be useful?
|
|
6220
|
+
const proceed = await prompts.select({
|
|
6221
|
+
message: 'No TARGET given. Do you want to use the current directory?',
|
|
6222
|
+
choices: [{
|
|
6223
|
+
name: 'Yes',
|
|
6224
|
+
value: true,
|
|
6225
|
+
description: 'Target the current directory'
|
|
6226
|
+
}, {
|
|
6227
|
+
name: 'No',
|
|
6228
|
+
value: false,
|
|
6229
|
+
description: 'Do not use the current directory (this will end in a no-op)'
|
|
6230
|
+
}]
|
|
6231
|
+
});
|
|
6232
|
+
if (proceed) {
|
|
6233
|
+
return ['.'];
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
|
|
6087
6237
|
async function createFullScan({
|
|
6088
|
-
apiToken,
|
|
6089
6238
|
branchName,
|
|
6090
6239
|
commitHash: _commitHash,
|
|
6091
6240
|
commitMessage,
|
|
@@ -6093,17 +6242,100 @@ async function createFullScan({
|
|
|
6093
6242
|
cwd,
|
|
6094
6243
|
defaultBranch,
|
|
6095
6244
|
orgSlug,
|
|
6096
|
-
packagePaths,
|
|
6097
6245
|
pendingHead,
|
|
6098
6246
|
pullRequest: _pullRequest,
|
|
6247
|
+
readOnly,
|
|
6099
6248
|
repoName,
|
|
6249
|
+
targets,
|
|
6100
6250
|
tmp
|
|
6101
6251
|
}) {
|
|
6252
|
+
const socketSdk = await index.setupSdk();
|
|
6253
|
+
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6254
|
+
if (!res.success) {
|
|
6255
|
+
handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
6256
|
+
assert(false, 'handleUnsuccessfulApiResponse should unconditionally throw');
|
|
6257
|
+
}
|
|
6258
|
+
return res.data;
|
|
6259
|
+
}).catch(cause => {
|
|
6260
|
+
throw new Error('Failed getting supported files for report', {
|
|
6261
|
+
cause
|
|
6262
|
+
});
|
|
6263
|
+
});
|
|
6264
|
+
|
|
6265
|
+
// If we updated any inputs then we should print the command line to repeat
|
|
6266
|
+
// the command without requiring user input, as a suggestion.
|
|
6267
|
+
let updatedInput = false;
|
|
6268
|
+
if (!targets.length) {
|
|
6269
|
+
const received = await suggestTarget();
|
|
6270
|
+
targets = received ?? [];
|
|
6271
|
+
updatedInput = true;
|
|
6272
|
+
}
|
|
6273
|
+
const packagePaths = await npmPaths.getPackageFilesFullScans(cwd, targets, supportedFiles);
|
|
6274
|
+
|
|
6275
|
+
// We're going to need an api token to suggest data because those suggestions
|
|
6276
|
+
// must come from data we already know. Don't error on missing api token yet.
|
|
6277
|
+
// If the api-token is not set, ignore it for the sake of suggestions.
|
|
6278
|
+
const apiToken = index.getDefaultToken();
|
|
6279
|
+
if (apiToken && !orgSlug) {
|
|
6280
|
+
const suggestion = await suggestOrgSlug(socketSdk);
|
|
6281
|
+
if (suggestion) orgSlug = suggestion;
|
|
6282
|
+
updatedInput = true;
|
|
6283
|
+
}
|
|
6284
|
+
|
|
6285
|
+
// If the current cwd is unknown and is used as a repo slug anyways, we will
|
|
6286
|
+
// first need to register the slug before we can use it.
|
|
6287
|
+
let repoDefaultBranch = '';
|
|
6288
|
+
|
|
6289
|
+
// (Don't bother asking for the rest if we didn't get an org slug above)
|
|
6290
|
+
if (apiToken && orgSlug && !repoName) {
|
|
6291
|
+
const suggestion = await suggestRepoSlug(socketSdk, orgSlug);
|
|
6292
|
+
if (suggestion) {
|
|
6293
|
+
({
|
|
6294
|
+
defaultBranch: repoDefaultBranch,
|
|
6295
|
+
slug: repoName
|
|
6296
|
+
} = suggestion);
|
|
6297
|
+
}
|
|
6298
|
+
updatedInput = true;
|
|
6299
|
+
}
|
|
6300
|
+
|
|
6301
|
+
// (Don't bother asking for the rest if we didn't get an org/repo above)
|
|
6302
|
+
if (apiToken && orgSlug && repoName && !branchName) {
|
|
6303
|
+
const suggestion = await suggestBranchSlug(repoDefaultBranch);
|
|
6304
|
+
if (suggestion) branchName = suggestion;
|
|
6305
|
+
updatedInput = true;
|
|
6306
|
+
}
|
|
6307
|
+
if (!orgSlug || !repoName || !branchName || !packagePaths.length) {
|
|
6308
|
+
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
6309
|
+
// options or missing arguments.
|
|
6310
|
+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6311
|
+
process$1.exitCode = 2;
|
|
6312
|
+
console.error(`
|
|
6313
|
+
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6314
|
+
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6315
|
+
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6316
|
+
- Branch name using --branch ${!branchName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6317
|
+
- At least one TARGET (e.g. \`.\` or \`./package.json\`) ${!packagePaths.length ? colors.red(targets.length > 0 ? '(TARGET' + (targets.length ? 's' : '') + ' contained no matching/supported files!)' : '(missing)') : colors.green('(ok)')}\n
|
|
6318
|
+
${!apiToken ? 'Note: was unable to make suggestions because no API Token was found; this would make command fail regardless\n' : ''}
|
|
6319
|
+
`);
|
|
6320
|
+
return;
|
|
6321
|
+
}
|
|
6322
|
+
if (updatedInput) {
|
|
6323
|
+
console.log('Note: You can invoke this command next time to skip the interactive questions:');
|
|
6324
|
+
console.log('```');
|
|
6325
|
+
console.log(` socket scan create [other flags...] --repo ${repoName} --branch ${branchName} ${orgSlug} ${targets.join(' ')}`);
|
|
6326
|
+
console.log('```');
|
|
6327
|
+
}
|
|
6328
|
+
if (!apiToken) {
|
|
6329
|
+
throw new index.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
6330
|
+
}
|
|
6331
|
+
if (readOnly) {
|
|
6332
|
+
console.log('[ReadOnly] Bailing now');
|
|
6333
|
+
return;
|
|
6334
|
+
}
|
|
6102
6335
|
const spinnerText = 'Creating a scan... \n';
|
|
6103
6336
|
const spinner$1 = new spinner.Spinner({
|
|
6104
6337
|
text: spinnerText
|
|
6105
6338
|
}).start();
|
|
6106
|
-
const socketSdk = await index.setupSdk(apiToken);
|
|
6107
6339
|
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
6108
6340
|
repo: repoName,
|
|
6109
6341
|
branch: branchName,
|
|
@@ -6116,7 +6348,7 @@ async function createFullScan({
|
|
|
6116
6348
|
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner$1);
|
|
6117
6349
|
return;
|
|
6118
6350
|
}
|
|
6119
|
-
spinner$1.
|
|
6351
|
+
spinner$1.successAndStop('Scan created successfully');
|
|
6120
6352
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
6121
6353
|
console.log(`Available at: ${link}`);
|
|
6122
6354
|
const rl = readline.createInterface({
|
|
@@ -6190,6 +6422,11 @@ const config$6 = {
|
|
|
6190
6422
|
default: false,
|
|
6191
6423
|
description: 'Set as pending head'
|
|
6192
6424
|
},
|
|
6425
|
+
readOnly: {
|
|
6426
|
+
type: 'boolean',
|
|
6427
|
+
default: false,
|
|
6428
|
+
description: 'Similar to --dry-run except it can read from remote, stops before it would create an actual report'
|
|
6429
|
+
},
|
|
6193
6430
|
tmp: {
|
|
6194
6431
|
type: 'boolean',
|
|
6195
6432
|
shortFlag: 't',
|
|
@@ -6229,71 +6466,60 @@ async function run$6(argv, importMeta, {
|
|
|
6229
6466
|
});
|
|
6230
6467
|
const [orgSlug = '', ...targets] = cli.input;
|
|
6231
6468
|
const cwd = cli.flags['cwd'] && cli.flags['cwd'] !== 'process.cwd()' ? String(cli.flags['cwd']) : process$1.cwd();
|
|
6232
|
-
|
|
6233
|
-
// Note exiting earlier to skirt a hidden auth requirement
|
|
6234
|
-
if (cli.flags['dryRun']) {
|
|
6235
|
-
return console.log('[DryRun] Bailing now');
|
|
6236
|
-
}
|
|
6237
|
-
const socketSdk = await index.setupSdk();
|
|
6238
|
-
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6239
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
6240
|
-
// TODO: verify type at runtime? Consider it trusted data and assume type?
|
|
6241
|
-
return res.data;
|
|
6242
|
-
}).catch(cause => {
|
|
6243
|
-
throw new Error('Failed getting supported files for report', {
|
|
6244
|
-
cause
|
|
6245
|
-
});
|
|
6246
|
-
});
|
|
6247
|
-
const packagePaths = await npmPaths.getPackageFilesFullScans(cwd, targets, supportedFiles);
|
|
6248
|
-
const {
|
|
6469
|
+
let {
|
|
6249
6470
|
branch: branchName,
|
|
6250
6471
|
repo: repoName
|
|
6251
6472
|
} = cli.flags;
|
|
6252
|
-
|
|
6473
|
+
const apiToken = index.getDefaultToken();
|
|
6474
|
+
if (!apiToken && (!orgSlug || !repoName || !branchName || !targets.length)) {
|
|
6475
|
+
// Without api token we cannot recover because we can't request more info
|
|
6476
|
+
// from the server, to match and help with the current cwd/git status.
|
|
6253
6477
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
6254
6478
|
// options or missing arguments.
|
|
6255
6479
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6256
6480
|
process$1.exitCode = 2;
|
|
6257
|
-
console.error(
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6481
|
+
console.error(`
|
|
6482
|
+
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6483
|
+
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6484
|
+
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6485
|
+
- Branch name using --branch ${!branchName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6486
|
+
- At least one TARGET (e.g. \`.\` or \`./package.json\`) ${!targets.length ? '(missing)' : colors.green('(ok)')}\n
|
|
6487
|
+
(Additionally, no API Token was set so we cannot auto-discover these details)\n
|
|
6488
|
+
`);
|
|
6262
6489
|
return;
|
|
6263
6490
|
}
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6491
|
+
|
|
6492
|
+
// Note exiting earlier to skirt a hidden auth requirement
|
|
6493
|
+
if (cli.flags['dryRun']) {
|
|
6494
|
+
return console.log('[DryRun] Bailing now');
|
|
6267
6495
|
}
|
|
6268
6496
|
await createFullScan({
|
|
6269
|
-
apiToken,
|
|
6270
|
-
orgSlug,
|
|
6271
|
-
repoName: repoName,
|
|
6272
6497
|
branchName: branchName,
|
|
6498
|
+
commitHash: cli.flags['commitHash'] ?? '',
|
|
6273
6499
|
commitMessage: cli.flags['commitMessage'] ?? '',
|
|
6500
|
+
committers: cli.flags['committers'] ?? '',
|
|
6501
|
+
cwd,
|
|
6274
6502
|
defaultBranch: Boolean(cli.flags['defaultBranch']),
|
|
6503
|
+
orgSlug,
|
|
6275
6504
|
pendingHead: Boolean(cli.flags['pendingHead']),
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
pullRequest: cli.flags['pullRequest'] ?? undefined
|
|
6505
|
+
pullRequest: cli.flags['pullRequest'] ?? undefined,
|
|
6506
|
+
readOnly: Boolean(cli.flags['readOnly']),
|
|
6507
|
+
repoName: repoName,
|
|
6508
|
+
targets,
|
|
6509
|
+
tmp: Boolean(cli.flags['tmp'])
|
|
6282
6510
|
});
|
|
6283
6511
|
}
|
|
6284
6512
|
|
|
6285
6513
|
async function deleteOrgFullScan(orgSlug, fullScanId, apiToken) {
|
|
6286
|
-
const
|
|
6287
|
-
|
|
6288
|
-
text: spinnerText
|
|
6289
|
-
}).start();
|
|
6514
|
+
const spinner$1 = new spinner.Spinner();
|
|
6515
|
+
spinner$1.start('Deleting scan...');
|
|
6290
6516
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6291
6517
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
6292
|
-
if (result.success) {
|
|
6293
|
-
spinner$1.success('Scan deleted successfully');
|
|
6294
|
-
} else {
|
|
6518
|
+
if (!result.success) {
|
|
6295
6519
|
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner$1);
|
|
6520
|
+
return;
|
|
6296
6521
|
}
|
|
6522
|
+
spinner$1.successAndStop('Scan deleted successfully');
|
|
6297
6523
|
}
|
|
6298
6524
|
|
|
6299
6525
|
const config$5 = {
|
|
@@ -6352,10 +6578,8 @@ async function run$5(argv, importMeta, {
|
|
|
6352
6578
|
|
|
6353
6579
|
// @ts-ignore
|
|
6354
6580
|
async function listFullScans(orgSlug, input, apiToken) {
|
|
6355
|
-
const
|
|
6356
|
-
|
|
6357
|
-
text: spinnerText
|
|
6358
|
-
}).start();
|
|
6581
|
+
const spinner$1 = new spinner.Spinner();
|
|
6582
|
+
spinner$1.start('Listing scans...');
|
|
6359
6583
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6360
6584
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
6361
6585
|
if (!result.success) {
|
|
@@ -6495,10 +6719,8 @@ async function run$4(argv, importMeta, {
|
|
|
6495
6719
|
}
|
|
6496
6720
|
|
|
6497
6721
|
async function getOrgScanMetadata(orgSlug, scanId, apiToken) {
|
|
6498
|
-
const
|
|
6499
|
-
|
|
6500
|
-
text: spinnerText
|
|
6501
|
-
}).start();
|
|
6722
|
+
const spinner$1 = new spinner.Spinner();
|
|
6723
|
+
spinner$1.start("Getting scan's metadata...");
|
|
6502
6724
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6503
6725
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
6504
6726
|
if (!result.success) {
|
|
@@ -6564,9 +6786,8 @@ async function run$3(argv, importMeta, {
|
|
|
6564
6786
|
}
|
|
6565
6787
|
|
|
6566
6788
|
async function getFullScan(orgSlug, fullScanId, file, apiToken) {
|
|
6567
|
-
const spinner$1 = new spinner.Spinner(
|
|
6568
|
-
|
|
6569
|
-
}).start();
|
|
6789
|
+
const spinner$1 = new spinner.Spinner();
|
|
6790
|
+
spinner$1.start('Streaming scan...');
|
|
6570
6791
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6571
6792
|
const data = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file === '-' ? undefined : file), 'Streaming a scan');
|
|
6572
6793
|
if (data?.success) {
|
|
@@ -6662,9 +6883,8 @@ async function getThreatFeed({
|
|
|
6662
6883
|
page,
|
|
6663
6884
|
perPage
|
|
6664
6885
|
}) {
|
|
6665
|
-
const spinner$1 = new spinner.Spinner(
|
|
6666
|
-
|
|
6667
|
-
}).start();
|
|
6886
|
+
const spinner$1 = new spinner.Spinner();
|
|
6887
|
+
spinner$1.start('Looking up the threat feed');
|
|
6668
6888
|
const formattedQueryParams = formatQueryParams({
|
|
6669
6889
|
per_page: perPage,
|
|
6670
6890
|
page,
|
|
@@ -7064,12 +7284,12 @@ void (async () => {
|
|
|
7064
7284
|
} else {
|
|
7065
7285
|
errorTitle = 'Unexpected error with no details';
|
|
7066
7286
|
}
|
|
7067
|
-
|
|
7287
|
+
logger.logger.error(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
7068
7288
|
if (errorBody) {
|
|
7069
7289
|
console.error(`\n${errorBody}`);
|
|
7070
7290
|
}
|
|
7071
7291
|
await index.captureException(e);
|
|
7072
7292
|
}
|
|
7073
7293
|
})();
|
|
7074
|
-
//# debugId=
|
|
7294
|
+
//# debugId=387e6564-5b13-4477-b447-bab83844129a
|
|
7075
7295
|
//# sourceMappingURL=cli.js.map
|