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