@socketsecurity/cli-with-sentry 0.14.50 → 0.14.52
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 +27 -2
- package/dist/constants.js +8 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +7 -10
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +635 -456
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/index.d.ts +1 -1
- package/dist/module-sync/index.js +22 -22
- package/dist/module-sync/index.js.map +1 -1
- package/dist/module-sync/npm-paths.js +12 -63
- package/dist/module-sync/npm-paths.js.map +1 -1
- package/dist/module-sync/npm.js +4 -3
- package/dist/module-sync/npm.js.map +1 -1
- package/dist/module-sync/path-resolve.d.ts +1 -2
- package/dist/require/cli.js +635 -456
- package/dist/require/cli.js.map +1 -1
- package/package.json +9 -8
- package/dist/module-sync/debug.d.ts +0 -3
- 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');
|
|
@@ -24,14 +25,13 @@ var path = require('node:path');
|
|
|
24
25
|
var ndjson = _socketInterop(require('ndjson'));
|
|
25
26
|
var rest = _socketInterop(require('@octokit/rest'));
|
|
26
27
|
var index = require('./index.js');
|
|
28
|
+
var constants = require('./constants.js');
|
|
27
29
|
var meow = _socketInterop(require('meow'));
|
|
28
30
|
var objects = require('@socketsecurity/registry/lib/objects');
|
|
29
31
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
30
|
-
var constants = require('./constants.js');
|
|
31
32
|
var fs$1 = require('node:fs/promises');
|
|
32
33
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
33
34
|
var contrib = _socketInterop(require('blessed-contrib'));
|
|
34
|
-
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
35
35
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
36
36
|
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
37
37
|
var words = require('@socketsecurity/registry/lib/words');
|
|
@@ -54,8 +54,9 @@ var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
|
54
54
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
55
55
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
56
56
|
var yaml = _socketInterop(require('yaml'));
|
|
57
|
-
var
|
|
57
|
+
var debug = require('@socketsecurity/registry/lib/debug');
|
|
58
58
|
var npm$1 = require('./npm.js');
|
|
59
|
+
var npmPaths = require('./npm-paths.js');
|
|
59
60
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
60
61
|
var config$A = require('@socketsecurity/config');
|
|
61
62
|
var assert = require('node:assert');
|
|
@@ -266,7 +267,6 @@ class Score {
|
|
|
266
267
|
}
|
|
267
268
|
|
|
268
269
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
|
|
269
|
-
/* eslint-disable no-await-in-loop */
|
|
270
270
|
class Core {
|
|
271
271
|
securityPolicy = {};
|
|
272
272
|
constructor({
|
|
@@ -561,6 +561,7 @@ class Core {
|
|
|
561
561
|
diff.newPackages.push(purl);
|
|
562
562
|
consolidated.add(basePurl);
|
|
563
563
|
}
|
|
564
|
+
// eslint-disable-next-line no-await-in-loop
|
|
564
565
|
newScanAlerts = await this.createIssueAlerts({
|
|
565
566
|
pkg,
|
|
566
567
|
alerts: newScanAlerts,
|
|
@@ -578,6 +579,7 @@ class Core {
|
|
|
578
579
|
if (!(packageId in newPackages) && pkg.direct) {
|
|
579
580
|
diff.removedPackages.push(purl);
|
|
580
581
|
}
|
|
582
|
+
// eslint-disable-next-line no-await-in-loop
|
|
581
583
|
headScanAlerts = await this.createIssueAlerts({
|
|
582
584
|
pkg,
|
|
583
585
|
alerts: headScanAlerts,
|
|
@@ -643,7 +645,7 @@ class Core {
|
|
|
643
645
|
license: sbomArtifact.license
|
|
644
646
|
});
|
|
645
647
|
if (pkg.id in packages) {
|
|
646
|
-
|
|
648
|
+
logger.logger.log('Duplicate package?');
|
|
647
649
|
} else {
|
|
648
650
|
pkg = this.getLicenseDetails({
|
|
649
651
|
package: pkg
|
|
@@ -683,8 +685,8 @@ class Core {
|
|
|
683
685
|
});
|
|
684
686
|
}
|
|
685
687
|
}
|
|
686
|
-
} catch (
|
|
687
|
-
|
|
688
|
+
} catch (e) {
|
|
689
|
+
logger.logger.error(e);
|
|
688
690
|
}
|
|
689
691
|
const newFullScan = await this.createFullScan({
|
|
690
692
|
params
|
|
@@ -708,7 +710,6 @@ class Core {
|
|
|
708
710
|
}
|
|
709
711
|
|
|
710
712
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
|
|
711
|
-
|
|
712
713
|
function checkForSocketComments({
|
|
713
714
|
comments
|
|
714
715
|
}) {
|
|
@@ -838,9 +839,9 @@ function getIgnoreOptions({
|
|
|
838
839
|
const data = `${name}/${version}`;
|
|
839
840
|
ignoreCommands.push(data);
|
|
840
841
|
}
|
|
841
|
-
} catch (
|
|
842
|
-
|
|
843
|
-
|
|
842
|
+
} catch (e) {
|
|
843
|
+
logger.logger.error(`Unable to process ignore command for ${comment}`);
|
|
844
|
+
logger.logger.error(e);
|
|
844
845
|
}
|
|
845
846
|
}
|
|
846
847
|
}
|
|
@@ -871,9 +872,9 @@ function removeAlerts({
|
|
|
871
872
|
const purl = `${fullName}/${alert.pkg_version}`;
|
|
872
873
|
const purlStar = `${fullName}/*`;
|
|
873
874
|
if (ignoreCommands.includes(purl) || ignoreCommands.includes(purlStar)) {
|
|
874
|
-
|
|
875
|
+
logger.logger.log(`Alerts for ${alert.pkg_name}@${alert.pkg_version} ignored`);
|
|
875
876
|
} else {
|
|
876
|
-
|
|
877
|
+
logger.logger.log(`Adding alert ${alert.type} for ${alert.pkg_name}@${alert.pkg_version}`);
|
|
877
878
|
alerts.push(alert);
|
|
878
879
|
}
|
|
879
880
|
}
|
|
@@ -911,7 +912,7 @@ class GitHub {
|
|
|
911
912
|
if (['opened', 'synchronize'].includes(eventAction)) {
|
|
912
913
|
return 'diff';
|
|
913
914
|
} else {
|
|
914
|
-
|
|
915
|
+
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
915
916
|
process.exit();
|
|
916
917
|
}
|
|
917
918
|
case 'issue_comment':
|
|
@@ -1026,30 +1027,30 @@ class GitHub {
|
|
|
1026
1027
|
security: existingSecurityComment
|
|
1027
1028
|
} = comments;
|
|
1028
1029
|
if (newOverviewComment) {
|
|
1029
|
-
|
|
1030
|
+
logger.logger.log('New Dependency Overview comment');
|
|
1030
1031
|
if (existingOverviewComment !== undefined) {
|
|
1031
|
-
|
|
1032
|
+
logger.logger.log('Previous version of Dependency Overview, updating');
|
|
1032
1033
|
await this.updateComment({
|
|
1033
1034
|
body: overviewComment,
|
|
1034
1035
|
id: existingOverviewComment.id
|
|
1035
1036
|
});
|
|
1036
1037
|
} else {
|
|
1037
|
-
|
|
1038
|
+
logger.logger.log('No previous version of Dependency Overview, posting');
|
|
1038
1039
|
await this.postComment({
|
|
1039
1040
|
body: overviewComment
|
|
1040
1041
|
});
|
|
1041
1042
|
}
|
|
1042
1043
|
}
|
|
1043
1044
|
if (newSecurityComment) {
|
|
1044
|
-
|
|
1045
|
+
logger.logger.log('New Security Issue Comment');
|
|
1045
1046
|
if (existingSecurityComment !== undefined) {
|
|
1046
|
-
|
|
1047
|
+
logger.logger.log('Previous version of Security Issue comment, updating');
|
|
1047
1048
|
await this.updateComment({
|
|
1048
1049
|
body: securityComment,
|
|
1049
1050
|
id: existingSecurityComment.id
|
|
1050
1051
|
});
|
|
1051
1052
|
} else {
|
|
1052
|
-
|
|
1053
|
+
logger.logger.log('No Previous version of Security Issue comment, posting');
|
|
1053
1054
|
await this.postComment({
|
|
1054
1055
|
body: securityComment
|
|
1055
1056
|
});
|
|
@@ -1228,7 +1229,7 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1228
1229
|
const socket = new sdk.SocketSdk(index.getDefaultToken());
|
|
1229
1230
|
const git = simpleGit.simpleGit();
|
|
1230
1231
|
const changedFiles = (await git.diff(process.env['GITHUB_EVENT_NAME'] === 'pull_request' ? ['--name-only', 'HEAD^1', 'HEAD'] : ['--name-only', githubEventBefore, githubEventAfter])).split('\n');
|
|
1231
|
-
|
|
1232
|
+
logger.logger.log({
|
|
1232
1233
|
changedFiles
|
|
1233
1234
|
});
|
|
1234
1235
|
// supportedFiles have 3-level deep globs
|
|
@@ -1236,13 +1237,13 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1236
1237
|
const files = micromatch(changedFiles, patterns);
|
|
1237
1238
|
const scm = new GitHub();
|
|
1238
1239
|
if (scm.checkEventType() === 'comment') {
|
|
1239
|
-
|
|
1240
|
+
logger.logger.log('Comment initiated flow');
|
|
1240
1241
|
const comments = await scm.getCommentsForPR();
|
|
1241
1242
|
await scm.removeCommentAlerts({
|
|
1242
1243
|
comments
|
|
1243
1244
|
});
|
|
1244
1245
|
} else if (scm.checkEventType() === 'diff') {
|
|
1245
|
-
|
|
1246
|
+
logger.logger.log('Push initiated flow');
|
|
1246
1247
|
const core = new Core({
|
|
1247
1248
|
owner: scm.owner,
|
|
1248
1249
|
repo: scm.repo,
|
|
@@ -1264,17 +1265,17 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1264
1265
|
if (diff.newAlerts.length === 0) {
|
|
1265
1266
|
if (!updateOldSecurityComment) {
|
|
1266
1267
|
newSecurityComment = false;
|
|
1267
|
-
|
|
1268
|
+
logger.logger.log('No new alerts or security issue comment disabled');
|
|
1268
1269
|
} else {
|
|
1269
|
-
|
|
1270
|
+
logger.logger.log('Updated security comment with no new alerts');
|
|
1270
1271
|
}
|
|
1271
1272
|
}
|
|
1272
1273
|
if (diff.newPackages.length === 0 && diff.removedPackages.length === 0) {
|
|
1273
1274
|
if (!updateOldOverviewComment) {
|
|
1274
1275
|
newOverviewComment = false;
|
|
1275
|
-
|
|
1276
|
+
logger.logger.log('No new/removed packages or Dependency Overview comment disabled');
|
|
1276
1277
|
} else {
|
|
1277
|
-
|
|
1278
|
+
logger.logger.log('Updated overview comment with no dependencies');
|
|
1278
1279
|
}
|
|
1279
1280
|
}
|
|
1280
1281
|
await scm.addSocketComments({
|
|
@@ -1402,6 +1403,8 @@ const validationFlags = {
|
|
|
1402
1403
|
};
|
|
1403
1404
|
|
|
1404
1405
|
const {
|
|
1406
|
+
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
1407
|
+
REDACTED,
|
|
1405
1408
|
SOCKET_CLI_SHOW_BANNER
|
|
1406
1409
|
} = constants;
|
|
1407
1410
|
async function meowWithSubcommands(subcommands, options) {
|
|
@@ -1439,7 +1442,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1439
1442
|
// Temp disable until we clear the --json and --markdown usage
|
|
1440
1443
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1441
1444
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1442
|
-
|
|
1445
|
+
logger.logger.log(getAsciiHeader(name));
|
|
1443
1446
|
}
|
|
1444
1447
|
const cli = meow(`
|
|
1445
1448
|
Usage
|
|
@@ -1475,7 +1478,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1475
1478
|
autoHelp: false // otherwise we can't exit(0)
|
|
1476
1479
|
});
|
|
1477
1480
|
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
1478
|
-
|
|
1481
|
+
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
1479
1482
|
process.exitCode = 0;
|
|
1480
1483
|
} else {
|
|
1481
1484
|
cli.showHelp();
|
|
@@ -1497,7 +1500,7 @@ function meowOrExit({
|
|
|
1497
1500
|
// Temp disable until we clear the --json and --markdown usage.
|
|
1498
1501
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1499
1502
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1500
|
-
|
|
1503
|
+
logger.logger.log(getAsciiHeader(command));
|
|
1501
1504
|
}
|
|
1502
1505
|
|
|
1503
1506
|
// This exits if .printHelp() is called either by meow itself or by us.
|
|
@@ -1517,7 +1520,7 @@ function meowOrExit({
|
|
|
1517
1520
|
}
|
|
1518
1521
|
function getAsciiHeader(command) {
|
|
1519
1522
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
|
|
1520
|
-
"0.14.
|
|
1523
|
+
"0.14.52:709a145:a30d9dfd:pub";
|
|
1521
1524
|
const nodeVersion = process.version;
|
|
1522
1525
|
const apiToken = index.getSetting('apiToken');
|
|
1523
1526
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -1532,6 +1535,9 @@ function getAsciiHeader(command) {
|
|
|
1532
1535
|
|
|
1533
1536
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
|
|
1534
1537
|
|
|
1538
|
+
const {
|
|
1539
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$y
|
|
1540
|
+
} = constants;
|
|
1535
1541
|
const config$z = {
|
|
1536
1542
|
commandName: 'action',
|
|
1537
1543
|
description: 'Socket action command',
|
|
@@ -1582,7 +1588,8 @@ async function run$z(argv, importMeta, {
|
|
|
1582
1588
|
const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
|
|
1583
1589
|
const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
|
|
1584
1590
|
if (cli.flags['dryRun']) {
|
|
1585
|
-
|
|
1591
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
1592
|
+
return;
|
|
1586
1593
|
}
|
|
1587
1594
|
await runAction(githubEventBefore, githubEventAfter);
|
|
1588
1595
|
}
|
|
@@ -1600,24 +1607,26 @@ async function displayAnalytics({
|
|
|
1600
1607
|
scope,
|
|
1601
1608
|
time
|
|
1602
1609
|
}) {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1610
|
+
// Lazily access constants.spinner.
|
|
1611
|
+
const {
|
|
1612
|
+
spinner
|
|
1613
|
+
} = constants;
|
|
1614
|
+
spinner.start('Fetching analytics data');
|
|
1606
1615
|
let data;
|
|
1607
1616
|
if (scope === 'org') {
|
|
1608
|
-
data = await fetchOrgAnalyticsData(time, spinner
|
|
1617
|
+
data = await fetchOrgAnalyticsData(time, spinner, apiToken);
|
|
1609
1618
|
} else if (repo) {
|
|
1610
|
-
data = await fetchRepoAnalyticsData(repo, time, spinner
|
|
1619
|
+
data = await fetchRepoAnalyticsData(repo, time, spinner, apiToken);
|
|
1611
1620
|
}
|
|
1612
1621
|
if (data) {
|
|
1613
1622
|
if (outputJson && !filePath) {
|
|
1614
|
-
|
|
1623
|
+
logger.logger.log(data);
|
|
1615
1624
|
} else if (filePath) {
|
|
1616
1625
|
try {
|
|
1617
1626
|
await fs$1.writeFile(filePath, JSON.stringify(data), 'utf8');
|
|
1618
|
-
|
|
1627
|
+
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1619
1628
|
} catch (e) {
|
|
1620
|
-
|
|
1629
|
+
logger.logger.error(e);
|
|
1621
1630
|
}
|
|
1622
1631
|
} else {
|
|
1623
1632
|
const fdata = scope === 'org' ? formatData(data, 'org') : formatData(data, 'repo');
|
|
@@ -1666,7 +1675,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiToken) {
|
|
|
1666
1675
|
}
|
|
1667
1676
|
spinner.stop();
|
|
1668
1677
|
if (!result.data.length) {
|
|
1669
|
-
|
|
1678
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1670
1679
|
return undefined;
|
|
1671
1680
|
}
|
|
1672
1681
|
return result.data;
|
|
@@ -1680,7 +1689,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiToken) {
|
|
|
1680
1689
|
}
|
|
1681
1690
|
spinner.stop();
|
|
1682
1691
|
if (!result.data.length) {
|
|
1683
|
-
|
|
1692
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1684
1693
|
return undefined;
|
|
1685
1694
|
}
|
|
1686
1695
|
return result.data;
|
|
@@ -1776,6 +1785,9 @@ function renderLineCharts(grid, screen, title, coords, data) {
|
|
|
1776
1785
|
line.setData([lineData]);
|
|
1777
1786
|
}
|
|
1778
1787
|
|
|
1788
|
+
const {
|
|
1789
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
1790
|
+
} = constants;
|
|
1779
1791
|
const config$y = {
|
|
1780
1792
|
commandName: 'analytics',
|
|
1781
1793
|
description: `Look up analytics data`,
|
|
@@ -1853,14 +1865,15 @@ async function run$y(argv, importMeta, {
|
|
|
1853
1865
|
// options or missing arguments.
|
|
1854
1866
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1855
1867
|
process.exitCode = 2;
|
|
1856
|
-
|
|
1868
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1857
1869
|
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1858
1870
|
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1859
1871
|
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`);
|
|
1860
1872
|
return;
|
|
1861
1873
|
}
|
|
1862
1874
|
if (cli.flags['dryRun']) {
|
|
1863
|
-
|
|
1875
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
1876
|
+
return;
|
|
1864
1877
|
}
|
|
1865
1878
|
const apiToken = index.getDefaultToken();
|
|
1866
1879
|
if (!apiToken) {
|
|
@@ -1885,9 +1898,11 @@ async function getAuditLog({
|
|
|
1885
1898
|
perPage,
|
|
1886
1899
|
type
|
|
1887
1900
|
}) {
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1901
|
+
// Lazily access constants.spinner.
|
|
1902
|
+
const {
|
|
1903
|
+
spinner
|
|
1904
|
+
} = constants;
|
|
1905
|
+
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
1891
1906
|
const socketSdk = await index.setupSdk(apiToken);
|
|
1892
1907
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
1893
1908
|
outputJson,
|
|
@@ -1898,10 +1913,10 @@ async function getAuditLog({
|
|
|
1898
1913
|
per_page: perPage
|
|
1899
1914
|
}), `Looking up audit log for ${orgSlug}\n`);
|
|
1900
1915
|
if (!result.success) {
|
|
1901
|
-
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner
|
|
1916
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
1902
1917
|
return;
|
|
1903
1918
|
}
|
|
1904
|
-
spinner
|
|
1919
|
+
spinner.stop();
|
|
1905
1920
|
const data = [];
|
|
1906
1921
|
const logDetails = {};
|
|
1907
1922
|
for (const d of result.data.results) {
|
|
@@ -1920,13 +1935,16 @@ async function getAuditLog({
|
|
|
1920
1935
|
logDetails[name] = JSON.stringify(d.payload);
|
|
1921
1936
|
}
|
|
1922
1937
|
}
|
|
1923
|
-
|
|
1938
|
+
logger.logger.log(logDetails[await prompts.select({
|
|
1924
1939
|
message: type ? `\n Audit log for: ${orgSlug} with type: ${type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
1925
1940
|
choices: data,
|
|
1926
1941
|
pageSize: 30
|
|
1927
1942
|
})]);
|
|
1928
1943
|
}
|
|
1929
1944
|
|
|
1945
|
+
const {
|
|
1946
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
1947
|
+
} = constants;
|
|
1930
1948
|
const config$x = {
|
|
1931
1949
|
commandName: 'audit-log',
|
|
1932
1950
|
description: 'Look up the audit log for an organization',
|
|
@@ -1985,12 +2003,13 @@ async function run$x(argv, importMeta, {
|
|
|
1985
2003
|
// options or missing arguments.
|
|
1986
2004
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1987
2005
|
process.exitCode = 2;
|
|
1988
|
-
|
|
2006
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1989
2007
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
1990
2008
|
return;
|
|
1991
2009
|
}
|
|
1992
2010
|
if (cli.flags['dryRun']) {
|
|
1993
|
-
|
|
2011
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
2012
|
+
return;
|
|
1994
2013
|
}
|
|
1995
2014
|
const apiToken = index.getDefaultToken();
|
|
1996
2015
|
if (!apiToken) {
|
|
@@ -2052,7 +2071,7 @@ async function runCycloneDX(yargv) {
|
|
|
2052
2071
|
}
|
|
2053
2072
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
2054
2073
|
if (fs.existsSync(fullOutputPath)) {
|
|
2055
|
-
|
|
2074
|
+
logger.logger.log(colors.cyanBright(`${yargv.output} created!`));
|
|
2056
2075
|
}
|
|
2057
2076
|
}
|
|
2058
2077
|
function argvToArray(argv) {
|
|
@@ -2082,6 +2101,10 @@ function argvToArray(argv) {
|
|
|
2082
2101
|
}
|
|
2083
2102
|
|
|
2084
2103
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2104
|
+
const {
|
|
2105
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
2106
|
+
} = constants;
|
|
2107
|
+
|
|
2085
2108
|
// TODO: convert yargs to meow. Or convert all the other things to yargs.
|
|
2086
2109
|
const toLower = arg => arg.toLowerCase();
|
|
2087
2110
|
const arrayToLower = arg => arg.map(toLower);
|
|
@@ -2186,7 +2209,7 @@ async function run$w(argv, importMeta, {
|
|
|
2186
2209
|
//
|
|
2187
2210
|
//
|
|
2188
2211
|
// if (cli.input.length)
|
|
2189
|
-
//
|
|
2212
|
+
// logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2190
2213
|
// - Unexpected arguments\n
|
|
2191
2214
|
// `)
|
|
2192
2215
|
// config.help(parentName, config)
|
|
@@ -2207,14 +2230,15 @@ async function run$w(argv, importMeta, {
|
|
|
2207
2230
|
// options or missing arguments.
|
|
2208
2231
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2209
2232
|
process$1.exitCode = 2;
|
|
2210
|
-
|
|
2233
|
+
logger.logger.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2211
2234
|
return;
|
|
2212
2235
|
}
|
|
2213
2236
|
if (yargv.output === undefined) {
|
|
2214
2237
|
yargv.output = 'socket-cdx.json';
|
|
2215
2238
|
}
|
|
2216
2239
|
if (cli.flags['dryRun']) {
|
|
2217
|
-
|
|
2240
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2241
|
+
return;
|
|
2218
2242
|
}
|
|
2219
2243
|
await runCycloneDX(yargv);
|
|
2220
2244
|
}
|
|
@@ -2229,21 +2253,23 @@ async function findDependencies({
|
|
|
2229
2253
|
if (!apiToken) {
|
|
2230
2254
|
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.');
|
|
2231
2255
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2256
|
+
// Lazily access constants.spinner.
|
|
2257
|
+
const {
|
|
2258
|
+
spinner
|
|
2259
|
+
} = constants;
|
|
2260
|
+
spinner.start('Searching dependencies...');
|
|
2235
2261
|
const socketSdk = await index.setupSdk(apiToken);
|
|
2236
2262
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
2237
2263
|
limit,
|
|
2238
2264
|
offset
|
|
2239
2265
|
}), 'Searching dependencies');
|
|
2240
2266
|
if (!result.success) {
|
|
2241
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner
|
|
2267
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
2242
2268
|
return;
|
|
2243
2269
|
}
|
|
2244
|
-
spinner
|
|
2270
|
+
spinner.stop('Organization dependencies:');
|
|
2245
2271
|
if (outputJson) {
|
|
2246
|
-
|
|
2272
|
+
logger.logger.log(result.data);
|
|
2247
2273
|
return;
|
|
2248
2274
|
}
|
|
2249
2275
|
const options = {
|
|
@@ -2270,9 +2296,12 @@ async function findDependencies({
|
|
|
2270
2296
|
name: colors.cyan('Direct')
|
|
2271
2297
|
}]
|
|
2272
2298
|
};
|
|
2273
|
-
|
|
2299
|
+
logger.logger.log(chalkTable(options, result.data.rows));
|
|
2274
2300
|
}
|
|
2275
2301
|
|
|
2302
|
+
const {
|
|
2303
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
2304
|
+
} = constants;
|
|
2276
2305
|
const config$v = {
|
|
2277
2306
|
commandName: 'dependencies',
|
|
2278
2307
|
description: 'Search for any dependency that is being used in your organization',
|
|
@@ -2319,7 +2348,8 @@ async function run$v(argv, importMeta, {
|
|
|
2319
2348
|
parentName
|
|
2320
2349
|
});
|
|
2321
2350
|
if (cli.flags['dryRun']) {
|
|
2322
|
-
|
|
2351
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
2352
|
+
return;
|
|
2323
2353
|
}
|
|
2324
2354
|
|
|
2325
2355
|
// TODO: markdown flag is ignored
|
|
@@ -2337,40 +2367,44 @@ async function getDiffScan({
|
|
|
2337
2367
|
orgSlug,
|
|
2338
2368
|
outputJson
|
|
2339
2369
|
}, apiToken) {
|
|
2340
|
-
|
|
2341
|
-
const
|
|
2342
|
-
|
|
2343
|
-
}
|
|
2370
|
+
// Lazily access constants.spinner.
|
|
2371
|
+
const {
|
|
2372
|
+
spinner
|
|
2373
|
+
} = constants;
|
|
2374
|
+
spinner.start('Getting diff scan...');
|
|
2344
2375
|
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiToken);
|
|
2345
2376
|
const data = await response.json();
|
|
2346
2377
|
if (!response.ok) {
|
|
2347
2378
|
const err = await handleAPIError(response.status);
|
|
2348
|
-
spinner
|
|
2379
|
+
spinner.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
2349
2380
|
return;
|
|
2350
2381
|
}
|
|
2351
|
-
spinner
|
|
2382
|
+
spinner.stop();
|
|
2352
2383
|
if (file && !outputJson) {
|
|
2353
2384
|
fs.writeFile(file, JSON.stringify(data), err => {
|
|
2354
|
-
err ?
|
|
2385
|
+
err ? logger.logger.error(err) : logger.logger.log(`Data successfully written to ${file}`);
|
|
2355
2386
|
});
|
|
2356
2387
|
return;
|
|
2357
2388
|
}
|
|
2358
2389
|
if (outputJson) {
|
|
2359
|
-
|
|
2360
|
-
|
|
2390
|
+
logger.logger.log(`\n Diff scan result: \n`);
|
|
2391
|
+
logger.logger.log(util.inspect(data, {
|
|
2361
2392
|
showHidden: false,
|
|
2362
2393
|
depth: null,
|
|
2363
2394
|
colors: true
|
|
2364
2395
|
}));
|
|
2365
|
-
|
|
2396
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2366
2397
|
return;
|
|
2367
2398
|
}
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2399
|
+
logger.logger.log('Diff scan result:');
|
|
2400
|
+
logger.logger.log(data);
|
|
2401
|
+
logger.logger.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
2402
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2372
2403
|
}
|
|
2373
2404
|
|
|
2405
|
+
const {
|
|
2406
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
2407
|
+
} = constants;
|
|
2374
2408
|
const config$u = {
|
|
2375
2409
|
commandName: 'get',
|
|
2376
2410
|
description: 'Get a diff scan for an organization',
|
|
@@ -2436,14 +2470,15 @@ async function run$u(argv, importMeta, {
|
|
|
2436
2470
|
// options or missing arguments.
|
|
2437
2471
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2438
2472
|
process.exitCode = 2;
|
|
2439
|
-
|
|
2473
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2440
2474
|
- Specify a before and after full scan ID ${!before && !after ? colors.red('(missing before and after!)') : !before ? colors.red('(missing before!)') : !after ? colors.red('(missing after!)') : colors.green('(ok)')}\n
|
|
2441
2475
|
- To get full scans IDs, you can run the command "socket scan list <your org slug>".
|
|
2442
2476
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
2443
2477
|
return;
|
|
2444
2478
|
}
|
|
2445
2479
|
if (cli.flags['dryRun']) {
|
|
2446
|
-
|
|
2480
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
2481
|
+
return;
|
|
2447
2482
|
}
|
|
2448
2483
|
const apiToken = index.getDefaultToken();
|
|
2449
2484
|
if (!apiToken) {
|
|
@@ -2486,7 +2521,11 @@ function isTopLevel(tree, node) {
|
|
|
2486
2521
|
return tree.children.get(node.name) === node;
|
|
2487
2522
|
}
|
|
2488
2523
|
async function runFix() {
|
|
2489
|
-
|
|
2524
|
+
// Lazily access constants.spinner.
|
|
2525
|
+
const {
|
|
2526
|
+
spinner
|
|
2527
|
+
} = constants;
|
|
2528
|
+
spinner.start();
|
|
2490
2529
|
const cwd = process.cwd();
|
|
2491
2530
|
const editablePkgJson = await packages.readPackageJson(cwd, {
|
|
2492
2531
|
editable: true
|
|
@@ -2517,9 +2556,7 @@ async function runFix() {
|
|
|
2517
2556
|
const tree = arb.idealTree;
|
|
2518
2557
|
const hasUpgrade = !!registry.getManifestData(NPM$d, name);
|
|
2519
2558
|
if (hasUpgrade) {
|
|
2520
|
-
spinner$
|
|
2521
|
-
console.log(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2522
|
-
spinner$1.start();
|
|
2559
|
+
spinner.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2523
2560
|
continue;
|
|
2524
2561
|
}
|
|
2525
2562
|
const nodes = index.findPackageNodes(tree, name);
|
|
@@ -2545,10 +2582,10 @@ async function runFix() {
|
|
|
2545
2582
|
try {
|
|
2546
2583
|
// eslint-disable-next-line no-await-in-loop
|
|
2547
2584
|
await npm.runScript('test', [], {
|
|
2548
|
-
|
|
2585
|
+
spinner,
|
|
2586
|
+
stdio: 'ignore'
|
|
2549
2587
|
});
|
|
2550
|
-
spinner
|
|
2551
|
-
spinner$1.start();
|
|
2588
|
+
spinner.info(`Patched ${name} ${oldVersion} -> ${node.version}`);
|
|
2552
2589
|
if (isTopLevel(tree, node)) {
|
|
2553
2590
|
for (const depField of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
2554
2591
|
const oldVersion = editablePkgJson.content[depField]?.[name];
|
|
@@ -2561,14 +2598,11 @@ async function runFix() {
|
|
|
2561
2598
|
// eslint-disable-next-line no-await-in-loop
|
|
2562
2599
|
await editablePkgJson.save();
|
|
2563
2600
|
} catch {
|
|
2564
|
-
spinner
|
|
2565
|
-
spinner$1.start();
|
|
2601
|
+
spinner.error(`Reverting ${name} to ${oldVersion}`);
|
|
2566
2602
|
arb.idealTree = revertToIdealTree;
|
|
2567
2603
|
}
|
|
2568
2604
|
} else {
|
|
2569
|
-
spinner
|
|
2570
|
-
console.log(`Could not patch ${name} ${oldVersion}`);
|
|
2571
|
-
spinner$1.start();
|
|
2605
|
+
spinner.error(`Could not patch ${name} ${oldVersion}`);
|
|
2572
2606
|
}
|
|
2573
2607
|
}
|
|
2574
2608
|
}
|
|
@@ -2580,9 +2614,12 @@ async function runFix() {
|
|
|
2580
2614
|
});
|
|
2581
2615
|
arb2.idealTree = arb.idealTree;
|
|
2582
2616
|
await arb2.reify();
|
|
2583
|
-
spinner
|
|
2617
|
+
spinner.stop();
|
|
2584
2618
|
}
|
|
2585
2619
|
|
|
2620
|
+
const {
|
|
2621
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
2622
|
+
} = constants;
|
|
2586
2623
|
const config$t = {
|
|
2587
2624
|
commandName: 'fix',
|
|
2588
2625
|
description: 'Fix "fixable" Socket alerts',
|
|
@@ -2613,7 +2650,8 @@ async function run$t(argv, importMeta, {
|
|
|
2613
2650
|
parentName
|
|
2614
2651
|
});
|
|
2615
2652
|
if (cli.flags['dryRun']) {
|
|
2616
|
-
|
|
2653
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
2654
|
+
return;
|
|
2617
2655
|
}
|
|
2618
2656
|
await runFix();
|
|
2619
2657
|
}
|
|
@@ -2725,9 +2763,9 @@ function formatPackageInfo({
|
|
|
2725
2763
|
strict
|
|
2726
2764
|
}, spinner) {
|
|
2727
2765
|
if (outputJson) {
|
|
2728
|
-
|
|
2766
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
2729
2767
|
} else {
|
|
2730
|
-
|
|
2768
|
+
logger.logger.log('\nPackage report card:');
|
|
2731
2769
|
const scoreResult = {
|
|
2732
2770
|
'Supply Chain Risk': Math.floor(score.supplyChainRisk.score * 100),
|
|
2733
2771
|
Maintenance: Math.floor(score.maintenance.score * 100),
|
|
@@ -2735,8 +2773,8 @@ function formatPackageInfo({
|
|
|
2735
2773
|
Vulnerabilities: Math.floor(score.vulnerability.score * 100),
|
|
2736
2774
|
License: Math.floor(score.license.score * 100)
|
|
2737
2775
|
};
|
|
2738
|
-
Object.entries(scoreResult).map(score =>
|
|
2739
|
-
|
|
2776
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2777
|
+
logger.logger.log('\n');
|
|
2740
2778
|
if (objectSome(severityCount)) {
|
|
2741
2779
|
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
2742
2780
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
@@ -2745,18 +2783,18 @@ function formatPackageInfo({
|
|
|
2745
2783
|
}
|
|
2746
2784
|
const format = new index.ColorOrMarkdown(!!outputMarkdown);
|
|
2747
2785
|
const url = index.getSocketDevPackageOverviewUrl(NPM$c, pkgName, pkgVersion);
|
|
2748
|
-
|
|
2786
|
+
logger.logger.log('\n');
|
|
2749
2787
|
if (pkgVersion === 'latest') {
|
|
2750
|
-
|
|
2788
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
2751
2789
|
fallbackToUrl: true
|
|
2752
2790
|
})}`);
|
|
2753
2791
|
} else {
|
|
2754
|
-
|
|
2792
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
|
|
2755
2793
|
fallbackToUrl: true
|
|
2756
2794
|
})}`);
|
|
2757
2795
|
}
|
|
2758
2796
|
if (!outputMarkdown) {
|
|
2759
|
-
|
|
2797
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2760
2798
|
}
|
|
2761
2799
|
}
|
|
2762
2800
|
if (strict && objectSome(severityCount)) {
|
|
@@ -2787,9 +2825,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2787
2825
|
fallbackToUrl: true
|
|
2788
2826
|
});
|
|
2789
2827
|
if (uniqueIssues[issue]?.count === 1) {
|
|
2790
|
-
|
|
2828
|
+
logger.logger.log(`- ${issueWithLink}`);
|
|
2791
2829
|
} else {
|
|
2792
|
-
|
|
2830
|
+
logger.logger.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`);
|
|
2793
2831
|
}
|
|
2794
2832
|
}
|
|
2795
2833
|
}
|
|
@@ -2811,11 +2849,12 @@ async function getPackageInfo({
|
|
|
2811
2849
|
pkgVersion,
|
|
2812
2850
|
strict
|
|
2813
2851
|
}) {
|
|
2814
|
-
|
|
2815
|
-
const
|
|
2816
|
-
|
|
2817
|
-
}
|
|
2818
|
-
|
|
2852
|
+
// Lazily access constants.spinner.
|
|
2853
|
+
const {
|
|
2854
|
+
spinner
|
|
2855
|
+
} = constants;
|
|
2856
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2857
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues, spinner);
|
|
2819
2858
|
if (packageData) {
|
|
2820
2859
|
formatPackageInfo(packageData, {
|
|
2821
2860
|
name: commandName,
|
|
@@ -2824,10 +2863,13 @@ async function getPackageInfo({
|
|
|
2824
2863
|
pkgName,
|
|
2825
2864
|
pkgVersion,
|
|
2826
2865
|
strict
|
|
2827
|
-
}, spinner
|
|
2866
|
+
}, spinner);
|
|
2828
2867
|
}
|
|
2829
2868
|
}
|
|
2830
2869
|
|
|
2870
|
+
const {
|
|
2871
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
2872
|
+
} = constants;
|
|
2831
2873
|
const config$s = {
|
|
2832
2874
|
commandName: 'info',
|
|
2833
2875
|
description: 'Look up info regarding a package',
|
|
@@ -2869,7 +2911,7 @@ async function run$s(argv, importMeta, {
|
|
|
2869
2911
|
// options or missing arguments.
|
|
2870
2912
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2871
2913
|
process.exitCode = 2;
|
|
2872
|
-
|
|
2914
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2873
2915
|
- Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
2874
2916
|
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`);
|
|
2875
2917
|
return;
|
|
@@ -2878,7 +2920,8 @@ async function run$s(argv, importMeta, {
|
|
|
2878
2920
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
2879
2921
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
2880
2922
|
if (cli.flags['dryRun']) {
|
|
2881
|
-
|
|
2923
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
2924
|
+
return;
|
|
2882
2925
|
}
|
|
2883
2926
|
await getPackageInfo({
|
|
2884
2927
|
commandName: `${parentName} ${config$s.commandName}`,
|
|
@@ -2904,14 +2947,16 @@ const {
|
|
|
2904
2947
|
SOCKET_PUBLIC_API_TOKEN
|
|
2905
2948
|
} = constants;
|
|
2906
2949
|
async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
2950
|
+
apiBaseUrl ??= index.getSetting('apiBaseUrl') ?? undefined;
|
|
2951
|
+
apiProxy ??= index.getSetting('apiProxy') ?? undefined;
|
|
2907
2952
|
const apiToken = (await prompts.password({
|
|
2908
2953
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
2909
2954
|
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2955
|
+
// Lazily access constants.spinner.
|
|
2956
|
+
const {
|
|
2957
|
+
spinner
|
|
2958
|
+
} = constants;
|
|
2959
|
+
spinner.start('Verifying API key...');
|
|
2915
2960
|
let orgs;
|
|
2916
2961
|
try {
|
|
2917
2962
|
const sdk = await index.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
@@ -2920,9 +2965,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2920
2965
|
throw new index.AuthError();
|
|
2921
2966
|
}
|
|
2922
2967
|
orgs = result.data;
|
|
2923
|
-
spinner
|
|
2968
|
+
spinner.success('API key verified');
|
|
2924
2969
|
} catch {
|
|
2925
|
-
spinner
|
|
2970
|
+
spinner.errorAndStop('Invalid API key');
|
|
2926
2971
|
return;
|
|
2927
2972
|
}
|
|
2928
2973
|
const enforcedChoices = Object.values(orgs.organizations).filter(org => org?.plan === 'enterprise').map(org => ({
|
|
@@ -2938,6 +2983,8 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2938
2983
|
value: '',
|
|
2939
2984
|
description: 'Pick "None" if this is a personal device'
|
|
2940
2985
|
})
|
|
2986
|
+
}, {
|
|
2987
|
+
spinner
|
|
2941
2988
|
});
|
|
2942
2989
|
if (id) {
|
|
2943
2990
|
enforcedOrgs = [id];
|
|
@@ -2946,6 +2993,8 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2946
2993
|
const confirmOrg = await prompts.confirm({
|
|
2947
2994
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
2948
2995
|
default: true
|
|
2996
|
+
}, {
|
|
2997
|
+
spinner
|
|
2949
2998
|
});
|
|
2950
2999
|
if (confirmOrg) {
|
|
2951
3000
|
const existing = enforcedChoices[0];
|
|
@@ -2957,12 +3006,15 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2957
3006
|
const oldToken = index.getSetting('apiToken');
|
|
2958
3007
|
try {
|
|
2959
3008
|
applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy);
|
|
2960
|
-
spinner
|
|
3009
|
+
spinner.successAndStop(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
2961
3010
|
} catch {
|
|
2962
|
-
spinner
|
|
3011
|
+
spinner.errorAndStop(`API login failed`);
|
|
2963
3012
|
}
|
|
2964
3013
|
}
|
|
2965
3014
|
|
|
3015
|
+
const {
|
|
3016
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
3017
|
+
} = constants;
|
|
2966
3018
|
const config$r = {
|
|
2967
3019
|
commandName: 'login',
|
|
2968
3020
|
description: 'Socket API login',
|
|
@@ -3009,7 +3061,8 @@ async function run$r(argv, importMeta, {
|
|
|
3009
3061
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3010
3062
|
let apiProxy = cli.flags['apiProxy'];
|
|
3011
3063
|
if (cli.flags['dryRun']) {
|
|
3012
|
-
|
|
3064
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
3065
|
+
return;
|
|
3013
3066
|
}
|
|
3014
3067
|
if (!isInteractive()) {
|
|
3015
3068
|
throw new index.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
@@ -3027,12 +3080,15 @@ function applyLogout() {
|
|
|
3027
3080
|
function attemptLogout() {
|
|
3028
3081
|
try {
|
|
3029
3082
|
applyLogout();
|
|
3030
|
-
|
|
3083
|
+
logger.logger.success('Successfully logged out');
|
|
3031
3084
|
} catch {
|
|
3032
|
-
|
|
3085
|
+
logger.logger.error('Failed to complete logout steps');
|
|
3033
3086
|
}
|
|
3034
3087
|
}
|
|
3035
3088
|
|
|
3089
|
+
const {
|
|
3090
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
3091
|
+
} = constants;
|
|
3036
3092
|
const config$q = {
|
|
3037
3093
|
commandName: 'logout',
|
|
3038
3094
|
description: 'Socket API logout',
|
|
@@ -3062,31 +3118,31 @@ async function run$q(argv, importMeta, {
|
|
|
3062
3118
|
parentName
|
|
3063
3119
|
});
|
|
3064
3120
|
if (cli.flags['dryRun']) {
|
|
3065
|
-
|
|
3121
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
3122
|
+
return;
|
|
3066
3123
|
}
|
|
3067
3124
|
attemptLogout();
|
|
3068
3125
|
}
|
|
3069
3126
|
|
|
3070
3127
|
async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
3128
|
+
// Lazily access constants.spinner.
|
|
3129
|
+
const {
|
|
3130
|
+
spinner
|
|
3131
|
+
} = constants;
|
|
3071
3132
|
const rbin = path.resolve(bin);
|
|
3072
3133
|
const rtarget = path.resolve(target);
|
|
3073
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3074
|
-
|
|
3075
3134
|
if (verbose) {
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
console.groupEnd();
|
|
3135
|
+
logger.logger.group('gradle2maven:');
|
|
3136
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3137
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3138
|
+
logger.logger.groupEnd();
|
|
3081
3139
|
} else {
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
}
|
|
3088
|
-
const spinner$1 = new spinner.Spinner();
|
|
3089
|
-
spinner$1.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3140
|
+
logger.logger.group('gradle2maven:');
|
|
3141
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3142
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3143
|
+
logger.logger.groupEnd();
|
|
3144
|
+
}
|
|
3145
|
+
spinner.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3090
3146
|
try {
|
|
3091
3147
|
// Run sbt with the init script we provide which should yield zero or more pom files.
|
|
3092
3148
|
// We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API.
|
|
@@ -3096,38 +3152,37 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3096
3152
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
3097
3153
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
3098
3154
|
if (verbose) {
|
|
3099
|
-
|
|
3155
|
+
spinner.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
3100
3156
|
}
|
|
3101
3157
|
const output = await spawn(bin, commandArgs, {
|
|
3102
3158
|
cwd: target || '.'
|
|
3103
3159
|
});
|
|
3104
|
-
spinner
|
|
3160
|
+
spinner.stop();
|
|
3105
3161
|
if (verbose) {
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3162
|
+
logger.logger.group('[VERBOSE] gradle stdout:');
|
|
3163
|
+
logger.logger.log(output);
|
|
3164
|
+
logger.logger.groupEnd();
|
|
3109
3165
|
}
|
|
3110
3166
|
if (output.stderr) {
|
|
3111
|
-
|
|
3167
|
+
logger.logger.error('There were errors while running gradle');
|
|
3112
3168
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3113
3169
|
if (!verbose) {
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3170
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3171
|
+
logger.logger.error(output.stderr);
|
|
3172
|
+
logger.logger.groupEnd();
|
|
3117
3173
|
}
|
|
3118
3174
|
process.exit(1);
|
|
3119
3175
|
}
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
console.log('Reported exports:');
|
|
3176
|
+
logger.logger.success('Executed gradle successfully');
|
|
3177
|
+
logger.logger.log('Reported exports:');
|
|
3123
3178
|
output.stdout.replace(/^POM file copied to: (.*)/gm, (_all, fn) => {
|
|
3124
|
-
|
|
3179
|
+
logger.logger.log('- ', fn);
|
|
3125
3180
|
return fn;
|
|
3126
3181
|
});
|
|
3127
3182
|
|
|
3128
3183
|
// const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
|
|
3129
3184
|
// if (!loc) {
|
|
3130
|
-
//
|
|
3185
|
+
// logger.error(
|
|
3131
3186
|
// 'There were no errors from sbt but could not find the location of resulting .pom file either'
|
|
3132
3187
|
// )
|
|
3133
3188
|
// process.exit(1)
|
|
@@ -3135,34 +3190,38 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3135
3190
|
//
|
|
3136
3191
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3137
3192
|
// if (out === '-') {
|
|
3138
|
-
// spinner.start('Result:\n```')
|
|
3139
|
-
//
|
|
3140
|
-
//
|
|
3141
|
-
// spinner.
|
|
3193
|
+
// spinner.start('Result:\n```')
|
|
3194
|
+
// spinner.log(await safeReadFile(loc, 'utf8'))
|
|
3195
|
+
// spinner.log('```')
|
|
3196
|
+
// spinner.successAndStop(`OK`)
|
|
3142
3197
|
// } else {
|
|
3198
|
+
// spinner.start()
|
|
3143
3199
|
// if (verbose) {
|
|
3144
|
-
// spinner.
|
|
3200
|
+
// spinner.log(
|
|
3145
3201
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3146
3202
|
// )
|
|
3147
3203
|
// } else {
|
|
3148
|
-
// spinner.
|
|
3204
|
+
// spinner.log('Moving output pom file')
|
|
3149
3205
|
// }
|
|
3150
3206
|
// // TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3151
3207
|
// await renamep(loc, out)
|
|
3152
|
-
// spinner.successAndStop()
|
|
3153
|
-
// spinner.start().success(`OK. File should be available in \`${out}\``)
|
|
3208
|
+
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
|
|
3154
3209
|
// }
|
|
3155
3210
|
} catch (e) {
|
|
3156
|
-
spinner
|
|
3211
|
+
spinner.stop();
|
|
3212
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3157
3213
|
if (verbose) {
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3214
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3215
|
+
logger.logger.log(e);
|
|
3216
|
+
logger.logger.groupEnd();
|
|
3161
3217
|
}
|
|
3162
3218
|
process.exit(1);
|
|
3163
3219
|
}
|
|
3164
3220
|
}
|
|
3165
3221
|
|
|
3222
|
+
const {
|
|
3223
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o
|
|
3224
|
+
} = constants;
|
|
3166
3225
|
const config$p = {
|
|
3167
3226
|
commandName: 'gradle',
|
|
3168
3227
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
@@ -3250,22 +3309,23 @@ async function run$p(argv, importMeta, {
|
|
|
3250
3309
|
});
|
|
3251
3310
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3252
3311
|
if (verbose) {
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3312
|
+
logger.logger.group('- ', parentName, config$p.commandName, ':');
|
|
3313
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3314
|
+
logger.logger.groupEnd();
|
|
3315
|
+
logger.logger.log('- input:', cli.input);
|
|
3316
|
+
logger.logger.groupEnd();
|
|
3258
3317
|
}
|
|
3259
3318
|
const target = cli.input[0];
|
|
3260
3319
|
|
|
3261
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3262
|
-
|
|
3320
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3321
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3322
|
+
// would the file name be?
|
|
3263
3323
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3264
3324
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3265
3325
|
// options or missing arguments.
|
|
3266
3326
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3267
3327
|
process.exitCode = 2;
|
|
3268
|
-
|
|
3328
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3269
3329
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3270
3330
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3271
3331
|
return;
|
|
@@ -3284,64 +3344,66 @@ async function run$p(argv, importMeta, {
|
|
|
3284
3344
|
out = '-';
|
|
3285
3345
|
}
|
|
3286
3346
|
if (verbose) {
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3347
|
+
logger.logger.group();
|
|
3348
|
+
logger.logger.log('- target:', target);
|
|
3349
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3350
|
+
logger.logger.log('- out:', out);
|
|
3351
|
+
logger.logger.groupEnd();
|
|
3292
3352
|
}
|
|
3293
3353
|
let gradleOpts = [];
|
|
3294
3354
|
if (cli.flags['gradleOpts']) {
|
|
3295
3355
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3296
3356
|
}
|
|
3297
3357
|
if (cli.flags['dryRun']) {
|
|
3298
|
-
|
|
3358
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
3359
|
+
return;
|
|
3299
3360
|
}
|
|
3300
3361
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3301
3362
|
}
|
|
3302
3363
|
|
|
3303
3364
|
async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
3365
|
+
// Lazily access constants.spinner.
|
|
3366
|
+
const {
|
|
3367
|
+
spinner
|
|
3368
|
+
} = constants;
|
|
3304
3369
|
const rbin = path.resolve(bin);
|
|
3305
3370
|
const rtarget = path.resolve(target);
|
|
3306
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3307
|
-
|
|
3308
3371
|
if (verbose) {
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
//
|
|
3313
|
-
|
|
3372
|
+
logger.logger.group('sbt2maven:');
|
|
3373
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3374
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3375
|
+
// logger.log(`[VERBOSE] - Absolute out path: \`${rout}\``)
|
|
3376
|
+
logger.logger.groupEnd();
|
|
3314
3377
|
} else {
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
//
|
|
3319
|
-
|
|
3320
|
-
}
|
|
3321
|
-
|
|
3322
|
-
spinner$1.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3378
|
+
logger.logger.group('sbt2maven:');
|
|
3379
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3380
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3381
|
+
// logger.log(`- dst dir: \`${out}\``)
|
|
3382
|
+
logger.logger.groupEnd();
|
|
3383
|
+
}
|
|
3384
|
+
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3323
3385
|
try {
|
|
3324
|
-
// Run sbt with the init script we provide which should yield zero or more
|
|
3325
|
-
// We have to figure out where to store those pom files such that
|
|
3326
|
-
//
|
|
3327
|
-
|
|
3386
|
+
// Run sbt with the init script we provide which should yield zero or more
|
|
3387
|
+
// pom files. We have to figure out where to store those pom files such that
|
|
3388
|
+
// we can upload them and predict them through the GitHub API. We could do a
|
|
3389
|
+
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3390
|
+
// I'd prefer something plain-text if it is to be committed.
|
|
3328
3391
|
const output = await spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3329
3392
|
cwd: target || '.'
|
|
3330
3393
|
});
|
|
3331
|
-
spinner
|
|
3394
|
+
spinner.stop();
|
|
3332
3395
|
if (verbose) {
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3396
|
+
logger.logger.group('[VERBOSE] sbt stdout:');
|
|
3397
|
+
logger.logger.log(output);
|
|
3398
|
+
logger.logger.groupEnd();
|
|
3336
3399
|
}
|
|
3337
3400
|
if (output.stderr) {
|
|
3338
|
-
|
|
3339
|
-
spinner$1.errorAndStop('There were errors while running sbt');
|
|
3401
|
+
logger.logger.error('There were errors while running sbt');
|
|
3340
3402
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3341
3403
|
if (!verbose) {
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3404
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3405
|
+
logger.logger.error(output.stderr);
|
|
3406
|
+
logger.logger.groupEnd();
|
|
3345
3407
|
}
|
|
3346
3408
|
process.exit(1);
|
|
3347
3409
|
}
|
|
@@ -3351,48 +3413,51 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3351
3413
|
return fn;
|
|
3352
3414
|
});
|
|
3353
3415
|
if (!poms.length) {
|
|
3354
|
-
|
|
3416
|
+
logger.logger.error('There were no errors from sbt but it seems to not have generated any poms either');
|
|
3355
3417
|
process.exit(1);
|
|
3356
3418
|
}
|
|
3357
|
-
|
|
3358
3419
|
// Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3359
3420
|
// TODO: what to do with multiple output files? Do we want to dump them to stdout? Raw or with separators or ?
|
|
3360
3421
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
3361
3422
|
if (out === '-' && poms.length === 1) {
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3423
|
+
logger.logger.log('Result:\n```');
|
|
3424
|
+
logger.logger.log(await index.safeReadFile(poms[0], 'utf8'));
|
|
3425
|
+
logger.logger.log('```');
|
|
3426
|
+
logger.logger.success(`OK`);
|
|
3366
3427
|
} else if (out === '-') {
|
|
3367
|
-
|
|
3368
|
-
poms.forEach(fn =>
|
|
3369
|
-
|
|
3428
|
+
logger.logger.error('Requested out target was stdout but there are multiple generated files');
|
|
3429
|
+
poms.forEach(fn => logger.logger.error('-', fn));
|
|
3430
|
+
logger.logger.error('Exiting now...');
|
|
3370
3431
|
process.exit(1);
|
|
3371
3432
|
} else {
|
|
3372
3433
|
// if (verbose) {
|
|
3373
|
-
//
|
|
3434
|
+
// logger.log(
|
|
3374
3435
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3375
3436
|
// )
|
|
3376
3437
|
// } else {
|
|
3377
|
-
//
|
|
3438
|
+
// logger.log('Moving output pom file')
|
|
3378
3439
|
// }
|
|
3379
3440
|
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3380
3441
|
// await renamep(loc, out)
|
|
3381
|
-
|
|
3382
|
-
poms.forEach(fn =>
|
|
3383
|
-
|
|
3442
|
+
logger.logger.success(`Generated ${poms.length} pom files`);
|
|
3443
|
+
poms.forEach(fn => logger.logger.log('-', fn));
|
|
3444
|
+
logger.logger.success(`OK`);
|
|
3384
3445
|
}
|
|
3385
3446
|
} catch (e) {
|
|
3386
|
-
spinner
|
|
3447
|
+
spinner.stop();
|
|
3448
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3387
3449
|
if (verbose) {
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3450
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3451
|
+
logger.logger.log(e);
|
|
3452
|
+
logger.logger.groupEnd();
|
|
3391
3453
|
}
|
|
3392
3454
|
process.exit(1);
|
|
3393
3455
|
}
|
|
3394
3456
|
}
|
|
3395
3457
|
|
|
3458
|
+
const {
|
|
3459
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n
|
|
3460
|
+
} = constants;
|
|
3396
3461
|
const config$o = {
|
|
3397
3462
|
commandName: 'scala',
|
|
3398
3463
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
@@ -3470,7 +3535,6 @@ const cmdManifestScala = {
|
|
|
3470
3535
|
async function run$o(argv, importMeta, {
|
|
3471
3536
|
parentName
|
|
3472
3537
|
}) {
|
|
3473
|
-
// console.log('scala', argv, parentName)
|
|
3474
3538
|
const cli = meowOrExit({
|
|
3475
3539
|
argv,
|
|
3476
3540
|
config: config$o,
|
|
@@ -3479,22 +3543,23 @@ async function run$o(argv, importMeta, {
|
|
|
3479
3543
|
});
|
|
3480
3544
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3481
3545
|
if (verbose) {
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3546
|
+
logger.logger.group('- ', parentName, config$o.commandName, ':');
|
|
3547
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3548
|
+
logger.logger.groupEnd();
|
|
3549
|
+
logger.logger.log('- input:', cli.input);
|
|
3550
|
+
logger.logger.groupEnd();
|
|
3487
3551
|
}
|
|
3488
3552
|
const target = cli.input[0];
|
|
3489
3553
|
|
|
3490
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3491
|
-
|
|
3554
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3555
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3556
|
+
// would the file name be?
|
|
3492
3557
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3493
3558
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3494
3559
|
// options or missing arguments.
|
|
3495
3560
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3496
3561
|
process.exitCode = 2;
|
|
3497
|
-
|
|
3562
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3498
3563
|
- The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3499
3564
|
- Can only accept one DIR or FILE (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3500
3565
|
return;
|
|
@@ -3511,22 +3576,26 @@ async function run$o(argv, importMeta, {
|
|
|
3511
3576
|
out = '-';
|
|
3512
3577
|
}
|
|
3513
3578
|
if (verbose) {
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3579
|
+
logger.logger.group();
|
|
3580
|
+
logger.logger.log('- target:', target);
|
|
3581
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3582
|
+
logger.logger.log('- out:', out);
|
|
3583
|
+
logger.logger.groupEnd();
|
|
3519
3584
|
}
|
|
3520
3585
|
let sbtOpts = [];
|
|
3521
3586
|
if (cli.flags['sbtOpts']) {
|
|
3522
3587
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3523
3588
|
}
|
|
3524
3589
|
if (cli.flags['dryRun']) {
|
|
3525
|
-
|
|
3590
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
3591
|
+
return;
|
|
3526
3592
|
}
|
|
3527
3593
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
3528
3594
|
}
|
|
3529
3595
|
|
|
3596
|
+
const {
|
|
3597
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
3598
|
+
} = constants;
|
|
3530
3599
|
const config$n = {
|
|
3531
3600
|
commandName: 'auto',
|
|
3532
3601
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
@@ -3573,12 +3642,12 @@ async function run$n(argv, importMeta, {
|
|
|
3573
3642
|
const verbose = !!cli.flags['verbose'];
|
|
3574
3643
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
3575
3644
|
if (verbose) {
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3645
|
+
logger.logger.group('- ', parentName, config$n.commandName, ':');
|
|
3646
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3647
|
+
logger.logger.groupEnd();
|
|
3648
|
+
logger.logger.log('- input:', cli.input);
|
|
3649
|
+
logger.logger.log('- cwd:', cwd);
|
|
3650
|
+
logger.logger.groupEnd();
|
|
3582
3651
|
}
|
|
3583
3652
|
const subArgs = [];
|
|
3584
3653
|
if (verbose) {
|
|
@@ -3586,13 +3655,14 @@ async function run$n(argv, importMeta, {
|
|
|
3586
3655
|
}
|
|
3587
3656
|
const dir = cwd;
|
|
3588
3657
|
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3589
|
-
|
|
3658
|
+
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
3590
3659
|
if (cwd) {
|
|
3591
3660
|
subArgs.push('--cwd', cwd);
|
|
3592
3661
|
}
|
|
3593
3662
|
subArgs.push(dir);
|
|
3594
3663
|
if (cli.flags['dryRun']) {
|
|
3595
|
-
|
|
3664
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3665
|
+
return;
|
|
3596
3666
|
}
|
|
3597
3667
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
3598
3668
|
parentName
|
|
@@ -3600,13 +3670,14 @@ async function run$n(argv, importMeta, {
|
|
|
3600
3670
|
return;
|
|
3601
3671
|
}
|
|
3602
3672
|
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3603
|
-
|
|
3673
|
+
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
3604
3674
|
if (cwd) {
|
|
3605
3675
|
// This command takes the cwd as first arg.
|
|
3606
3676
|
subArgs.push(cwd);
|
|
3607
3677
|
}
|
|
3608
3678
|
if (cli.flags['dryRun']) {
|
|
3609
|
-
|
|
3679
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3680
|
+
return;
|
|
3610
3681
|
}
|
|
3611
3682
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
3612
3683
|
parentName
|
|
@@ -3634,6 +3705,10 @@ async function run$n(argv, importMeta, {
|
|
|
3634
3705
|
}).showHelp();
|
|
3635
3706
|
}
|
|
3636
3707
|
|
|
3708
|
+
const {
|
|
3709
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
3710
|
+
} = constants;
|
|
3711
|
+
|
|
3637
3712
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
3638
3713
|
// makes sense to have separate commands for them and I think it makes
|
|
3639
3714
|
// sense for the help panels to note the requested language, rather than
|
|
@@ -3726,22 +3801,23 @@ async function run$m(argv, importMeta, {
|
|
|
3726
3801
|
});
|
|
3727
3802
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3728
3803
|
if (verbose) {
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3804
|
+
logger.logger.group('- ', parentName, config$m.commandName, ':');
|
|
3805
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3806
|
+
logger.logger.groupEnd();
|
|
3807
|
+
logger.logger.log('- input:', cli.input);
|
|
3808
|
+
logger.logger.groupEnd();
|
|
3734
3809
|
}
|
|
3735
3810
|
const target = cli.input[0];
|
|
3736
3811
|
|
|
3737
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3738
|
-
|
|
3812
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3813
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3814
|
+
// would the file name be?
|
|
3739
3815
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3740
3816
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3741
3817
|
// options or missing arguments.
|
|
3742
3818
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3743
3819
|
process.exitCode = 2;
|
|
3744
|
-
|
|
3820
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3745
3821
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3746
3822
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3747
3823
|
return;
|
|
@@ -3760,18 +3836,19 @@ async function run$m(argv, importMeta, {
|
|
|
3760
3836
|
out = '-';
|
|
3761
3837
|
}
|
|
3762
3838
|
if (verbose) {
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3839
|
+
logger.logger.group();
|
|
3840
|
+
logger.logger.log('- target:', target);
|
|
3841
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3842
|
+
logger.logger.log('- out:', out);
|
|
3843
|
+
logger.logger.groupEnd();
|
|
3768
3844
|
}
|
|
3769
3845
|
let gradleOpts = [];
|
|
3770
3846
|
if (cli.flags['gradleOpts']) {
|
|
3771
3847
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3772
3848
|
}
|
|
3773
3849
|
if (cli.flags['dryRun']) {
|
|
3774
|
-
|
|
3850
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
3851
|
+
return;
|
|
3775
3852
|
}
|
|
3776
3853
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3777
3854
|
}
|
|
@@ -3823,6 +3900,7 @@ async function wrapNpm(argv) {
|
|
|
3823
3900
|
}
|
|
3824
3901
|
|
|
3825
3902
|
const {
|
|
3903
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
3826
3904
|
NPM: NPM$a
|
|
3827
3905
|
} = constants;
|
|
3828
3906
|
const config$k = {
|
|
@@ -3851,7 +3929,8 @@ async function run$k(argv, importMeta, {
|
|
|
3851
3929
|
parentName
|
|
3852
3930
|
});
|
|
3853
3931
|
if (cli.flags['dryRun']) {
|
|
3854
|
-
|
|
3932
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
3933
|
+
return;
|
|
3855
3934
|
}
|
|
3856
3935
|
await wrapNpm(argv);
|
|
3857
3936
|
}
|
|
@@ -3867,6 +3946,7 @@ async function wrapNpx(argv) {
|
|
|
3867
3946
|
}
|
|
3868
3947
|
|
|
3869
3948
|
const {
|
|
3949
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j,
|
|
3870
3950
|
NPX: NPX$1
|
|
3871
3951
|
} = constants;
|
|
3872
3952
|
const config$j = {
|
|
@@ -3895,11 +3975,15 @@ async function run$j(argv, importMeta, {
|
|
|
3895
3975
|
parentName
|
|
3896
3976
|
});
|
|
3897
3977
|
if (cli.flags['dryRun']) {
|
|
3898
|
-
|
|
3978
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
3979
|
+
return;
|
|
3899
3980
|
}
|
|
3900
3981
|
await wrapNpx(argv);
|
|
3901
3982
|
}
|
|
3902
3983
|
|
|
3984
|
+
const {
|
|
3985
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
3986
|
+
} = constants;
|
|
3903
3987
|
const config$i = {
|
|
3904
3988
|
commandName: 'oops',
|
|
3905
3989
|
description: 'Trigger an intentional error (for development)',
|
|
@@ -3929,7 +4013,8 @@ async function run$i(argv, importMeta, {
|
|
|
3929
4013
|
parentName
|
|
3930
4014
|
});
|
|
3931
4015
|
if (cli.flags['dryRun']) {
|
|
3932
|
-
|
|
4016
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4017
|
+
return;
|
|
3933
4018
|
}
|
|
3934
4019
|
throw new Error('This error was intentionally left blank');
|
|
3935
4020
|
}
|
|
@@ -4640,7 +4725,7 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4640
4725
|
__proto__: null,
|
|
4641
4726
|
...options
|
|
4642
4727
|
};
|
|
4643
|
-
const isSilent = !
|
|
4728
|
+
const isSilent = !debug.isDebug();
|
|
4644
4729
|
const isSpinning = spinner?.isSpinning ?? false;
|
|
4645
4730
|
if (!isSilent) {
|
|
4646
4731
|
spinner?.stop();
|
|
@@ -4688,7 +4773,8 @@ async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
|
4688
4773
|
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
4689
4774
|
}
|
|
4690
4775
|
} catch (e) {
|
|
4691
|
-
spinner?.
|
|
4776
|
+
spinner?.stop();
|
|
4777
|
+
logger?.error(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
4692
4778
|
logger?.error(e);
|
|
4693
4779
|
}
|
|
4694
4780
|
}
|
|
@@ -4701,44 +4787,44 @@ const {
|
|
|
4701
4787
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
4702
4788
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
4703
4789
|
async function applyOptimization(cwd, pin, prod) {
|
|
4704
|
-
const logger = console;
|
|
4705
4790
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
4706
|
-
logger,
|
|
4791
|
+
logger: logger.logger,
|
|
4707
4792
|
prod
|
|
4708
4793
|
});
|
|
4709
4794
|
if (!pkgEnvDetails) {
|
|
4710
4795
|
return;
|
|
4711
4796
|
}
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4797
|
+
// Lazily access constants.spinner.
|
|
4798
|
+
const {
|
|
4799
|
+
spinner
|
|
4800
|
+
} = constants;
|
|
4801
|
+
spinner.start('Socket optimizing...');
|
|
4716
4802
|
const state = await addOverrides(pkgEnvDetails.pkgPath, pkgEnvDetails, {
|
|
4717
|
-
logger,
|
|
4803
|
+
logger: logger.logger,
|
|
4718
4804
|
pin,
|
|
4719
4805
|
prod,
|
|
4720
|
-
spinner
|
|
4806
|
+
spinner
|
|
4721
4807
|
});
|
|
4722
|
-
spinner
|
|
4808
|
+
spinner.stop();
|
|
4723
4809
|
const addedCount = state.added.size;
|
|
4724
4810
|
const updatedCount = state.updated.size;
|
|
4725
4811
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
4726
4812
|
if (pkgJsonChanged) {
|
|
4727
4813
|
if (updatedCount > 0) {
|
|
4728
|
-
logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4814
|
+
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4729
4815
|
}
|
|
4730
4816
|
if (addedCount > 0) {
|
|
4731
|
-
logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4817
|
+
logger.logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4732
4818
|
}
|
|
4733
4819
|
} else {
|
|
4734
|
-
logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4820
|
+
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4735
4821
|
}
|
|
4736
4822
|
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
4737
4823
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
4738
4824
|
// https://github.com/npm/cli/pull/8089
|
|
4739
4825
|
await updatePackageLockJson(pkgEnvDetails, {
|
|
4740
|
-
logger,
|
|
4741
|
-
spinner
|
|
4826
|
+
logger: logger.logger,
|
|
4827
|
+
spinner
|
|
4742
4828
|
});
|
|
4743
4829
|
}
|
|
4744
4830
|
}
|
|
@@ -4805,9 +4891,7 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4805
4891
|
} else {
|
|
4806
4892
|
overridesDataObjects.push(overridesDataByAgent.get(NPM$1)(pkgJson), overridesDataByAgent.get(YARN_CLASSIC)(pkgJson));
|
|
4807
4893
|
}
|
|
4808
|
-
|
|
4809
|
-
spinner.text = `Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`;
|
|
4810
|
-
}
|
|
4894
|
+
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
4811
4895
|
const depAliasMap = new Map();
|
|
4812
4896
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
4813
4897
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
@@ -4926,6 +5010,9 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4926
5010
|
return state;
|
|
4927
5011
|
}
|
|
4928
5012
|
|
|
5013
|
+
const {
|
|
5014
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
5015
|
+
} = constants;
|
|
4929
5016
|
const config$h = {
|
|
4930
5017
|
commandName: 'optimize',
|
|
4931
5018
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
@@ -4971,7 +5058,8 @@ async function run$h(argv, importMeta, {
|
|
|
4971
5058
|
});
|
|
4972
5059
|
const cwd = process$1.cwd();
|
|
4973
5060
|
if (cli.flags['dryRun']) {
|
|
4974
|
-
|
|
5061
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5062
|
+
return;
|
|
4975
5063
|
}
|
|
4976
5064
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4977
5065
|
}
|
|
@@ -4984,22 +5072,24 @@ async function getOrganization(format = 'text') {
|
|
|
4984
5072
|
await printOrganizationsFromToken(apiToken, format);
|
|
4985
5073
|
}
|
|
4986
5074
|
async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
5075
|
+
// Lazily access constants.spinner.
|
|
5076
|
+
const {
|
|
5077
|
+
spinner
|
|
5078
|
+
} = constants;
|
|
5079
|
+
spinner.start('Fetching organizations...');
|
|
4990
5080
|
const socketSdk = await index.setupSdk(apiToken);
|
|
4991
5081
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4992
5082
|
if (!result.success) {
|
|
4993
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner
|
|
5083
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
4994
5084
|
return;
|
|
4995
5085
|
}
|
|
4996
|
-
spinner
|
|
5086
|
+
spinner.stop();
|
|
4997
5087
|
const organizations = Object.values(result.data.organizations);
|
|
4998
5088
|
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken);
|
|
4999
5089
|
switch (format) {
|
|
5000
5090
|
case 'json':
|
|
5001
5091
|
{
|
|
5002
|
-
|
|
5092
|
+
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
5003
5093
|
name: o.name,
|
|
5004
5094
|
id: o.id,
|
|
5005
5095
|
plan: o.plan
|
|
@@ -5020,27 +5110,30 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5020
5110
|
mw2 = Math.max(mw2, o.id.length);
|
|
5021
5111
|
mw3 = Math.max(mw3, o.plan.length);
|
|
5022
5112
|
}
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5113
|
+
logger.logger.log('# Organizations\n');
|
|
5114
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5115
|
+
logger.logger.log(`| Name${' '.repeat(mw1 - 4)} | ID${' '.repeat(mw2 - 2)} | Plan${' '.repeat(mw3 - 4)} |`);
|
|
5116
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5027
5117
|
for (const o of organizations) {
|
|
5028
|
-
|
|
5118
|
+
logger.logger.log(`| ${(o.name || '').padEnd(mw1, ' ')} | ${(o.id || '').padEnd(mw2, ' ')} | ${(o.plan || '').padEnd(mw3, ' ')} |`);
|
|
5029
5119
|
}
|
|
5030
|
-
|
|
5120
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5031
5121
|
return;
|
|
5032
5122
|
}
|
|
5033
5123
|
default:
|
|
5034
5124
|
{
|
|
5035
|
-
|
|
5125
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5036
5126
|
// Just dump
|
|
5037
5127
|
for (const o of organizations) {
|
|
5038
|
-
|
|
5128
|
+
logger.logger.log(`- Name: ${colors.bold(o.name)}, ID: ${colors.bold(o.id)}, Plan: ${colors.bold(o.plan)}`);
|
|
5039
5129
|
}
|
|
5040
5130
|
}
|
|
5041
5131
|
}
|
|
5042
5132
|
}
|
|
5043
5133
|
|
|
5134
|
+
const {
|
|
5135
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$g
|
|
5136
|
+
} = constants;
|
|
5044
5137
|
const config$g = {
|
|
5045
5138
|
commandName: 'organizations',
|
|
5046
5139
|
description: 'List organizations associated with the API key used',
|
|
@@ -5078,14 +5171,15 @@ async function run$g(argv, importMeta, {
|
|
|
5078
5171
|
// options or missing arguments.
|
|
5079
5172
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5080
5173
|
process.exitCode = 2;
|
|
5081
|
-
|
|
5174
|
+
logger.logger.error(`
|
|
5082
5175
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5083
5176
|
- The json and markdown flags cannot be both set, pick one
|
|
5084
5177
|
`);
|
|
5085
5178
|
return;
|
|
5086
5179
|
}
|
|
5087
5180
|
if (cli.flags['dryRun']) {
|
|
5088
|
-
|
|
5181
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$g);
|
|
5182
|
+
return;
|
|
5089
5183
|
}
|
|
5090
5184
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5091
5185
|
}
|
|
@@ -5113,6 +5207,7 @@ async function runRawNpm(argv) {
|
|
|
5113
5207
|
}
|
|
5114
5208
|
|
|
5115
5209
|
const {
|
|
5210
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$f,
|
|
5116
5211
|
NPM
|
|
5117
5212
|
} = constants;
|
|
5118
5213
|
const config$f = {
|
|
@@ -5147,7 +5242,8 @@ async function run$f(argv, importMeta, {
|
|
|
5147
5242
|
parentName
|
|
5148
5243
|
});
|
|
5149
5244
|
if (cli.flags['dryRun']) {
|
|
5150
|
-
|
|
5245
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$f);
|
|
5246
|
+
return;
|
|
5151
5247
|
}
|
|
5152
5248
|
await runRawNpm(argv);
|
|
5153
5249
|
}
|
|
@@ -5175,6 +5271,7 @@ async function runRawNpx(argv) {
|
|
|
5175
5271
|
}
|
|
5176
5272
|
|
|
5177
5273
|
const {
|
|
5274
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$e,
|
|
5178
5275
|
NPX
|
|
5179
5276
|
} = constants;
|
|
5180
5277
|
const config$e = {
|
|
@@ -5209,18 +5306,26 @@ async function run$e(argv, importMeta, {
|
|
|
5209
5306
|
parentName
|
|
5210
5307
|
});
|
|
5211
5308
|
if (cli.flags['dryRun']) {
|
|
5212
|
-
|
|
5309
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$e);
|
|
5310
|
+
return;
|
|
5213
5311
|
}
|
|
5214
5312
|
await runRawNpx(argv);
|
|
5215
5313
|
}
|
|
5216
5314
|
|
|
5315
|
+
const {
|
|
5316
|
+
DRY_RUN_LABEL
|
|
5317
|
+
} = constants;
|
|
5217
5318
|
async function createReport(socketConfig, inputPaths, {
|
|
5218
5319
|
cwd,
|
|
5219
5320
|
dryRun
|
|
5220
5321
|
}) {
|
|
5322
|
+
// Lazily access constants.spinner.
|
|
5323
|
+
const {
|
|
5324
|
+
spinner
|
|
5325
|
+
} = constants;
|
|
5221
5326
|
const socketSdk = await index.setupSdk();
|
|
5222
5327
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
5223
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
5328
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
5224
5329
|
return res.data;
|
|
5225
5330
|
}).catch(cause => {
|
|
5226
5331
|
throw new Error('Failed getting supported files for report', {
|
|
@@ -5228,24 +5333,27 @@ async function createReport(socketConfig, inputPaths, {
|
|
|
5228
5333
|
});
|
|
5229
5334
|
});
|
|
5230
5335
|
const packagePaths = await npmPaths.getPackageFiles(cwd, inputPaths, socketConfig, supportedFiles);
|
|
5231
|
-
|
|
5336
|
+
const {
|
|
5337
|
+
length: packagePathsCount
|
|
5338
|
+
} = packagePaths;
|
|
5339
|
+
if (packagePathsCount && debug.isDebug()) {
|
|
5340
|
+
for (const pkgPath of packagePaths) {
|
|
5341
|
+
debug.debugLog(`Uploading: ${pkgPath}`);
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5232
5344
|
if (dryRun) {
|
|
5233
|
-
|
|
5345
|
+
debug.debugLog(`${DRY_RUN_LABEL}: Skipped actual upload`);
|
|
5346
|
+
return undefined;
|
|
5347
|
+
}
|
|
5348
|
+
spinner.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5349
|
+
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5350
|
+
const result = await handleApiCall(apiCall, 'creating report');
|
|
5351
|
+
if (!result.success) {
|
|
5352
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
5234
5353
|
return undefined;
|
|
5235
|
-
} else {
|
|
5236
|
-
const socketSdk = await index.setupSdk();
|
|
5237
|
-
const spinner$1 = new spinner.Spinner({
|
|
5238
|
-
text: `Creating report with ${packagePaths.length} package files`
|
|
5239
|
-
}).start();
|
|
5240
|
-
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5241
|
-
const result = await handleApiCall(apiCall, 'creating report');
|
|
5242
|
-
if (!result.success) {
|
|
5243
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner$1);
|
|
5244
|
-
return undefined;
|
|
5245
|
-
}
|
|
5246
|
-
spinner$1.successAndStop();
|
|
5247
|
-
return result;
|
|
5248
5354
|
}
|
|
5355
|
+
spinner.successAndStop();
|
|
5356
|
+
return result;
|
|
5249
5357
|
}
|
|
5250
5358
|
|
|
5251
5359
|
async function getSocketConfig(absoluteConfigPath) {
|
|
@@ -5272,10 +5380,12 @@ async function getSocketConfig(absoluteConfigPath) {
|
|
|
5272
5380
|
const MAX_TIMEOUT_RETRY = 5;
|
|
5273
5381
|
const HTTP_CODE_TIMEOUT = 524;
|
|
5274
5382
|
async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
5383
|
+
// Lazily access constants.spinner.
|
|
5384
|
+
const {
|
|
5385
|
+
spinner
|
|
5386
|
+
} = constants;
|
|
5387
|
+
spinner.start(`Fetching report with ID ${reportId} (this could take a while)`);
|
|
5275
5388
|
const socketSdk = await index.setupSdk();
|
|
5276
|
-
const spinner$1 = new spinner.Spinner({
|
|
5277
|
-
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
5278
|
-
}).start();
|
|
5279
5389
|
let result;
|
|
5280
5390
|
for (let retry = 1; !result; ++retry) {
|
|
5281
5391
|
try {
|
|
@@ -5283,42 +5393,43 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5283
5393
|
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
5284
5394
|
} catch (err) {
|
|
5285
5395
|
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof Error) || err.cause?.cause?.response?.statusCode !== HTTP_CODE_TIMEOUT) {
|
|
5396
|
+
spinner.stop();
|
|
5286
5397
|
throw err;
|
|
5287
5398
|
}
|
|
5288
5399
|
}
|
|
5289
5400
|
}
|
|
5290
5401
|
if (!result.success) {
|
|
5291
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner
|
|
5402
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
5292
5403
|
}
|
|
5293
5404
|
|
|
5294
|
-
// Conclude the status of the API call
|
|
5295
|
-
|
|
5405
|
+
// Conclude the status of the API call.
|
|
5296
5406
|
if (strict) {
|
|
5297
5407
|
if (result.data.healthy) {
|
|
5298
|
-
spinner
|
|
5408
|
+
spinner.success('Report result is healthy and great!');
|
|
5299
5409
|
} else {
|
|
5300
|
-
spinner
|
|
5410
|
+
spinner.error('Report result deemed unhealthy for project');
|
|
5301
5411
|
}
|
|
5302
5412
|
} else if (!result.data.healthy) {
|
|
5303
5413
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
5304
5414
|
const issueSummary = formatSeverityCount(severityCount);
|
|
5305
|
-
spinner
|
|
5415
|
+
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
5306
5416
|
} else {
|
|
5307
|
-
spinner
|
|
5417
|
+
spinner.success('Report has no issues');
|
|
5308
5418
|
}
|
|
5419
|
+
spinner.stop();
|
|
5309
5420
|
return result.data;
|
|
5310
5421
|
}
|
|
5311
5422
|
|
|
5312
5423
|
function formatReportDataOutput(reportId, data, commandName, outputJson, outputMarkdown, strict) {
|
|
5313
5424
|
if (outputJson) {
|
|
5314
|
-
|
|
5425
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
5315
5426
|
} else {
|
|
5316
5427
|
const format = new index.ColorOrMarkdown(outputMarkdown);
|
|
5317
|
-
|
|
5428
|
+
logger.logger.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
5318
5429
|
fallbackToUrl: true
|
|
5319
5430
|
}));
|
|
5320
5431
|
if (!outputMarkdown) {
|
|
5321
|
-
|
|
5432
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(commandName)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
5322
5433
|
}
|
|
5323
5434
|
}
|
|
5324
5435
|
if (strict && !data.healthy) {
|
|
@@ -5339,6 +5450,9 @@ async function viewReport(reportId, {
|
|
|
5339
5450
|
}
|
|
5340
5451
|
}
|
|
5341
5452
|
|
|
5453
|
+
const {
|
|
5454
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$d
|
|
5455
|
+
} = constants;
|
|
5342
5456
|
const config$d = {
|
|
5343
5457
|
commandName: 'create',
|
|
5344
5458
|
description: 'Create a project report',
|
|
@@ -5409,7 +5523,8 @@ async function run$d(argv, importMeta, {
|
|
|
5409
5523
|
|
|
5410
5524
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
5411
5525
|
if (cli.flags['dryRun']) {
|
|
5412
|
-
|
|
5526
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$d);
|
|
5527
|
+
return;
|
|
5413
5528
|
}
|
|
5414
5529
|
const socketConfig = await getSocketConfig(absoluteConfigPath);
|
|
5415
5530
|
const result = await createReport(socketConfig, cli.input, {
|
|
@@ -5428,17 +5543,19 @@ async function run$d(argv, importMeta, {
|
|
|
5428
5543
|
strict
|
|
5429
5544
|
});
|
|
5430
5545
|
} else if (json) {
|
|
5431
|
-
|
|
5432
|
-
return;
|
|
5546
|
+
logger.logger.log(JSON.stringify(result.data, undefined, 2));
|
|
5433
5547
|
} else {
|
|
5434
5548
|
const format = new index.ColorOrMarkdown(markdown);
|
|
5435
|
-
|
|
5549
|
+
logger.logger.log(`New report: ${format.hyperlink(result.data.id, result.data.url, {
|
|
5436
5550
|
fallbackToUrl: true
|
|
5437
5551
|
})}`);
|
|
5438
5552
|
}
|
|
5439
5553
|
}
|
|
5440
5554
|
}
|
|
5441
5555
|
|
|
5556
|
+
const {
|
|
5557
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$c
|
|
5558
|
+
} = constants;
|
|
5442
5559
|
const config$c = {
|
|
5443
5560
|
commandName: 'view',
|
|
5444
5561
|
description: 'View a project report',
|
|
@@ -5481,13 +5598,14 @@ async function run$c(argv, importMeta, {
|
|
|
5481
5598
|
// options or missing arguments.
|
|
5482
5599
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5483
5600
|
process.exitCode = 2;
|
|
5484
|
-
|
|
5601
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5485
5602
|
- Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5486
5603
|
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`);
|
|
5487
5604
|
return;
|
|
5488
5605
|
}
|
|
5489
5606
|
if (cli.flags['dryRun']) {
|
|
5490
|
-
|
|
5607
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5608
|
+
return;
|
|
5491
5609
|
}
|
|
5492
5610
|
await viewReport(reportId, {
|
|
5493
5611
|
all: Boolean(cli.flags['all']),
|
|
@@ -5527,10 +5645,11 @@ async function createRepo({
|
|
|
5527
5645
|
repoName,
|
|
5528
5646
|
visibility
|
|
5529
5647
|
}) {
|
|
5530
|
-
|
|
5531
|
-
const
|
|
5532
|
-
|
|
5533
|
-
}
|
|
5648
|
+
// Lazily access constants.spinner.
|
|
5649
|
+
const {
|
|
5650
|
+
spinner
|
|
5651
|
+
} = constants;
|
|
5652
|
+
spinner.start('Creating repository...');
|
|
5534
5653
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5535
5654
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5536
5655
|
outputJson,
|
|
@@ -5543,12 +5662,15 @@ async function createRepo({
|
|
|
5543
5662
|
visibility
|
|
5544
5663
|
}), 'creating repository');
|
|
5545
5664
|
if (result.success) {
|
|
5546
|
-
spinner
|
|
5665
|
+
spinner.successAndStop('Repository created successfully');
|
|
5547
5666
|
} else {
|
|
5548
|
-
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner
|
|
5667
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
5549
5668
|
}
|
|
5550
5669
|
}
|
|
5551
5670
|
|
|
5671
|
+
const {
|
|
5672
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$b
|
|
5673
|
+
} = constants;
|
|
5552
5674
|
const config$b = {
|
|
5553
5675
|
commandName: 'create',
|
|
5554
5676
|
description: 'Create a repository in an organization',
|
|
@@ -5619,13 +5741,14 @@ async function run$b(argv, importMeta, {
|
|
|
5619
5741
|
// options or missing arguments.
|
|
5620
5742
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5621
5743
|
process.exitCode = 2;
|
|
5622
|
-
|
|
5744
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5623
5745
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5624
5746
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
5625
5747
|
return;
|
|
5626
5748
|
}
|
|
5627
5749
|
if (cli.flags['dryRun']) {
|
|
5628
|
-
|
|
5750
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5751
|
+
return;
|
|
5629
5752
|
}
|
|
5630
5753
|
const apiToken = index.getDefaultToken();
|
|
5631
5754
|
if (!apiToken) {
|
|
@@ -5645,19 +5768,23 @@ async function run$b(argv, importMeta, {
|
|
|
5645
5768
|
}
|
|
5646
5769
|
|
|
5647
5770
|
async function deleteRepo(orgSlug, repoName, apiToken) {
|
|
5648
|
-
|
|
5649
|
-
const
|
|
5650
|
-
|
|
5651
|
-
}
|
|
5771
|
+
// Lazily access constants.spinner.
|
|
5772
|
+
const {
|
|
5773
|
+
spinner
|
|
5774
|
+
} = constants;
|
|
5775
|
+
spinner.start('Deleting repository...');
|
|
5652
5776
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5653
5777
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
5654
5778
|
if (result.success) {
|
|
5655
|
-
spinner
|
|
5779
|
+
spinner.successAndStop('Repository deleted successfully');
|
|
5656
5780
|
} else {
|
|
5657
|
-
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner
|
|
5781
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
5658
5782
|
}
|
|
5659
5783
|
}
|
|
5660
5784
|
|
|
5785
|
+
const {
|
|
5786
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$a
|
|
5787
|
+
} = constants;
|
|
5661
5788
|
const config$a = {
|
|
5662
5789
|
commandName: 'del',
|
|
5663
5790
|
description: 'Delete a repository in an organization',
|
|
@@ -5696,14 +5823,15 @@ async function run$a(argv, importMeta, {
|
|
|
5696
5823
|
// options or missing arguments.
|
|
5697
5824
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5698
5825
|
process.exitCode = 2;
|
|
5699
|
-
|
|
5826
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5700
5827
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5701
5828
|
- Repository name as the second argument ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5702
5829
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5703
5830
|
return;
|
|
5704
5831
|
}
|
|
5705
5832
|
if (cli.flags['dryRun']) {
|
|
5706
|
-
|
|
5833
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5834
|
+
return;
|
|
5707
5835
|
}
|
|
5708
5836
|
const apiToken = index.getDefaultToken();
|
|
5709
5837
|
if (!apiToken) {
|
|
@@ -5723,10 +5851,11 @@ async function listRepos({
|
|
|
5723
5851
|
per_page,
|
|
5724
5852
|
sort
|
|
5725
5853
|
}) {
|
|
5726
|
-
|
|
5727
|
-
const
|
|
5728
|
-
|
|
5729
|
-
}
|
|
5854
|
+
// Lazily access constants.spinner.
|
|
5855
|
+
const {
|
|
5856
|
+
spinner
|
|
5857
|
+
} = constants;
|
|
5858
|
+
spinner.start('Listing repositories...');
|
|
5730
5859
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5731
5860
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5732
5861
|
outputJson,
|
|
@@ -5738,10 +5867,10 @@ async function listRepos({
|
|
|
5738
5867
|
page
|
|
5739
5868
|
}), 'listing repositories');
|
|
5740
5869
|
if (!result.success) {
|
|
5741
|
-
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner
|
|
5870
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
5742
5871
|
return;
|
|
5743
5872
|
}
|
|
5744
|
-
spinner
|
|
5873
|
+
spinner.stop();
|
|
5745
5874
|
if (outputJson) {
|
|
5746
5875
|
const data = result.data.results.map(o => ({
|
|
5747
5876
|
id: o.id,
|
|
@@ -5750,7 +5879,7 @@ async function listRepos({
|
|
|
5750
5879
|
defaultBranch: o.default_branch,
|
|
5751
5880
|
archived: o.archived
|
|
5752
5881
|
}));
|
|
5753
|
-
|
|
5882
|
+
logger.logger.log(JSON.stringify(data, null, 2));
|
|
5754
5883
|
return;
|
|
5755
5884
|
}
|
|
5756
5885
|
const options = {
|
|
@@ -5771,9 +5900,12 @@ async function listRepos({
|
|
|
5771
5900
|
name: colors.magenta('Archived')
|
|
5772
5901
|
}]
|
|
5773
5902
|
};
|
|
5774
|
-
|
|
5903
|
+
logger.logger.log(chalkTable(options, result.data.results));
|
|
5775
5904
|
}
|
|
5776
5905
|
|
|
5906
|
+
const {
|
|
5907
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$9
|
|
5908
|
+
} = constants;
|
|
5777
5909
|
const config$9 = {
|
|
5778
5910
|
commandName: 'list',
|
|
5779
5911
|
description: 'List repositories in an organization',
|
|
@@ -5836,13 +5968,14 @@ async function run$9(argv, importMeta, {
|
|
|
5836
5968
|
// options or missing arguments.
|
|
5837
5969
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5838
5970
|
process.exitCode = 2;
|
|
5839
|
-
|
|
5971
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5840
5972
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5841
5973
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5842
5974
|
return;
|
|
5843
5975
|
}
|
|
5844
5976
|
if (cli.flags['dryRun']) {
|
|
5845
|
-
|
|
5977
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
5978
|
+
return;
|
|
5846
5979
|
}
|
|
5847
5980
|
const apiToken = index.getDefaultToken();
|
|
5848
5981
|
if (!apiToken) {
|
|
@@ -5871,10 +6004,11 @@ async function updateRepo({
|
|
|
5871
6004
|
repoName,
|
|
5872
6005
|
visibility
|
|
5873
6006
|
}) {
|
|
5874
|
-
|
|
5875
|
-
const
|
|
5876
|
-
|
|
5877
|
-
}
|
|
6007
|
+
// Lazily access constants.spinner.
|
|
6008
|
+
const {
|
|
6009
|
+
spinner
|
|
6010
|
+
} = constants;
|
|
6011
|
+
spinner.start('Updating repository...');
|
|
5878
6012
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5879
6013
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5880
6014
|
outputJson,
|
|
@@ -5887,12 +6021,15 @@ async function updateRepo({
|
|
|
5887
6021
|
visibility
|
|
5888
6022
|
}), 'updating repository');
|
|
5889
6023
|
if (result.success) {
|
|
5890
|
-
spinner
|
|
6024
|
+
spinner.successAndStop('Repository updated successfully');
|
|
5891
6025
|
} else {
|
|
5892
|
-
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner
|
|
6026
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
5893
6027
|
}
|
|
5894
6028
|
}
|
|
5895
6029
|
|
|
6030
|
+
const {
|
|
6031
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$8
|
|
6032
|
+
} = constants;
|
|
5896
6033
|
const config$8 = {
|
|
5897
6034
|
commandName: 'update',
|
|
5898
6035
|
description: 'Update a repository in an organization',
|
|
@@ -5963,14 +6100,15 @@ async function run$8(argv, importMeta, {
|
|
|
5963
6100
|
// options or missing arguments.
|
|
5964
6101
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5965
6102
|
process.exitCode = 2;
|
|
5966
|
-
|
|
6103
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5967
6104
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5968
6105
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5969
6106
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5970
6107
|
return;
|
|
5971
6108
|
}
|
|
5972
6109
|
if (cli.flags['dryRun']) {
|
|
5973
|
-
|
|
6110
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6111
|
+
return;
|
|
5974
6112
|
}
|
|
5975
6113
|
const apiToken = index.getDefaultToken();
|
|
5976
6114
|
if (!apiToken) {
|
|
@@ -5991,14 +6129,15 @@ async function run$8(argv, importMeta, {
|
|
|
5991
6129
|
|
|
5992
6130
|
// @ts-ignore
|
|
5993
6131
|
async function viewRepo(orgSlug, repoName, apiToken) {
|
|
5994
|
-
|
|
5995
|
-
const
|
|
5996
|
-
|
|
5997
|
-
}
|
|
6132
|
+
// Lazily access constants.spinner.
|
|
6133
|
+
const {
|
|
6134
|
+
spinner
|
|
6135
|
+
} = constants;
|
|
6136
|
+
spinner.start('Fetching repository...');
|
|
5998
6137
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5999
6138
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
6000
6139
|
if (!result.success) {
|
|
6001
|
-
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner
|
|
6140
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
6002
6141
|
return;
|
|
6003
6142
|
}
|
|
6004
6143
|
const options = {
|
|
@@ -6025,9 +6164,12 @@ async function viewRepo(orgSlug, repoName, apiToken) {
|
|
|
6025
6164
|
name: colors.magenta('Created at')
|
|
6026
6165
|
}]
|
|
6027
6166
|
};
|
|
6028
|
-
spinner
|
|
6167
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
6029
6168
|
}
|
|
6030
6169
|
|
|
6170
|
+
const {
|
|
6171
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$7
|
|
6172
|
+
} = constants;
|
|
6031
6173
|
const config$7 = {
|
|
6032
6174
|
commandName: 'view',
|
|
6033
6175
|
description: 'View repositories in an organization',
|
|
@@ -6068,13 +6210,14 @@ async function run$7(argv, importMeta, {
|
|
|
6068
6210
|
// options or missing arguments.
|
|
6069
6211
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6070
6212
|
process.exitCode = 2;
|
|
6071
|
-
|
|
6213
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6072
6214
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6073
6215
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
6074
6216
|
return;
|
|
6075
6217
|
}
|
|
6076
6218
|
if (cli.flags['dryRun']) {
|
|
6077
|
-
|
|
6219
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$7);
|
|
6220
|
+
return;
|
|
6078
6221
|
}
|
|
6079
6222
|
const apiToken = index.getDefaultToken();
|
|
6080
6223
|
if (!apiToken) {
|
|
@@ -6203,7 +6346,7 @@ function dirNameToSlug(name) {
|
|
|
6203
6346
|
async function suggestBranchSlug(repoDefaultBranch) {
|
|
6204
6347
|
const spawnResult = node_child_process.spawnSync('git', ['branch', '--show-current']);
|
|
6205
6348
|
const currentBranch = spawnResult.stdout.toString('utf8').trim();
|
|
6206
|
-
if (spawnResult.status === 0
|
|
6349
|
+
if (currentBranch && spawnResult.status === 0) {
|
|
6207
6350
|
const proceed = await prompts.select({
|
|
6208
6351
|
message: 'Use the current git branch as target branch name?',
|
|
6209
6352
|
choices: [{
|
|
@@ -6261,10 +6404,14 @@ async function createFullScan({
|
|
|
6261
6404
|
targets,
|
|
6262
6405
|
tmp
|
|
6263
6406
|
}) {
|
|
6407
|
+
// Lazily access constants.spinner.
|
|
6408
|
+
const {
|
|
6409
|
+
spinner
|
|
6410
|
+
} = constants;
|
|
6264
6411
|
const socketSdk = await index.setupSdk();
|
|
6265
6412
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6266
6413
|
if (!res.success) {
|
|
6267
|
-
handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
6414
|
+
handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
6268
6415
|
assert(false, 'handleUnsuccessfulApiResponse should unconditionally throw');
|
|
6269
6416
|
}
|
|
6270
6417
|
return res.data;
|
|
@@ -6321,7 +6468,7 @@ async function createFullScan({
|
|
|
6321
6468
|
// options or missing arguments.
|
|
6322
6469
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6323
6470
|
process$1.exitCode = 2;
|
|
6324
|
-
|
|
6471
|
+
logger.logger.error(`
|
|
6325
6472
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6326
6473
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6327
6474
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6332,22 +6479,19 @@ async function createFullScan({
|
|
|
6332
6479
|
return;
|
|
6333
6480
|
}
|
|
6334
6481
|
if (updatedInput) {
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6482
|
+
logger.logger.log('Note: You can invoke this command next time to skip the interactive questions:');
|
|
6483
|
+
logger.logger.log('```');
|
|
6484
|
+
logger.logger.log(` socket scan create [other flags...] --repo ${repoName} --branch ${branchName} ${orgSlug} ${targets.join(' ')}`);
|
|
6485
|
+
logger.logger.log('```');
|
|
6339
6486
|
}
|
|
6340
6487
|
if (!apiToken) {
|
|
6341
6488
|
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.');
|
|
6342
6489
|
}
|
|
6343
6490
|
if (readOnly) {
|
|
6344
|
-
|
|
6491
|
+
logger.logger.log('[ReadOnly] Bailing now');
|
|
6345
6492
|
return;
|
|
6346
6493
|
}
|
|
6347
|
-
|
|
6348
|
-
const spinner$1 = new spinner.Spinner({
|
|
6349
|
-
text: spinnerText
|
|
6350
|
-
}).start();
|
|
6494
|
+
spinner.start('Creating a scan...');
|
|
6351
6495
|
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
6352
6496
|
repo: repoName,
|
|
6353
6497
|
branch: branchName,
|
|
@@ -6357,12 +6501,12 @@ async function createFullScan({
|
|
|
6357
6501
|
tmp
|
|
6358
6502
|
}, packagePaths, cwd), 'Creating scan');
|
|
6359
6503
|
if (!result.success) {
|
|
6360
|
-
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner
|
|
6504
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
6361
6505
|
return;
|
|
6362
6506
|
}
|
|
6363
|
-
spinner
|
|
6507
|
+
spinner.successAndStop('Scan created successfully');
|
|
6364
6508
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
6365
|
-
|
|
6509
|
+
logger.logger.log(`Available at: ${link}`);
|
|
6366
6510
|
const rl = readline.createInterface({
|
|
6367
6511
|
input: process$1.stdin,
|
|
6368
6512
|
output: process$1.stdout
|
|
@@ -6374,6 +6518,9 @@ async function createFullScan({
|
|
|
6374
6518
|
rl.close();
|
|
6375
6519
|
}
|
|
6376
6520
|
|
|
6521
|
+
const {
|
|
6522
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$6
|
|
6523
|
+
} = constants;
|
|
6377
6524
|
const config$6 = {
|
|
6378
6525
|
commandName: 'create',
|
|
6379
6526
|
description: 'Create a scan',
|
|
@@ -6490,7 +6637,7 @@ async function run$6(argv, importMeta, {
|
|
|
6490
6637
|
// options or missing arguments.
|
|
6491
6638
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6492
6639
|
process$1.exitCode = 2;
|
|
6493
|
-
|
|
6640
|
+
logger.logger.error(`
|
|
6494
6641
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6495
6642
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6496
6643
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6503,7 +6650,8 @@ async function run$6(argv, importMeta, {
|
|
|
6503
6650
|
|
|
6504
6651
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
6505
6652
|
if (cli.flags['dryRun']) {
|
|
6506
|
-
|
|
6653
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$6);
|
|
6654
|
+
return;
|
|
6507
6655
|
}
|
|
6508
6656
|
await createFullScan({
|
|
6509
6657
|
branchName: branchName,
|
|
@@ -6523,19 +6671,23 @@ async function run$6(argv, importMeta, {
|
|
|
6523
6671
|
}
|
|
6524
6672
|
|
|
6525
6673
|
async function deleteOrgFullScan(orgSlug, fullScanId, apiToken) {
|
|
6526
|
-
|
|
6527
|
-
const
|
|
6528
|
-
|
|
6529
|
-
}
|
|
6674
|
+
// Lazily access constants.spinner.
|
|
6675
|
+
const {
|
|
6676
|
+
spinner
|
|
6677
|
+
} = constants;
|
|
6678
|
+
spinner.start('Deleting scan...');
|
|
6530
6679
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6531
6680
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
6532
|
-
if (result.success) {
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner$1);
|
|
6681
|
+
if (!result.success) {
|
|
6682
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
6683
|
+
return;
|
|
6536
6684
|
}
|
|
6685
|
+
spinner.successAndStop('Scan deleted successfully');
|
|
6537
6686
|
}
|
|
6538
6687
|
|
|
6688
|
+
const {
|
|
6689
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$5
|
|
6690
|
+
} = constants;
|
|
6539
6691
|
const config$5 = {
|
|
6540
6692
|
commandName: 'del',
|
|
6541
6693
|
description: 'Delete a scan',
|
|
@@ -6575,13 +6727,14 @@ async function run$5(argv, importMeta, {
|
|
|
6575
6727
|
// options or missing arguments.
|
|
6576
6728
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6577
6729
|
process.exitCode = 2;
|
|
6578
|
-
|
|
6730
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6579
6731
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6580
6732
|
- Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6581
6733
|
return;
|
|
6582
6734
|
}
|
|
6583
6735
|
if (cli.flags['dryRun']) {
|
|
6584
|
-
|
|
6736
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$5);
|
|
6737
|
+
return;
|
|
6585
6738
|
}
|
|
6586
6739
|
const apiToken = index.getDefaultToken();
|
|
6587
6740
|
if (!apiToken) {
|
|
@@ -6592,14 +6745,15 @@ async function run$5(argv, importMeta, {
|
|
|
6592
6745
|
|
|
6593
6746
|
// @ts-ignore
|
|
6594
6747
|
async function listFullScans(orgSlug, input, apiToken) {
|
|
6595
|
-
|
|
6596
|
-
const
|
|
6597
|
-
|
|
6598
|
-
}
|
|
6748
|
+
// Lazily access constants.spinner.
|
|
6749
|
+
const {
|
|
6750
|
+
spinner
|
|
6751
|
+
} = constants;
|
|
6752
|
+
spinner.start('Listing scans...');
|
|
6599
6753
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6600
6754
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
6601
6755
|
if (!result.success) {
|
|
6602
|
-
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner
|
|
6756
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
6603
6757
|
return;
|
|
6604
6758
|
}
|
|
6605
6759
|
const options = {
|
|
@@ -6629,10 +6783,13 @@ async function listFullScans(orgSlug, input, apiToken) {
|
|
|
6629
6783
|
branch: d.branch
|
|
6630
6784
|
};
|
|
6631
6785
|
});
|
|
6632
|
-
spinner
|
|
6633
|
-
|
|
6786
|
+
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
6787
|
+
logger.logger.log(chalkTable(options, formattedResults));
|
|
6634
6788
|
}
|
|
6635
6789
|
|
|
6790
|
+
const {
|
|
6791
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$4
|
|
6792
|
+
} = constants;
|
|
6636
6793
|
const config$4 = {
|
|
6637
6794
|
commandName: 'list',
|
|
6638
6795
|
description: 'List the full scans for an organization',
|
|
@@ -6708,12 +6865,13 @@ async function run$4(argv, importMeta, {
|
|
|
6708
6865
|
// options or missing arguments.
|
|
6709
6866
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6710
6867
|
process.exitCode = 2;
|
|
6711
|
-
|
|
6868
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6712
6869
|
- Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6713
6870
|
return;
|
|
6714
6871
|
}
|
|
6715
6872
|
if (cli.flags['dryRun']) {
|
|
6716
|
-
|
|
6873
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$4);
|
|
6874
|
+
return;
|
|
6717
6875
|
}
|
|
6718
6876
|
const apiToken = index.getDefaultToken();
|
|
6719
6877
|
if (!apiToken) {
|
|
@@ -6735,20 +6893,24 @@ async function run$4(argv, importMeta, {
|
|
|
6735
6893
|
}
|
|
6736
6894
|
|
|
6737
6895
|
async function getOrgScanMetadata(orgSlug, scanId, apiToken) {
|
|
6738
|
-
|
|
6739
|
-
const
|
|
6740
|
-
|
|
6741
|
-
}
|
|
6896
|
+
// Lazily access constants.spinner.
|
|
6897
|
+
const {
|
|
6898
|
+
spinner
|
|
6899
|
+
} = constants;
|
|
6900
|
+
spinner.start("Getting scan's metadata...");
|
|
6742
6901
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6743
6902
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
6744
6903
|
if (!result.success) {
|
|
6745
|
-
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner
|
|
6904
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
6746
6905
|
return;
|
|
6747
6906
|
}
|
|
6748
|
-
spinner
|
|
6749
|
-
|
|
6907
|
+
spinner.stop('Scan metadata:');
|
|
6908
|
+
logger.logger.log(result.data);
|
|
6750
6909
|
}
|
|
6751
6910
|
|
|
6911
|
+
const {
|
|
6912
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$3
|
|
6913
|
+
} = constants;
|
|
6752
6914
|
const config$3 = {
|
|
6753
6915
|
commandName: 'metadata',
|
|
6754
6916
|
description: "Get a full scan's metadata",
|
|
@@ -6788,13 +6950,14 @@ async function run$3(argv, importMeta, {
|
|
|
6788
6950
|
// options or missing arguments.
|
|
6789
6951
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6790
6952
|
process.exitCode = 2;
|
|
6791
|
-
|
|
6953
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6792
6954
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6793
6955
|
- Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6794
6956
|
return;
|
|
6795
6957
|
}
|
|
6796
6958
|
if (cli.flags['dryRun']) {
|
|
6797
|
-
|
|
6959
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$3);
|
|
6960
|
+
return;
|
|
6798
6961
|
}
|
|
6799
6962
|
const apiToken = index.getDefaultToken();
|
|
6800
6963
|
if (!apiToken) {
|
|
@@ -6804,19 +6967,24 @@ async function run$3(argv, importMeta, {
|
|
|
6804
6967
|
}
|
|
6805
6968
|
|
|
6806
6969
|
async function getFullScan(orgSlug, fullScanId, file, apiToken) {
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6970
|
+
// Lazily access constants.spinner.
|
|
6971
|
+
const {
|
|
6972
|
+
spinner
|
|
6973
|
+
} = constants;
|
|
6974
|
+
spinner.start('Streaming scan...');
|
|
6810
6975
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6811
6976
|
const data = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file === '-' ? undefined : file), 'Streaming a scan');
|
|
6812
6977
|
if (data?.success) {
|
|
6813
|
-
spinner
|
|
6978
|
+
spinner.stop(file ? `Full scan details written to ${file}` : '');
|
|
6814
6979
|
} else {
|
|
6815
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner
|
|
6980
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner);
|
|
6816
6981
|
}
|
|
6817
6982
|
return data;
|
|
6818
6983
|
}
|
|
6819
6984
|
|
|
6985
|
+
const {
|
|
6986
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$2
|
|
6987
|
+
} = constants;
|
|
6820
6988
|
const config$2 = {
|
|
6821
6989
|
commandName: 'stream',
|
|
6822
6990
|
description: 'Stream the output of a scan',
|
|
@@ -6858,13 +7026,14 @@ async function run$2(argv, importMeta, {
|
|
|
6858
7026
|
// options or missing arguments.
|
|
6859
7027
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6860
7028
|
process.exitCode = 2;
|
|
6861
|
-
|
|
7029
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6862
7030
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6863
7031
|
- Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6864
7032
|
return;
|
|
6865
7033
|
}
|
|
6866
7034
|
if (cli.flags['dryRun']) {
|
|
6867
|
-
|
|
7035
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$2);
|
|
7036
|
+
return;
|
|
6868
7037
|
}
|
|
6869
7038
|
const apiToken = index.getDefaultToken();
|
|
6870
7039
|
if (!apiToken) {
|
|
@@ -6902,9 +7071,11 @@ async function getThreatFeed({
|
|
|
6902
7071
|
page,
|
|
6903
7072
|
perPage
|
|
6904
7073
|
}) {
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
7074
|
+
// Lazily access constants.spinner.
|
|
7075
|
+
const {
|
|
7076
|
+
spinner
|
|
7077
|
+
} = constants;
|
|
7078
|
+
spinner.start('Looking up the threat feed');
|
|
6908
7079
|
const formattedQueryParams = formatQueryParams({
|
|
6909
7080
|
per_page: perPage,
|
|
6910
7081
|
page,
|
|
@@ -6913,9 +7084,9 @@ async function getThreatFeed({
|
|
|
6913
7084
|
}).join('&');
|
|
6914
7085
|
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiToken);
|
|
6915
7086
|
const data = await response.json();
|
|
6916
|
-
spinner
|
|
7087
|
+
spinner.stop();
|
|
6917
7088
|
if (outputJson) {
|
|
6918
|
-
|
|
7089
|
+
logger.logger.log(data);
|
|
6919
7090
|
return;
|
|
6920
7091
|
}
|
|
6921
7092
|
const screen = new ScreenWidget();
|
|
@@ -6970,6 +7141,9 @@ function getMinDiff(start, end) {
|
|
|
6970
7141
|
return Math.floor((end - start) / 60000);
|
|
6971
7142
|
}
|
|
6972
7143
|
|
|
7144
|
+
const {
|
|
7145
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$1
|
|
7146
|
+
} = constants;
|
|
6973
7147
|
const config$1 = {
|
|
6974
7148
|
commandName: 'threat-feed',
|
|
6975
7149
|
description: 'Look up the threat feed',
|
|
@@ -7029,7 +7203,8 @@ async function run$1(argv, importMeta, {
|
|
|
7029
7203
|
parentName
|
|
7030
7204
|
});
|
|
7031
7205
|
if (cli.flags['dryRun']) {
|
|
7032
|
-
|
|
7206
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$1);
|
|
7207
|
+
return;
|
|
7033
7208
|
}
|
|
7034
7209
|
const apiToken = index.getDefaultToken();
|
|
7035
7210
|
if (!apiToken) {
|
|
@@ -7052,7 +7227,7 @@ function addSocketWrapper(file) {
|
|
|
7052
7227
|
}
|
|
7053
7228
|
// TODO: pretty sure you need to source the file or restart
|
|
7054
7229
|
// any terminal session before changes are reflected.
|
|
7055
|
-
|
|
7230
|
+
logger.logger.log(`
|
|
7056
7231
|
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
7057
7232
|
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
7058
7233
|
`);
|
|
@@ -7063,7 +7238,7 @@ function checkSocketWrapperSetup(file) {
|
|
|
7063
7238
|
const fileContent = fs.readFileSync(file, 'utf8');
|
|
7064
7239
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
7065
7240
|
if (linesWithSocketAlias.length) {
|
|
7066
|
-
|
|
7241
|
+
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
7067
7242
|
return true;
|
|
7068
7243
|
}
|
|
7069
7244
|
return false;
|
|
@@ -7085,7 +7260,7 @@ function postinstallWrapper() {
|
|
|
7085
7260
|
}
|
|
7086
7261
|
}
|
|
7087
7262
|
function installSafeNpm(query) {
|
|
7088
|
-
|
|
7263
|
+
logger.logger.log(`
|
|
7089
7264
|
_____ _ _
|
|
7090
7265
|
| __|___ ___| |_ ___| |_
|
|
7091
7266
|
|__ | . | _| '_| -_| _|
|
|
@@ -7128,24 +7303,27 @@ function askQuestion(rl, query) {
|
|
|
7128
7303
|
function removeSocketWrapper(file) {
|
|
7129
7304
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
7130
7305
|
if (err) {
|
|
7131
|
-
|
|
7306
|
+
logger.logger.error('There was an error removing the alias:');
|
|
7307
|
+
logger.logger.error(err);
|
|
7132
7308
|
return;
|
|
7133
7309
|
}
|
|
7134
7310
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
7135
7311
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
7136
7312
|
fs.writeFile(file, updatedFileContent, function (err) {
|
|
7137
7313
|
if (err) {
|
|
7138
|
-
|
|
7314
|
+
logger.logger.error(err);
|
|
7139
7315
|
return;
|
|
7140
|
-
} else {
|
|
7141
|
-
// TODO: pretty sure you need to source the file or restart
|
|
7142
|
-
// any terminal session before changes are reflected.
|
|
7143
|
-
console.log(`\nThe alias was removed from ${file}. Running 'npm install' will now run the standard npm command.\n`);
|
|
7144
7316
|
}
|
|
7317
|
+
// TODO: pretty sure you need to source the file or restart
|
|
7318
|
+
// any terminal session before changes are reflected.
|
|
7319
|
+
logger.logger.log(`The alias was removed from ${file}. Running 'npm install' will now run the standard npm command.`);
|
|
7145
7320
|
});
|
|
7146
7321
|
});
|
|
7147
7322
|
}
|
|
7148
7323
|
|
|
7324
|
+
const {
|
|
7325
|
+
DRY_RUN_BAIL_TEXT
|
|
7326
|
+
} = constants;
|
|
7149
7327
|
const config = {
|
|
7150
7328
|
commandName: 'wrapper',
|
|
7151
7329
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
@@ -7202,12 +7380,13 @@ async function run(argv, importMeta, {
|
|
|
7202
7380
|
// options or missing arguments.
|
|
7203
7381
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
7204
7382
|
process.exitCode = 2;
|
|
7205
|
-
|
|
7383
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required flags:\n
|
|
7206
7384
|
- Must use --enabled or --disabled\n`);
|
|
7207
7385
|
return;
|
|
7208
7386
|
}
|
|
7209
7387
|
if (cli.flags['dryRun']) {
|
|
7210
|
-
|
|
7388
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT);
|
|
7389
|
+
return;
|
|
7211
7390
|
}
|
|
7212
7391
|
|
|
7213
7392
|
// Lazily access constants.bashRcPath and constants.zshRcPath.
|
|
@@ -7231,7 +7410,7 @@ async function run(argv, importMeta, {
|
|
|
7231
7410
|
}
|
|
7232
7411
|
}
|
|
7233
7412
|
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
7234
|
-
|
|
7413
|
+
logger.logger.error('There was an issue setting up the alias in your bash profile');
|
|
7235
7414
|
}
|
|
7236
7415
|
}
|
|
7237
7416
|
|
|
@@ -7304,12 +7483,12 @@ void (async () => {
|
|
|
7304
7483
|
} else {
|
|
7305
7484
|
errorTitle = 'Unexpected error with no details';
|
|
7306
7485
|
}
|
|
7307
|
-
|
|
7486
|
+
logger.logger.error(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
7308
7487
|
if (errorBody) {
|
|
7309
|
-
|
|
7488
|
+
logger.logger.error(`\n${errorBody}`);
|
|
7310
7489
|
}
|
|
7311
7490
|
await index.captureException(e);
|
|
7312
7491
|
}
|
|
7313
7492
|
})();
|
|
7314
|
-
//# debugId=
|
|
7493
|
+
//# debugId=9ba118ee-ceb1-4f74-9334-3ae81bcb81f3
|
|
7315
7494
|
//# sourceMappingURL=cli.js.map
|