@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/require/cli.js
CHANGED
|
@@ -15,6 +15,7 @@ var require$$0 = require('node:url');
|
|
|
15
15
|
var ponyCause = _socketInterop(require('pony-cause'));
|
|
16
16
|
var vendor = require('./vendor.js');
|
|
17
17
|
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
18
|
+
var logger = require('@socketsecurity/registry/lib/logger');
|
|
18
19
|
var micromatch = _socketInterop(require('micromatch'));
|
|
19
20
|
var simpleGit = _socketInterop(require('simple-git'));
|
|
20
21
|
var sdk = require('@socketsecurity/sdk');
|
|
@@ -23,13 +24,12 @@ var fs = require('node:fs');
|
|
|
23
24
|
var path = require('node:path');
|
|
24
25
|
var ndjson = _socketInterop(require('ndjson'));
|
|
25
26
|
var index = require('./index.js');
|
|
27
|
+
var constants = require('./constants.js');
|
|
26
28
|
var objects = require('@socketsecurity/registry/lib/objects');
|
|
27
29
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
28
|
-
var constants = require('./constants.js');
|
|
29
30
|
var fs$1 = require('node:fs/promises');
|
|
30
31
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
31
32
|
var contrib = _socketInterop(require('blessed-contrib'));
|
|
32
|
-
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
33
33
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
34
34
|
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
35
35
|
var words = require('@socketsecurity/registry/lib/words');
|
|
@@ -52,8 +52,9 @@ var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
|
52
52
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
53
53
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
54
54
|
var yaml = _socketInterop(require('yaml'));
|
|
55
|
-
var
|
|
55
|
+
var debug = require('@socketsecurity/registry/lib/debug');
|
|
56
56
|
var npm$1 = require('./npm.js');
|
|
57
|
+
var npmPaths = require('./npm-paths.js');
|
|
57
58
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
58
59
|
var config$A = require('@socketsecurity/config');
|
|
59
60
|
var assert = require('node:assert');
|
|
@@ -263,7 +264,6 @@ class Score {
|
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
|
|
266
|
-
/* eslint-disable no-await-in-loop */
|
|
267
267
|
class Core {
|
|
268
268
|
securityPolicy = {};
|
|
269
269
|
constructor({
|
|
@@ -558,6 +558,7 @@ class Core {
|
|
|
558
558
|
diff.newPackages.push(purl);
|
|
559
559
|
consolidated.add(basePurl);
|
|
560
560
|
}
|
|
561
|
+
// eslint-disable-next-line no-await-in-loop
|
|
561
562
|
newScanAlerts = await this.createIssueAlerts({
|
|
562
563
|
pkg,
|
|
563
564
|
alerts: newScanAlerts,
|
|
@@ -575,6 +576,7 @@ class Core {
|
|
|
575
576
|
if (!(packageId in newPackages) && pkg.direct) {
|
|
576
577
|
diff.removedPackages.push(purl);
|
|
577
578
|
}
|
|
579
|
+
// eslint-disable-next-line no-await-in-loop
|
|
578
580
|
headScanAlerts = await this.createIssueAlerts({
|
|
579
581
|
pkg,
|
|
580
582
|
alerts: headScanAlerts,
|
|
@@ -640,7 +642,7 @@ class Core {
|
|
|
640
642
|
license: sbomArtifact.license
|
|
641
643
|
});
|
|
642
644
|
if (pkg.id in packages) {
|
|
643
|
-
|
|
645
|
+
logger.logger.log('Duplicate package?');
|
|
644
646
|
} else {
|
|
645
647
|
pkg = this.getLicenseDetails({
|
|
646
648
|
package: pkg
|
|
@@ -680,8 +682,8 @@ class Core {
|
|
|
680
682
|
});
|
|
681
683
|
}
|
|
682
684
|
}
|
|
683
|
-
} catch (
|
|
684
|
-
|
|
685
|
+
} catch (e) {
|
|
686
|
+
logger.logger.error(e);
|
|
685
687
|
}
|
|
686
688
|
const newFullScan = await this.createFullScan({
|
|
687
689
|
params
|
|
@@ -705,7 +707,6 @@ class Core {
|
|
|
705
707
|
}
|
|
706
708
|
|
|
707
709
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
|
|
708
|
-
|
|
709
710
|
function checkForSocketComments({
|
|
710
711
|
comments
|
|
711
712
|
}) {
|
|
@@ -835,9 +836,9 @@ function getIgnoreOptions({
|
|
|
835
836
|
const data = `${name}/${version}`;
|
|
836
837
|
ignoreCommands.push(data);
|
|
837
838
|
}
|
|
838
|
-
} catch (
|
|
839
|
-
|
|
840
|
-
|
|
839
|
+
} catch (e) {
|
|
840
|
+
logger.logger.error(`Unable to process ignore command for ${comment}`);
|
|
841
|
+
logger.logger.error(e);
|
|
841
842
|
}
|
|
842
843
|
}
|
|
843
844
|
}
|
|
@@ -868,9 +869,9 @@ function removeAlerts({
|
|
|
868
869
|
const purl = `${fullName}/${alert.pkg_version}`;
|
|
869
870
|
const purlStar = `${fullName}/*`;
|
|
870
871
|
if (ignoreCommands.includes(purl) || ignoreCommands.includes(purlStar)) {
|
|
871
|
-
|
|
872
|
+
logger.logger.log(`Alerts for ${alert.pkg_name}@${alert.pkg_version} ignored`);
|
|
872
873
|
} else {
|
|
873
|
-
|
|
874
|
+
logger.logger.log(`Adding alert ${alert.type} for ${alert.pkg_name}@${alert.pkg_version}`);
|
|
874
875
|
alerts.push(alert);
|
|
875
876
|
}
|
|
876
877
|
}
|
|
@@ -908,7 +909,7 @@ class GitHub {
|
|
|
908
909
|
if (['opened', 'synchronize'].includes(eventAction)) {
|
|
909
910
|
return 'diff';
|
|
910
911
|
} else {
|
|
911
|
-
|
|
912
|
+
logger.logger.log(`Pull request action: ${eventAction} is not supported`);
|
|
912
913
|
process.exit();
|
|
913
914
|
}
|
|
914
915
|
case 'issue_comment':
|
|
@@ -1023,30 +1024,30 @@ class GitHub {
|
|
|
1023
1024
|
security: existingSecurityComment
|
|
1024
1025
|
} = comments;
|
|
1025
1026
|
if (newOverviewComment) {
|
|
1026
|
-
|
|
1027
|
+
logger.logger.log('New Dependency Overview comment');
|
|
1027
1028
|
if (existingOverviewComment !== undefined) {
|
|
1028
|
-
|
|
1029
|
+
logger.logger.log('Previous version of Dependency Overview, updating');
|
|
1029
1030
|
await this.updateComment({
|
|
1030
1031
|
body: overviewComment,
|
|
1031
1032
|
id: existingOverviewComment.id
|
|
1032
1033
|
});
|
|
1033
1034
|
} else {
|
|
1034
|
-
|
|
1035
|
+
logger.logger.log('No previous version of Dependency Overview, posting');
|
|
1035
1036
|
await this.postComment({
|
|
1036
1037
|
body: overviewComment
|
|
1037
1038
|
});
|
|
1038
1039
|
}
|
|
1039
1040
|
}
|
|
1040
1041
|
if (newSecurityComment) {
|
|
1041
|
-
|
|
1042
|
+
logger.logger.log('New Security Issue Comment');
|
|
1042
1043
|
if (existingSecurityComment !== undefined) {
|
|
1043
|
-
|
|
1044
|
+
logger.logger.log('Previous version of Security Issue comment, updating');
|
|
1044
1045
|
await this.updateComment({
|
|
1045
1046
|
body: securityComment,
|
|
1046
1047
|
id: existingSecurityComment.id
|
|
1047
1048
|
});
|
|
1048
1049
|
} else {
|
|
1049
|
-
|
|
1050
|
+
logger.logger.log('No Previous version of Security Issue comment, posting');
|
|
1050
1051
|
await this.postComment({
|
|
1051
1052
|
body: securityComment
|
|
1052
1053
|
});
|
|
@@ -1225,7 +1226,7 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1225
1226
|
const socket = new sdk.SocketSdk(index.getDefaultToken());
|
|
1226
1227
|
const git = simpleGit.simpleGit();
|
|
1227
1228
|
const changedFiles = (await git.diff(process.env['GITHUB_EVENT_NAME'] === 'pull_request' ? ['--name-only', 'HEAD^1', 'HEAD'] : ['--name-only', githubEventBefore, githubEventAfter])).split('\n');
|
|
1228
|
-
|
|
1229
|
+
logger.logger.log({
|
|
1229
1230
|
changedFiles
|
|
1230
1231
|
});
|
|
1231
1232
|
// supportedFiles have 3-level deep globs
|
|
@@ -1233,13 +1234,13 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1233
1234
|
const files = micromatch(changedFiles, patterns);
|
|
1234
1235
|
const scm = new GitHub();
|
|
1235
1236
|
if (scm.checkEventType() === 'comment') {
|
|
1236
|
-
|
|
1237
|
+
logger.logger.log('Comment initiated flow');
|
|
1237
1238
|
const comments = await scm.getCommentsForPR();
|
|
1238
1239
|
await scm.removeCommentAlerts({
|
|
1239
1240
|
comments
|
|
1240
1241
|
});
|
|
1241
1242
|
} else if (scm.checkEventType() === 'diff') {
|
|
1242
|
-
|
|
1243
|
+
logger.logger.log('Push initiated flow');
|
|
1243
1244
|
const core = new Core({
|
|
1244
1245
|
owner: scm.owner,
|
|
1245
1246
|
repo: scm.repo,
|
|
@@ -1261,17 +1262,17 @@ async function runAction(githubEventBefore, githubEventAfter) {
|
|
|
1261
1262
|
if (diff.newAlerts.length === 0) {
|
|
1262
1263
|
if (!updateOldSecurityComment) {
|
|
1263
1264
|
newSecurityComment = false;
|
|
1264
|
-
|
|
1265
|
+
logger.logger.log('No new alerts or security issue comment disabled');
|
|
1265
1266
|
} else {
|
|
1266
|
-
|
|
1267
|
+
logger.logger.log('Updated security comment with no new alerts');
|
|
1267
1268
|
}
|
|
1268
1269
|
}
|
|
1269
1270
|
if (diff.newPackages.length === 0 && diff.removedPackages.length === 0) {
|
|
1270
1271
|
if (!updateOldOverviewComment) {
|
|
1271
1272
|
newOverviewComment = false;
|
|
1272
|
-
|
|
1273
|
+
logger.logger.log('No new/removed packages or Dependency Overview comment disabled');
|
|
1273
1274
|
} else {
|
|
1274
|
-
|
|
1275
|
+
logger.logger.log('Updated overview comment with no dependencies');
|
|
1275
1276
|
}
|
|
1276
1277
|
}
|
|
1277
1278
|
await scm.addSocketComments({
|
|
@@ -1399,6 +1400,8 @@ const validationFlags = {
|
|
|
1399
1400
|
};
|
|
1400
1401
|
|
|
1401
1402
|
const {
|
|
1403
|
+
DRY_RUN_LABEL: DRY_RUN_LABEL$1,
|
|
1404
|
+
REDACTED,
|
|
1402
1405
|
SOCKET_CLI_SHOW_BANNER
|
|
1403
1406
|
} = constants;
|
|
1404
1407
|
async function meowWithSubcommands(subcommands, options) {
|
|
@@ -1436,7 +1439,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1436
1439
|
// Temp disable until we clear the --json and --markdown usage
|
|
1437
1440
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1438
1441
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1439
|
-
|
|
1442
|
+
logger.logger.log(getAsciiHeader(name));
|
|
1440
1443
|
}
|
|
1441
1444
|
const cli = vendor.meow(`
|
|
1442
1445
|
Usage
|
|
@@ -1472,7 +1475,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1472
1475
|
autoHelp: false // otherwise we can't exit(0)
|
|
1473
1476
|
});
|
|
1474
1477
|
if (!cli.flags['help'] && cli.flags['dryRun']) {
|
|
1475
|
-
|
|
1478
|
+
logger.logger.log(`${DRY_RUN_LABEL$1}: No-op, call a sub-command; ok`);
|
|
1476
1479
|
process.exitCode = 0;
|
|
1477
1480
|
} else {
|
|
1478
1481
|
cli.showHelp();
|
|
@@ -1494,7 +1497,7 @@ function meowOrExit({
|
|
|
1494
1497
|
// Temp disable until we clear the --json and --markdown usage.
|
|
1495
1498
|
// Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
|
|
1496
1499
|
if (constants.ENV[SOCKET_CLI_SHOW_BANNER]) {
|
|
1497
|
-
|
|
1500
|
+
logger.logger.log(getAsciiHeader(command));
|
|
1498
1501
|
}
|
|
1499
1502
|
|
|
1500
1503
|
// This exits if .printHelp() is called either by meow itself or by us.
|
|
@@ -1514,7 +1517,7 @@ function meowOrExit({
|
|
|
1514
1517
|
}
|
|
1515
1518
|
function getAsciiHeader(command) {
|
|
1516
1519
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
|
|
1517
|
-
"0.14.
|
|
1520
|
+
"0.14.52:709a145:a30d9dfd:pub";
|
|
1518
1521
|
const nodeVersion = process.version;
|
|
1519
1522
|
const apiToken = index.getSetting('apiToken');
|
|
1520
1523
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -1529,6 +1532,9 @@ function getAsciiHeader(command) {
|
|
|
1529
1532
|
|
|
1530
1533
|
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
|
|
1531
1534
|
|
|
1535
|
+
const {
|
|
1536
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$y
|
|
1537
|
+
} = constants;
|
|
1532
1538
|
const config$z = {
|
|
1533
1539
|
commandName: 'action',
|
|
1534
1540
|
description: 'Socket action command',
|
|
@@ -1579,7 +1585,8 @@ async function run$z(argv, importMeta, {
|
|
|
1579
1585
|
const githubEventBefore = String(cli.flags['githubEventBefore'] || '');
|
|
1580
1586
|
const githubEventAfter = String(cli.flags['githubEventAfter'] || '');
|
|
1581
1587
|
if (cli.flags['dryRun']) {
|
|
1582
|
-
|
|
1588
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
1589
|
+
return;
|
|
1583
1590
|
}
|
|
1584
1591
|
await runAction(githubEventBefore, githubEventAfter);
|
|
1585
1592
|
}
|
|
@@ -1597,24 +1604,26 @@ async function displayAnalytics({
|
|
|
1597
1604
|
scope,
|
|
1598
1605
|
time
|
|
1599
1606
|
}) {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1607
|
+
// Lazily access constants.spinner.
|
|
1608
|
+
const {
|
|
1609
|
+
spinner
|
|
1610
|
+
} = constants;
|
|
1611
|
+
spinner.start('Fetching analytics data');
|
|
1603
1612
|
let data;
|
|
1604
1613
|
if (scope === 'org') {
|
|
1605
|
-
data = await fetchOrgAnalyticsData(time, spinner
|
|
1614
|
+
data = await fetchOrgAnalyticsData(time, spinner, apiToken);
|
|
1606
1615
|
} else if (repo) {
|
|
1607
|
-
data = await fetchRepoAnalyticsData(repo, time, spinner
|
|
1616
|
+
data = await fetchRepoAnalyticsData(repo, time, spinner, apiToken);
|
|
1608
1617
|
}
|
|
1609
1618
|
if (data) {
|
|
1610
1619
|
if (outputJson && !filePath) {
|
|
1611
|
-
|
|
1620
|
+
logger.logger.log(data);
|
|
1612
1621
|
} else if (filePath) {
|
|
1613
1622
|
try {
|
|
1614
1623
|
await fs$1.writeFile(filePath, JSON.stringify(data), 'utf8');
|
|
1615
|
-
|
|
1624
|
+
logger.logger.log(`Data successfully written to ${filePath}`);
|
|
1616
1625
|
} catch (e) {
|
|
1617
|
-
|
|
1626
|
+
logger.logger.error(e);
|
|
1618
1627
|
}
|
|
1619
1628
|
} else {
|
|
1620
1629
|
const fdata = scope === 'org' ? formatData(data, 'org') : formatData(data, 'repo');
|
|
@@ -1663,7 +1672,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiToken) {
|
|
|
1663
1672
|
}
|
|
1664
1673
|
spinner.stop();
|
|
1665
1674
|
if (!result.data.length) {
|
|
1666
|
-
|
|
1675
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1667
1676
|
return undefined;
|
|
1668
1677
|
}
|
|
1669
1678
|
return result.data;
|
|
@@ -1677,7 +1686,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiToken) {
|
|
|
1677
1686
|
}
|
|
1678
1687
|
spinner.stop();
|
|
1679
1688
|
if (!result.data.length) {
|
|
1680
|
-
|
|
1689
|
+
logger.logger.log('No analytics data is available for this organization yet.');
|
|
1681
1690
|
return undefined;
|
|
1682
1691
|
}
|
|
1683
1692
|
return result.data;
|
|
@@ -1773,6 +1782,9 @@ function renderLineCharts(grid, screen, title, coords, data) {
|
|
|
1773
1782
|
line.setData([lineData]);
|
|
1774
1783
|
}
|
|
1775
1784
|
|
|
1785
|
+
const {
|
|
1786
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
1787
|
+
} = constants;
|
|
1776
1788
|
const config$y = {
|
|
1777
1789
|
commandName: 'analytics',
|
|
1778
1790
|
description: `Look up analytics data`,
|
|
@@ -1850,14 +1862,15 @@ async function run$y(argv, importMeta, {
|
|
|
1850
1862
|
// options or missing arguments.
|
|
1851
1863
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1852
1864
|
process.exitCode = 2;
|
|
1853
|
-
|
|
1865
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1854
1866
|
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1855
1867
|
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
|
|
1856
1868
|
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`);
|
|
1857
1869
|
return;
|
|
1858
1870
|
}
|
|
1859
1871
|
if (cli.flags['dryRun']) {
|
|
1860
|
-
|
|
1872
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
1873
|
+
return;
|
|
1861
1874
|
}
|
|
1862
1875
|
const apiToken = index.getDefaultToken();
|
|
1863
1876
|
if (!apiToken) {
|
|
@@ -1882,9 +1895,11 @@ async function getAuditLog({
|
|
|
1882
1895
|
perPage,
|
|
1883
1896
|
type
|
|
1884
1897
|
}) {
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1898
|
+
// Lazily access constants.spinner.
|
|
1899
|
+
const {
|
|
1900
|
+
spinner
|
|
1901
|
+
} = constants;
|
|
1902
|
+
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
1888
1903
|
const socketSdk = await index.setupSdk(apiToken);
|
|
1889
1904
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
1890
1905
|
outputJson,
|
|
@@ -1895,10 +1910,10 @@ async function getAuditLog({
|
|
|
1895
1910
|
per_page: perPage
|
|
1896
1911
|
}), `Looking up audit log for ${orgSlug}\n`);
|
|
1897
1912
|
if (!result.success) {
|
|
1898
|
-
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner
|
|
1913
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
1899
1914
|
return;
|
|
1900
1915
|
}
|
|
1901
|
-
spinner
|
|
1916
|
+
spinner.stop();
|
|
1902
1917
|
const data = [];
|
|
1903
1918
|
const logDetails = {};
|
|
1904
1919
|
for (const d of result.data.results) {
|
|
@@ -1917,13 +1932,16 @@ async function getAuditLog({
|
|
|
1917
1932
|
logDetails[name] = JSON.stringify(d.payload);
|
|
1918
1933
|
}
|
|
1919
1934
|
}
|
|
1920
|
-
|
|
1935
|
+
logger.logger.log(logDetails[await prompts.select({
|
|
1921
1936
|
message: type ? `\n Audit log for: ${orgSlug} with type: ${type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
1922
1937
|
choices: data,
|
|
1923
1938
|
pageSize: 30
|
|
1924
1939
|
})]);
|
|
1925
1940
|
}
|
|
1926
1941
|
|
|
1942
|
+
const {
|
|
1943
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$w
|
|
1944
|
+
} = constants;
|
|
1927
1945
|
const config$x = {
|
|
1928
1946
|
commandName: 'audit-log',
|
|
1929
1947
|
description: 'Look up the audit log for an organization',
|
|
@@ -1982,12 +2000,13 @@ async function run$x(argv, importMeta, {
|
|
|
1982
2000
|
// options or missing arguments.
|
|
1983
2001
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
1984
2002
|
process.exitCode = 2;
|
|
1985
|
-
|
|
2003
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
1986
2004
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
1987
2005
|
return;
|
|
1988
2006
|
}
|
|
1989
2007
|
if (cli.flags['dryRun']) {
|
|
1990
|
-
|
|
2008
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$w);
|
|
2009
|
+
return;
|
|
1991
2010
|
}
|
|
1992
2011
|
const apiToken = index.getDefaultToken();
|
|
1993
2012
|
if (!apiToken) {
|
|
@@ -2049,7 +2068,7 @@ async function runCycloneDX(yargv) {
|
|
|
2049
2068
|
}
|
|
2050
2069
|
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
2051
2070
|
if (fs.existsSync(fullOutputPath)) {
|
|
2052
|
-
|
|
2071
|
+
logger.logger.log(colors.cyanBright(`${yargv.output} created!`));
|
|
2053
2072
|
}
|
|
2054
2073
|
}
|
|
2055
2074
|
function argvToArray(argv) {
|
|
@@ -2079,6 +2098,10 @@ function argvToArray(argv) {
|
|
|
2079
2098
|
}
|
|
2080
2099
|
|
|
2081
2100
|
// import { meowOrExit } from '../../utils/meow-with-subcommands'
|
|
2101
|
+
const {
|
|
2102
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$v
|
|
2103
|
+
} = constants;
|
|
2104
|
+
|
|
2082
2105
|
// TODO: convert yargs to meow. Or convert all the other things to yargs.
|
|
2083
2106
|
const toLower = arg => arg.toLowerCase();
|
|
2084
2107
|
const arrayToLower = arg => arg.map(toLower);
|
|
@@ -2183,7 +2206,7 @@ async function run$w(argv, importMeta, {
|
|
|
2183
2206
|
//
|
|
2184
2207
|
//
|
|
2185
2208
|
// if (cli.input.length)
|
|
2186
|
-
//
|
|
2209
|
+
// logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2187
2210
|
// - Unexpected arguments\n
|
|
2188
2211
|
// `)
|
|
2189
2212
|
// config.help(parentName, config)
|
|
@@ -2204,14 +2227,15 @@ async function run$w(argv, importMeta, {
|
|
|
2204
2227
|
// options or missing arguments.
|
|
2205
2228
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2206
2229
|
process$1.exitCode = 2;
|
|
2207
|
-
|
|
2230
|
+
logger.logger.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
2208
2231
|
return;
|
|
2209
2232
|
}
|
|
2210
2233
|
if (yargv.output === undefined) {
|
|
2211
2234
|
yargv.output = 'socket-cdx.json';
|
|
2212
2235
|
}
|
|
2213
2236
|
if (cli.flags['dryRun']) {
|
|
2214
|
-
|
|
2237
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2238
|
+
return;
|
|
2215
2239
|
}
|
|
2216
2240
|
await runCycloneDX(yargv);
|
|
2217
2241
|
}
|
|
@@ -2226,21 +2250,23 @@ async function findDependencies({
|
|
|
2226
2250
|
if (!apiToken) {
|
|
2227
2251
|
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.');
|
|
2228
2252
|
}
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2253
|
+
// Lazily access constants.spinner.
|
|
2254
|
+
const {
|
|
2255
|
+
spinner
|
|
2256
|
+
} = constants;
|
|
2257
|
+
spinner.start('Searching dependencies...');
|
|
2232
2258
|
const socketSdk = await index.setupSdk(apiToken);
|
|
2233
2259
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
2234
2260
|
limit,
|
|
2235
2261
|
offset
|
|
2236
2262
|
}), 'Searching dependencies');
|
|
2237
2263
|
if (!result.success) {
|
|
2238
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner
|
|
2264
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
2239
2265
|
return;
|
|
2240
2266
|
}
|
|
2241
|
-
spinner
|
|
2267
|
+
spinner.stop('Organization dependencies:');
|
|
2242
2268
|
if (outputJson) {
|
|
2243
|
-
|
|
2269
|
+
logger.logger.log(result.data);
|
|
2244
2270
|
return;
|
|
2245
2271
|
}
|
|
2246
2272
|
const options = {
|
|
@@ -2267,9 +2293,12 @@ async function findDependencies({
|
|
|
2267
2293
|
name: colors.cyan('Direct')
|
|
2268
2294
|
}]
|
|
2269
2295
|
};
|
|
2270
|
-
|
|
2296
|
+
logger.logger.log(chalkTable(options, result.data.rows));
|
|
2271
2297
|
}
|
|
2272
2298
|
|
|
2299
|
+
const {
|
|
2300
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$u
|
|
2301
|
+
} = constants;
|
|
2273
2302
|
const config$v = {
|
|
2274
2303
|
commandName: 'dependencies',
|
|
2275
2304
|
description: 'Search for any dependency that is being used in your organization',
|
|
@@ -2316,7 +2345,8 @@ async function run$v(argv, importMeta, {
|
|
|
2316
2345
|
parentName
|
|
2317
2346
|
});
|
|
2318
2347
|
if (cli.flags['dryRun']) {
|
|
2319
|
-
|
|
2348
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$u);
|
|
2349
|
+
return;
|
|
2320
2350
|
}
|
|
2321
2351
|
|
|
2322
2352
|
// TODO: markdown flag is ignored
|
|
@@ -2334,40 +2364,44 @@ async function getDiffScan({
|
|
|
2334
2364
|
orgSlug,
|
|
2335
2365
|
outputJson
|
|
2336
2366
|
}, apiToken) {
|
|
2337
|
-
|
|
2338
|
-
const
|
|
2339
|
-
|
|
2340
|
-
}
|
|
2367
|
+
// Lazily access constants.spinner.
|
|
2368
|
+
const {
|
|
2369
|
+
spinner
|
|
2370
|
+
} = constants;
|
|
2371
|
+
spinner.start('Getting diff scan...');
|
|
2341
2372
|
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiToken);
|
|
2342
2373
|
const data = await response.json();
|
|
2343
2374
|
if (!response.ok) {
|
|
2344
2375
|
const err = await handleAPIError(response.status);
|
|
2345
|
-
spinner
|
|
2376
|
+
spinner.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
2346
2377
|
return;
|
|
2347
2378
|
}
|
|
2348
|
-
spinner
|
|
2379
|
+
spinner.stop();
|
|
2349
2380
|
if (file && !outputJson) {
|
|
2350
2381
|
fs.writeFile(file, JSON.stringify(data), err => {
|
|
2351
|
-
err ?
|
|
2382
|
+
err ? logger.logger.error(err) : logger.logger.log(`Data successfully written to ${file}`);
|
|
2352
2383
|
});
|
|
2353
2384
|
return;
|
|
2354
2385
|
}
|
|
2355
2386
|
if (outputJson) {
|
|
2356
|
-
|
|
2357
|
-
|
|
2387
|
+
logger.logger.log(`\n Diff scan result: \n`);
|
|
2388
|
+
logger.logger.log(require$$0$1.inspect(data, {
|
|
2358
2389
|
showHidden: false,
|
|
2359
2390
|
depth: null,
|
|
2360
2391
|
colors: true
|
|
2361
2392
|
}));
|
|
2362
|
-
|
|
2393
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2363
2394
|
return;
|
|
2364
2395
|
}
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2396
|
+
logger.logger.log('Diff scan result:');
|
|
2397
|
+
logger.logger.log(data);
|
|
2398
|
+
logger.logger.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
2399
|
+
logger.logger.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
2369
2400
|
}
|
|
2370
2401
|
|
|
2402
|
+
const {
|
|
2403
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$t
|
|
2404
|
+
} = constants;
|
|
2371
2405
|
const config$u = {
|
|
2372
2406
|
commandName: 'get',
|
|
2373
2407
|
description: 'Get a diff scan for an organization',
|
|
@@ -2433,14 +2467,15 @@ async function run$u(argv, importMeta, {
|
|
|
2433
2467
|
// options or missing arguments.
|
|
2434
2468
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2435
2469
|
process.exitCode = 2;
|
|
2436
|
-
|
|
2470
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2437
2471
|
- 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
|
|
2438
2472
|
- To get full scans IDs, you can run the command "socket scan list <your org slug>".
|
|
2439
2473
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
2440
2474
|
return;
|
|
2441
2475
|
}
|
|
2442
2476
|
if (cli.flags['dryRun']) {
|
|
2443
|
-
|
|
2477
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$t);
|
|
2478
|
+
return;
|
|
2444
2479
|
}
|
|
2445
2480
|
const apiToken = index.getDefaultToken();
|
|
2446
2481
|
if (!apiToken) {
|
|
@@ -2483,7 +2518,11 @@ function isTopLevel(tree, node) {
|
|
|
2483
2518
|
return tree.children.get(node.name) === node;
|
|
2484
2519
|
}
|
|
2485
2520
|
async function runFix() {
|
|
2486
|
-
|
|
2521
|
+
// Lazily access constants.spinner.
|
|
2522
|
+
const {
|
|
2523
|
+
spinner
|
|
2524
|
+
} = constants;
|
|
2525
|
+
spinner.start();
|
|
2487
2526
|
const cwd = process.cwd();
|
|
2488
2527
|
const editablePkgJson = await packages.readPackageJson(cwd, {
|
|
2489
2528
|
editable: true
|
|
@@ -2514,9 +2553,7 @@ async function runFix() {
|
|
|
2514
2553
|
const tree = arb.idealTree;
|
|
2515
2554
|
const hasUpgrade = !!registry.getManifestData(NPM$d, name);
|
|
2516
2555
|
if (hasUpgrade) {
|
|
2517
|
-
spinner$
|
|
2518
|
-
console.log(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2519
|
-
spinner$1.start();
|
|
2556
|
+
spinner.info(`Skipping ${name}. Socket Optimize package exists.`);
|
|
2520
2557
|
continue;
|
|
2521
2558
|
}
|
|
2522
2559
|
const nodes = index.findPackageNodes(tree, name);
|
|
@@ -2542,10 +2579,10 @@ async function runFix() {
|
|
|
2542
2579
|
try {
|
|
2543
2580
|
// eslint-disable-next-line no-await-in-loop
|
|
2544
2581
|
await npm.runScript('test', [], {
|
|
2545
|
-
|
|
2582
|
+
spinner,
|
|
2583
|
+
stdio: 'ignore'
|
|
2546
2584
|
});
|
|
2547
|
-
spinner
|
|
2548
|
-
spinner$1.start();
|
|
2585
|
+
spinner.info(`Patched ${name} ${oldVersion} -> ${node.version}`);
|
|
2549
2586
|
if (isTopLevel(tree, node)) {
|
|
2550
2587
|
for (const depField of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
2551
2588
|
const oldVersion = editablePkgJson.content[depField]?.[name];
|
|
@@ -2558,14 +2595,11 @@ async function runFix() {
|
|
|
2558
2595
|
// eslint-disable-next-line no-await-in-loop
|
|
2559
2596
|
await editablePkgJson.save();
|
|
2560
2597
|
} catch {
|
|
2561
|
-
spinner
|
|
2562
|
-
spinner$1.start();
|
|
2598
|
+
spinner.error(`Reverting ${name} to ${oldVersion}`);
|
|
2563
2599
|
arb.idealTree = revertToIdealTree;
|
|
2564
2600
|
}
|
|
2565
2601
|
} else {
|
|
2566
|
-
spinner
|
|
2567
|
-
console.log(`Could not patch ${name} ${oldVersion}`);
|
|
2568
|
-
spinner$1.start();
|
|
2602
|
+
spinner.error(`Could not patch ${name} ${oldVersion}`);
|
|
2569
2603
|
}
|
|
2570
2604
|
}
|
|
2571
2605
|
}
|
|
@@ -2577,9 +2611,12 @@ async function runFix() {
|
|
|
2577
2611
|
});
|
|
2578
2612
|
arb2.idealTree = arb.idealTree;
|
|
2579
2613
|
await arb2.reify();
|
|
2580
|
-
spinner
|
|
2614
|
+
spinner.stop();
|
|
2581
2615
|
}
|
|
2582
2616
|
|
|
2617
|
+
const {
|
|
2618
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$s
|
|
2619
|
+
} = constants;
|
|
2583
2620
|
const config$t = {
|
|
2584
2621
|
commandName: 'fix',
|
|
2585
2622
|
description: 'Fix "fixable" Socket alerts',
|
|
@@ -2610,7 +2647,8 @@ async function run$t(argv, importMeta, {
|
|
|
2610
2647
|
parentName
|
|
2611
2648
|
});
|
|
2612
2649
|
if (cli.flags['dryRun']) {
|
|
2613
|
-
|
|
2650
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$s);
|
|
2651
|
+
return;
|
|
2614
2652
|
}
|
|
2615
2653
|
await runFix();
|
|
2616
2654
|
}
|
|
@@ -2722,9 +2760,9 @@ function formatPackageInfo({
|
|
|
2722
2760
|
strict
|
|
2723
2761
|
}, spinner) {
|
|
2724
2762
|
if (outputJson) {
|
|
2725
|
-
|
|
2763
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
2726
2764
|
} else {
|
|
2727
|
-
|
|
2765
|
+
logger.logger.log('\nPackage report card:');
|
|
2728
2766
|
const scoreResult = {
|
|
2729
2767
|
'Supply Chain Risk': Math.floor(score.supplyChainRisk.score * 100),
|
|
2730
2768
|
Maintenance: Math.floor(score.maintenance.score * 100),
|
|
@@ -2732,8 +2770,8 @@ function formatPackageInfo({
|
|
|
2732
2770
|
Vulnerabilities: Math.floor(score.vulnerability.score * 100),
|
|
2733
2771
|
License: Math.floor(score.license.score * 100)
|
|
2734
2772
|
};
|
|
2735
|
-
Object.entries(scoreResult).map(score =>
|
|
2736
|
-
|
|
2773
|
+
Object.entries(scoreResult).map(score => logger.logger.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
2774
|
+
logger.logger.log('\n');
|
|
2737
2775
|
if (objectSome(severityCount)) {
|
|
2738
2776
|
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
2739
2777
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
@@ -2742,18 +2780,18 @@ function formatPackageInfo({
|
|
|
2742
2780
|
}
|
|
2743
2781
|
const format = new index.ColorOrMarkdown(!!outputMarkdown);
|
|
2744
2782
|
const url = index.getSocketDevPackageOverviewUrl(NPM$c, pkgName, pkgVersion);
|
|
2745
|
-
|
|
2783
|
+
logger.logger.log('\n');
|
|
2746
2784
|
if (pkgVersion === 'latest') {
|
|
2747
|
-
|
|
2785
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
2748
2786
|
fallbackToUrl: true
|
|
2749
2787
|
})}`);
|
|
2750
2788
|
} else {
|
|
2751
|
-
|
|
2789
|
+
logger.logger.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
|
|
2752
2790
|
fallbackToUrl: true
|
|
2753
2791
|
})}`);
|
|
2754
2792
|
}
|
|
2755
2793
|
if (!outputMarkdown) {
|
|
2756
|
-
|
|
2794
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2757
2795
|
}
|
|
2758
2796
|
}
|
|
2759
2797
|
if (strict && objectSome(severityCount)) {
|
|
@@ -2784,9 +2822,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2784
2822
|
fallbackToUrl: true
|
|
2785
2823
|
});
|
|
2786
2824
|
if (uniqueIssues[issue]?.count === 1) {
|
|
2787
|
-
|
|
2825
|
+
logger.logger.log(`- ${issueWithLink}`);
|
|
2788
2826
|
} else {
|
|
2789
|
-
|
|
2827
|
+
logger.logger.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`);
|
|
2790
2828
|
}
|
|
2791
2829
|
}
|
|
2792
2830
|
}
|
|
@@ -2808,11 +2846,12 @@ async function getPackageInfo({
|
|
|
2808
2846
|
pkgVersion,
|
|
2809
2847
|
strict
|
|
2810
2848
|
}) {
|
|
2811
|
-
|
|
2812
|
-
const
|
|
2813
|
-
|
|
2814
|
-
}
|
|
2815
|
-
|
|
2849
|
+
// Lazily access constants.spinner.
|
|
2850
|
+
const {
|
|
2851
|
+
spinner
|
|
2852
|
+
} = constants;
|
|
2853
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2854
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues, spinner);
|
|
2816
2855
|
if (packageData) {
|
|
2817
2856
|
formatPackageInfo(packageData, {
|
|
2818
2857
|
name: commandName,
|
|
@@ -2821,10 +2860,13 @@ async function getPackageInfo({
|
|
|
2821
2860
|
pkgName,
|
|
2822
2861
|
pkgVersion,
|
|
2823
2862
|
strict
|
|
2824
|
-
}, spinner
|
|
2863
|
+
}, spinner);
|
|
2825
2864
|
}
|
|
2826
2865
|
}
|
|
2827
2866
|
|
|
2867
|
+
const {
|
|
2868
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$r
|
|
2869
|
+
} = constants;
|
|
2828
2870
|
const config$s = {
|
|
2829
2871
|
commandName: 'info',
|
|
2830
2872
|
description: 'Look up info regarding a package',
|
|
@@ -2866,7 +2908,7 @@ async function run$s(argv, importMeta, {
|
|
|
2866
2908
|
// options or missing arguments.
|
|
2867
2909
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
2868
2910
|
process.exitCode = 2;
|
|
2869
|
-
|
|
2911
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2870
2912
|
- Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
2871
2913
|
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`);
|
|
2872
2914
|
return;
|
|
@@ -2875,7 +2917,8 @@ async function run$s(argv, importMeta, {
|
|
|
2875
2917
|
const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
|
|
2876
2918
|
const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
|
|
2877
2919
|
if (cli.flags['dryRun']) {
|
|
2878
|
-
|
|
2920
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$r);
|
|
2921
|
+
return;
|
|
2879
2922
|
}
|
|
2880
2923
|
await getPackageInfo({
|
|
2881
2924
|
commandName: `${parentName} ${config$s.commandName}`,
|
|
@@ -2901,14 +2944,16 @@ const {
|
|
|
2901
2944
|
SOCKET_PUBLIC_API_TOKEN
|
|
2902
2945
|
} = constants;
|
|
2903
2946
|
async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
2947
|
+
apiBaseUrl ??= index.getSetting('apiBaseUrl') ?? undefined;
|
|
2948
|
+
apiProxy ??= index.getSetting('apiProxy') ?? undefined;
|
|
2904
2949
|
const apiToken = (await prompts.password({
|
|
2905
2950
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
2906
2951
|
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2952
|
+
// Lazily access constants.spinner.
|
|
2953
|
+
const {
|
|
2954
|
+
spinner
|
|
2955
|
+
} = constants;
|
|
2956
|
+
spinner.start('Verifying API key...');
|
|
2912
2957
|
let orgs;
|
|
2913
2958
|
try {
|
|
2914
2959
|
const sdk = await index.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
@@ -2917,9 +2962,9 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2917
2962
|
throw new index.AuthError();
|
|
2918
2963
|
}
|
|
2919
2964
|
orgs = result.data;
|
|
2920
|
-
spinner
|
|
2965
|
+
spinner.success('API key verified');
|
|
2921
2966
|
} catch {
|
|
2922
|
-
spinner
|
|
2967
|
+
spinner.errorAndStop('Invalid API key');
|
|
2923
2968
|
return;
|
|
2924
2969
|
}
|
|
2925
2970
|
const enforcedChoices = Object.values(orgs.organizations).filter(org => org?.plan === 'enterprise').map(org => ({
|
|
@@ -2935,6 +2980,8 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2935
2980
|
value: '',
|
|
2936
2981
|
description: 'Pick "None" if this is a personal device'
|
|
2937
2982
|
})
|
|
2983
|
+
}, {
|
|
2984
|
+
spinner
|
|
2938
2985
|
});
|
|
2939
2986
|
if (id) {
|
|
2940
2987
|
enforcedOrgs = [id];
|
|
@@ -2943,6 +2990,8 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2943
2990
|
const confirmOrg = await prompts.confirm({
|
|
2944
2991
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
2945
2992
|
default: true
|
|
2993
|
+
}, {
|
|
2994
|
+
spinner
|
|
2946
2995
|
});
|
|
2947
2996
|
if (confirmOrg) {
|
|
2948
2997
|
const existing = enforcedChoices[0];
|
|
@@ -2954,12 +3003,15 @@ async function attemptLogin(apiBaseUrl, apiProxy) {
|
|
|
2954
3003
|
const oldToken = index.getSetting('apiToken');
|
|
2955
3004
|
try {
|
|
2956
3005
|
applyLogin(apiToken, enforcedOrgs, apiBaseUrl, apiProxy);
|
|
2957
|
-
spinner
|
|
3006
|
+
spinner.successAndStop(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
2958
3007
|
} catch {
|
|
2959
|
-
spinner
|
|
3008
|
+
spinner.errorAndStop(`API login failed`);
|
|
2960
3009
|
}
|
|
2961
3010
|
}
|
|
2962
3011
|
|
|
3012
|
+
const {
|
|
3013
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$q
|
|
3014
|
+
} = constants;
|
|
2963
3015
|
const config$r = {
|
|
2964
3016
|
commandName: 'login',
|
|
2965
3017
|
description: 'Socket API login',
|
|
@@ -3006,7 +3058,8 @@ async function run$r(argv, importMeta, {
|
|
|
3006
3058
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
3007
3059
|
let apiProxy = cli.flags['apiProxy'];
|
|
3008
3060
|
if (cli.flags['dryRun']) {
|
|
3009
|
-
|
|
3061
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$q);
|
|
3062
|
+
return;
|
|
3010
3063
|
}
|
|
3011
3064
|
if (!isInteractive()) {
|
|
3012
3065
|
throw new index.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
@@ -3024,12 +3077,15 @@ function applyLogout() {
|
|
|
3024
3077
|
function attemptLogout() {
|
|
3025
3078
|
try {
|
|
3026
3079
|
applyLogout();
|
|
3027
|
-
|
|
3080
|
+
logger.logger.success('Successfully logged out');
|
|
3028
3081
|
} catch {
|
|
3029
|
-
|
|
3082
|
+
logger.logger.error('Failed to complete logout steps');
|
|
3030
3083
|
}
|
|
3031
3084
|
}
|
|
3032
3085
|
|
|
3086
|
+
const {
|
|
3087
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$p
|
|
3088
|
+
} = constants;
|
|
3033
3089
|
const config$q = {
|
|
3034
3090
|
commandName: 'logout',
|
|
3035
3091
|
description: 'Socket API logout',
|
|
@@ -3059,31 +3115,31 @@ async function run$q(argv, importMeta, {
|
|
|
3059
3115
|
parentName
|
|
3060
3116
|
});
|
|
3061
3117
|
if (cli.flags['dryRun']) {
|
|
3062
|
-
|
|
3118
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$p);
|
|
3119
|
+
return;
|
|
3063
3120
|
}
|
|
3064
3121
|
attemptLogout();
|
|
3065
3122
|
}
|
|
3066
3123
|
|
|
3067
3124
|
async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
3125
|
+
// Lazily access constants.spinner.
|
|
3126
|
+
const {
|
|
3127
|
+
spinner
|
|
3128
|
+
} = constants;
|
|
3068
3129
|
const rbin = path.resolve(bin);
|
|
3069
3130
|
const rtarget = path.resolve(target);
|
|
3070
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3071
|
-
|
|
3072
3131
|
if (verbose) {
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
console.groupEnd();
|
|
3132
|
+
logger.logger.group('gradle2maven:');
|
|
3133
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3134
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3135
|
+
logger.logger.groupEnd();
|
|
3078
3136
|
} else {
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
}
|
|
3085
|
-
const spinner$1 = new spinner.Spinner();
|
|
3086
|
-
spinner$1.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3137
|
+
logger.logger.group('gradle2maven:');
|
|
3138
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3139
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3140
|
+
logger.logger.groupEnd();
|
|
3141
|
+
}
|
|
3142
|
+
spinner.start(`Converting gradle to maven from \`${bin}\` on \`${target}\`...`);
|
|
3087
3143
|
try {
|
|
3088
3144
|
// Run sbt with the init script we provide which should yield zero or more pom files.
|
|
3089
3145
|
// We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API.
|
|
@@ -3093,38 +3149,37 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3093
3149
|
const initLocation = path.join(constants.rootDistPath, 'init.gradle');
|
|
3094
3150
|
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'];
|
|
3095
3151
|
if (verbose) {
|
|
3096
|
-
|
|
3152
|
+
spinner.log('[VERBOSE] Executing:', bin, commandArgs);
|
|
3097
3153
|
}
|
|
3098
3154
|
const output = await spawn(bin, commandArgs, {
|
|
3099
3155
|
cwd: target || '.'
|
|
3100
3156
|
});
|
|
3101
|
-
spinner
|
|
3157
|
+
spinner.stop();
|
|
3102
3158
|
if (verbose) {
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3159
|
+
logger.logger.group('[VERBOSE] gradle stdout:');
|
|
3160
|
+
logger.logger.log(output);
|
|
3161
|
+
logger.logger.groupEnd();
|
|
3106
3162
|
}
|
|
3107
3163
|
if (output.stderr) {
|
|
3108
|
-
|
|
3164
|
+
logger.logger.error('There were errors while running gradle');
|
|
3109
3165
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3110
3166
|
if (!verbose) {
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3167
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3168
|
+
logger.logger.error(output.stderr);
|
|
3169
|
+
logger.logger.groupEnd();
|
|
3114
3170
|
}
|
|
3115
3171
|
process.exit(1);
|
|
3116
3172
|
}
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
console.log('Reported exports:');
|
|
3173
|
+
logger.logger.success('Executed gradle successfully');
|
|
3174
|
+
logger.logger.log('Reported exports:');
|
|
3120
3175
|
output.stdout.replace(/^POM file copied to: (.*)/gm, (_all, fn) => {
|
|
3121
|
-
|
|
3176
|
+
logger.logger.log('- ', fn);
|
|
3122
3177
|
return fn;
|
|
3123
3178
|
});
|
|
3124
3179
|
|
|
3125
3180
|
// const loc = output.stdout?.match(/Wrote (.*?.pom)\n/)?.[1]?.trim()
|
|
3126
3181
|
// if (!loc) {
|
|
3127
|
-
//
|
|
3182
|
+
// logger.error(
|
|
3128
3183
|
// 'There were no errors from sbt but could not find the location of resulting .pom file either'
|
|
3129
3184
|
// )
|
|
3130
3185
|
// process.exit(1)
|
|
@@ -3132,34 +3187,38 @@ async function convertGradleToMaven(target, bin, _out, verbose, gradleOpts) {
|
|
|
3132
3187
|
//
|
|
3133
3188
|
// // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3134
3189
|
// if (out === '-') {
|
|
3135
|
-
// spinner.start('Result:\n```')
|
|
3136
|
-
//
|
|
3137
|
-
//
|
|
3138
|
-
// spinner.
|
|
3190
|
+
// spinner.start('Result:\n```')
|
|
3191
|
+
// spinner.log(await safeReadFile(loc, 'utf8'))
|
|
3192
|
+
// spinner.log('```')
|
|
3193
|
+
// spinner.successAndStop(`OK`)
|
|
3139
3194
|
// } else {
|
|
3195
|
+
// spinner.start()
|
|
3140
3196
|
// if (verbose) {
|
|
3141
|
-
// spinner.
|
|
3197
|
+
// spinner.log(
|
|
3142
3198
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3143
3199
|
// )
|
|
3144
3200
|
// } else {
|
|
3145
|
-
// spinner.
|
|
3201
|
+
// spinner.log('Moving output pom file')
|
|
3146
3202
|
// }
|
|
3147
3203
|
// // TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3148
3204
|
// await renamep(loc, out)
|
|
3149
|
-
// spinner.successAndStop()
|
|
3150
|
-
// spinner.start().success(`OK. File should be available in \`${out}\``)
|
|
3205
|
+
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
|
|
3151
3206
|
// }
|
|
3152
3207
|
} catch (e) {
|
|
3153
|
-
spinner
|
|
3208
|
+
spinner.stop();
|
|
3209
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3154
3210
|
if (verbose) {
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3211
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3212
|
+
logger.logger.log(e);
|
|
3213
|
+
logger.logger.groupEnd();
|
|
3158
3214
|
}
|
|
3159
3215
|
process.exit(1);
|
|
3160
3216
|
}
|
|
3161
3217
|
}
|
|
3162
3218
|
|
|
3219
|
+
const {
|
|
3220
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$o
|
|
3221
|
+
} = constants;
|
|
3163
3222
|
const config$p = {
|
|
3164
3223
|
commandName: 'gradle',
|
|
3165
3224
|
description: '[beta] Use Gradle to generate a manifest file (`pom.xml`) for a Gradle/Java/Kotlin/etc project',
|
|
@@ -3247,22 +3306,23 @@ async function run$p(argv, importMeta, {
|
|
|
3247
3306
|
});
|
|
3248
3307
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3249
3308
|
if (verbose) {
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3309
|
+
logger.logger.group('- ', parentName, config$p.commandName, ':');
|
|
3310
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3311
|
+
logger.logger.groupEnd();
|
|
3312
|
+
logger.logger.log('- input:', cli.input);
|
|
3313
|
+
logger.logger.groupEnd();
|
|
3255
3314
|
}
|
|
3256
3315
|
const target = cli.input[0];
|
|
3257
3316
|
|
|
3258
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3259
|
-
|
|
3317
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3318
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3319
|
+
// would the file name be?
|
|
3260
3320
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3261
3321
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3262
3322
|
// options or missing arguments.
|
|
3263
3323
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3264
3324
|
process.exitCode = 2;
|
|
3265
|
-
|
|
3325
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3266
3326
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3267
3327
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3268
3328
|
return;
|
|
@@ -3281,64 +3341,66 @@ async function run$p(argv, importMeta, {
|
|
|
3281
3341
|
out = '-';
|
|
3282
3342
|
}
|
|
3283
3343
|
if (verbose) {
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3344
|
+
logger.logger.group();
|
|
3345
|
+
logger.logger.log('- target:', target);
|
|
3346
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3347
|
+
logger.logger.log('- out:', out);
|
|
3348
|
+
logger.logger.groupEnd();
|
|
3289
3349
|
}
|
|
3290
3350
|
let gradleOpts = [];
|
|
3291
3351
|
if (cli.flags['gradleOpts']) {
|
|
3292
3352
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3293
3353
|
}
|
|
3294
3354
|
if (cli.flags['dryRun']) {
|
|
3295
|
-
|
|
3355
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$o);
|
|
3356
|
+
return;
|
|
3296
3357
|
}
|
|
3297
3358
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3298
3359
|
}
|
|
3299
3360
|
|
|
3300
3361
|
async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
3362
|
+
// Lazily access constants.spinner.
|
|
3363
|
+
const {
|
|
3364
|
+
spinner
|
|
3365
|
+
} = constants;
|
|
3301
3366
|
const rbin = path.resolve(bin);
|
|
3302
3367
|
const rtarget = path.resolve(target);
|
|
3303
|
-
// const rout = out === '-' ? '-' : path.resolve(out)
|
|
3304
|
-
|
|
3305
3368
|
if (verbose) {
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
//
|
|
3310
|
-
|
|
3369
|
+
logger.logger.group('sbt2maven:');
|
|
3370
|
+
logger.logger.log(`[VERBOSE] - Absolute bin path: \`${rbin}\``);
|
|
3371
|
+
logger.logger.log(`[VERBOSE] - Absolute target path: \`${rtarget}\``);
|
|
3372
|
+
// logger.log(`[VERBOSE] - Absolute out path: \`${rout}\``)
|
|
3373
|
+
logger.logger.groupEnd();
|
|
3311
3374
|
} else {
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
//
|
|
3316
|
-
|
|
3317
|
-
}
|
|
3318
|
-
|
|
3319
|
-
spinner$1.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3375
|
+
logger.logger.group('sbt2maven:');
|
|
3376
|
+
logger.logger.log(`- executing: \`${bin}\``);
|
|
3377
|
+
logger.logger.log(`- src dir: \`${target}\``);
|
|
3378
|
+
// logger.log(`- dst dir: \`${out}\``)
|
|
3379
|
+
logger.logger.groupEnd();
|
|
3380
|
+
}
|
|
3381
|
+
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`);
|
|
3320
3382
|
try {
|
|
3321
|
-
// Run sbt with the init script we provide which should yield zero or more
|
|
3322
|
-
// We have to figure out where to store those pom files such that
|
|
3323
|
-
//
|
|
3324
|
-
|
|
3383
|
+
// Run sbt with the init script we provide which should yield zero or more
|
|
3384
|
+
// pom files. We have to figure out where to store those pom files such that
|
|
3385
|
+
// we can upload them and predict them through the GitHub API. We could do a
|
|
3386
|
+
// .socket folder. We could do a socket.pom.gz with all the poms, although
|
|
3387
|
+
// I'd prefer something plain-text if it is to be committed.
|
|
3325
3388
|
const output = await spawn(bin, ['makePom'].concat(sbtOpts), {
|
|
3326
3389
|
cwd: target || '.'
|
|
3327
3390
|
});
|
|
3328
|
-
spinner
|
|
3391
|
+
spinner.stop();
|
|
3329
3392
|
if (verbose) {
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3393
|
+
logger.logger.group('[VERBOSE] sbt stdout:');
|
|
3394
|
+
logger.logger.log(output);
|
|
3395
|
+
logger.logger.groupEnd();
|
|
3333
3396
|
}
|
|
3334
3397
|
if (output.stderr) {
|
|
3335
|
-
|
|
3336
|
-
spinner$1.errorAndStop('There were errors while running sbt');
|
|
3398
|
+
logger.logger.error('There were errors while running sbt');
|
|
3337
3399
|
// (In verbose mode, stderr was printed above, no need to repeat it)
|
|
3338
3400
|
if (!verbose) {
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3401
|
+
logger.logger.group('[VERBOSE] stderr:');
|
|
3402
|
+
logger.logger.error(output.stderr);
|
|
3403
|
+
logger.logger.groupEnd();
|
|
3342
3404
|
}
|
|
3343
3405
|
process.exit(1);
|
|
3344
3406
|
}
|
|
@@ -3348,48 +3410,51 @@ async function convertSbtToMaven(target, bin, out, verbose, sbtOpts) {
|
|
|
3348
3410
|
return fn;
|
|
3349
3411
|
});
|
|
3350
3412
|
if (!poms.length) {
|
|
3351
|
-
|
|
3413
|
+
logger.logger.error('There were no errors from sbt but it seems to not have generated any poms either');
|
|
3352
3414
|
process.exit(1);
|
|
3353
3415
|
}
|
|
3354
|
-
|
|
3355
3416
|
// Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
|
|
3356
3417
|
// TODO: what to do with multiple output files? Do we want to dump them to stdout? Raw or with separators or ?
|
|
3357
3418
|
// TODO: maybe we can add an option to target a specific file to dump to stdout
|
|
3358
3419
|
if (out === '-' && poms.length === 1) {
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3420
|
+
logger.logger.log('Result:\n```');
|
|
3421
|
+
logger.logger.log(await index.safeReadFile(poms[0], 'utf8'));
|
|
3422
|
+
logger.logger.log('```');
|
|
3423
|
+
logger.logger.success(`OK`);
|
|
3363
3424
|
} else if (out === '-') {
|
|
3364
|
-
|
|
3365
|
-
poms.forEach(fn =>
|
|
3366
|
-
|
|
3425
|
+
logger.logger.error('Requested out target was stdout but there are multiple generated files');
|
|
3426
|
+
poms.forEach(fn => logger.logger.error('-', fn));
|
|
3427
|
+
logger.logger.error('Exiting now...');
|
|
3367
3428
|
process.exit(1);
|
|
3368
3429
|
} else {
|
|
3369
3430
|
// if (verbose) {
|
|
3370
|
-
//
|
|
3431
|
+
// logger.log(
|
|
3371
3432
|
// `Moving manifest file from \`${loc.replace(/^\/home\/[^/]*?\//, '~/')}\` to \`${out}\``
|
|
3372
3433
|
// )
|
|
3373
3434
|
// } else {
|
|
3374
|
-
//
|
|
3435
|
+
// logger.log('Moving output pom file')
|
|
3375
3436
|
// }
|
|
3376
3437
|
// TODO: do we prefer fs-extra? renaming can be gnarly on windows and fs-extra's version is better
|
|
3377
3438
|
// await renamep(loc, out)
|
|
3378
|
-
|
|
3379
|
-
poms.forEach(fn =>
|
|
3380
|
-
|
|
3439
|
+
logger.logger.success(`Generated ${poms.length} pom files`);
|
|
3440
|
+
poms.forEach(fn => logger.logger.log('-', fn));
|
|
3441
|
+
logger.logger.success(`OK`);
|
|
3381
3442
|
}
|
|
3382
3443
|
} catch (e) {
|
|
3383
|
-
spinner
|
|
3444
|
+
spinner.stop();
|
|
3445
|
+
logger.logger.error('There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)'));
|
|
3384
3446
|
if (verbose) {
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3447
|
+
logger.logger.group('[VERBOSE] error:');
|
|
3448
|
+
logger.logger.log(e);
|
|
3449
|
+
logger.logger.groupEnd();
|
|
3388
3450
|
}
|
|
3389
3451
|
process.exit(1);
|
|
3390
3452
|
}
|
|
3391
3453
|
}
|
|
3392
3454
|
|
|
3455
|
+
const {
|
|
3456
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$n
|
|
3457
|
+
} = constants;
|
|
3393
3458
|
const config$o = {
|
|
3394
3459
|
commandName: 'scala',
|
|
3395
3460
|
description: "[beta] Generate a manifest file (`pom.xml`) from Scala's `build.sbt` file",
|
|
@@ -3467,7 +3532,6 @@ const cmdManifestScala = {
|
|
|
3467
3532
|
async function run$o(argv, importMeta, {
|
|
3468
3533
|
parentName
|
|
3469
3534
|
}) {
|
|
3470
|
-
// console.log('scala', argv, parentName)
|
|
3471
3535
|
const cli = meowOrExit({
|
|
3472
3536
|
argv,
|
|
3473
3537
|
config: config$o,
|
|
@@ -3476,22 +3540,23 @@ async function run$o(argv, importMeta, {
|
|
|
3476
3540
|
});
|
|
3477
3541
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3478
3542
|
if (verbose) {
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3543
|
+
logger.logger.group('- ', parentName, config$o.commandName, ':');
|
|
3544
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3545
|
+
logger.logger.groupEnd();
|
|
3546
|
+
logger.logger.log('- input:', cli.input);
|
|
3547
|
+
logger.logger.groupEnd();
|
|
3484
3548
|
}
|
|
3485
3549
|
const target = cli.input[0];
|
|
3486
3550
|
|
|
3487
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3488
|
-
|
|
3551
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3552
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3553
|
+
// would the file name be?
|
|
3489
3554
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3490
3555
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3491
3556
|
// options or missing arguments.
|
|
3492
3557
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3493
3558
|
process.exitCode = 2;
|
|
3494
|
-
|
|
3559
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3495
3560
|
- The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3496
3561
|
- 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`);
|
|
3497
3562
|
return;
|
|
@@ -3508,22 +3573,26 @@ async function run$o(argv, importMeta, {
|
|
|
3508
3573
|
out = '-';
|
|
3509
3574
|
}
|
|
3510
3575
|
if (verbose) {
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3576
|
+
logger.logger.group();
|
|
3577
|
+
logger.logger.log('- target:', target);
|
|
3578
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3579
|
+
logger.logger.log('- out:', out);
|
|
3580
|
+
logger.logger.groupEnd();
|
|
3516
3581
|
}
|
|
3517
3582
|
let sbtOpts = [];
|
|
3518
3583
|
if (cli.flags['sbtOpts']) {
|
|
3519
3584
|
sbtOpts = cli.flags['sbtOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3520
3585
|
}
|
|
3521
3586
|
if (cli.flags['dryRun']) {
|
|
3522
|
-
|
|
3587
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$n);
|
|
3588
|
+
return;
|
|
3523
3589
|
}
|
|
3524
3590
|
await convertSbtToMaven(target, bin, out, verbose, sbtOpts);
|
|
3525
3591
|
}
|
|
3526
3592
|
|
|
3593
|
+
const {
|
|
3594
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$m
|
|
3595
|
+
} = constants;
|
|
3527
3596
|
const config$n = {
|
|
3528
3597
|
commandName: 'auto',
|
|
3529
3598
|
description: 'Auto-detect build and attempt to generate manifest file',
|
|
@@ -3570,12 +3639,12 @@ async function run$n(argv, importMeta, {
|
|
|
3570
3639
|
const verbose = !!cli.flags['verbose'];
|
|
3571
3640
|
const cwd = cli.flags['cwd'] ?? process.cwd();
|
|
3572
3641
|
if (verbose) {
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3642
|
+
logger.logger.group('- ', parentName, config$n.commandName, ':');
|
|
3643
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3644
|
+
logger.logger.groupEnd();
|
|
3645
|
+
logger.logger.log('- input:', cli.input);
|
|
3646
|
+
logger.logger.log('- cwd:', cwd);
|
|
3647
|
+
logger.logger.groupEnd();
|
|
3579
3648
|
}
|
|
3580
3649
|
const subArgs = [];
|
|
3581
3650
|
if (verbose) {
|
|
@@ -3583,13 +3652,14 @@ async function run$n(argv, importMeta, {
|
|
|
3583
3652
|
}
|
|
3584
3653
|
const dir = cwd;
|
|
3585
3654
|
if (fs.existsSync(path.join(dir, 'build.sbt'))) {
|
|
3586
|
-
|
|
3655
|
+
logger.logger.log('Detected a Scala sbt build, running default Scala generator...');
|
|
3587
3656
|
if (cwd) {
|
|
3588
3657
|
subArgs.push('--cwd', cwd);
|
|
3589
3658
|
}
|
|
3590
3659
|
subArgs.push(dir);
|
|
3591
3660
|
if (cli.flags['dryRun']) {
|
|
3592
|
-
|
|
3661
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3662
|
+
return;
|
|
3593
3663
|
}
|
|
3594
3664
|
await cmdManifestScala.run(subArgs, importMeta, {
|
|
3595
3665
|
parentName
|
|
@@ -3597,13 +3667,14 @@ async function run$n(argv, importMeta, {
|
|
|
3597
3667
|
return;
|
|
3598
3668
|
}
|
|
3599
3669
|
if (fs.existsSync(path.join(dir, 'gradlew'))) {
|
|
3600
|
-
|
|
3670
|
+
logger.logger.log('Detected a gradle build, running default gradle generator...');
|
|
3601
3671
|
if (cwd) {
|
|
3602
3672
|
// This command takes the cwd as first arg.
|
|
3603
3673
|
subArgs.push(cwd);
|
|
3604
3674
|
}
|
|
3605
3675
|
if (cli.flags['dryRun']) {
|
|
3606
|
-
|
|
3676
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$m);
|
|
3677
|
+
return;
|
|
3607
3678
|
}
|
|
3608
3679
|
await cmdManifestGradle.run(subArgs, importMeta, {
|
|
3609
3680
|
parentName
|
|
@@ -3631,6 +3702,10 @@ async function run$n(argv, importMeta, {
|
|
|
3631
3702
|
}).showHelp();
|
|
3632
3703
|
}
|
|
3633
3704
|
|
|
3705
|
+
const {
|
|
3706
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$l
|
|
3707
|
+
} = constants;
|
|
3708
|
+
|
|
3634
3709
|
// TODO: we may want to dedupe some pieces for all gradle languages. I think it
|
|
3635
3710
|
// makes sense to have separate commands for them and I think it makes
|
|
3636
3711
|
// sense for the help panels to note the requested language, rather than
|
|
@@ -3723,22 +3798,23 @@ async function run$m(argv, importMeta, {
|
|
|
3723
3798
|
});
|
|
3724
3799
|
const verbose = Boolean(cli.flags['verbose']);
|
|
3725
3800
|
if (verbose) {
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3801
|
+
logger.logger.group('- ', parentName, config$m.commandName, ':');
|
|
3802
|
+
logger.logger.group('- flags:', cli.flags);
|
|
3803
|
+
logger.logger.groupEnd();
|
|
3804
|
+
logger.logger.log('- input:', cli.input);
|
|
3805
|
+
logger.logger.groupEnd();
|
|
3731
3806
|
}
|
|
3732
3807
|
const target = cli.input[0];
|
|
3733
3808
|
|
|
3734
|
-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3735
|
-
|
|
3809
|
+
// TODO: I'm not sure it's feasible to parse source file from stdin. We could
|
|
3810
|
+
// try, store contents in a file in some folder, target that folder... what
|
|
3811
|
+
// would the file name be?
|
|
3736
3812
|
if (!target || target === '-' || cli.input.length > 1) {
|
|
3737
3813
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
3738
3814
|
// options or missing arguments.
|
|
3739
3815
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
3740
3816
|
process.exitCode = 2;
|
|
3741
|
-
|
|
3817
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
3742
3818
|
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
|
|
3743
3819
|
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`);
|
|
3744
3820
|
return;
|
|
@@ -3757,18 +3833,19 @@ async function run$m(argv, importMeta, {
|
|
|
3757
3833
|
out = '-';
|
|
3758
3834
|
}
|
|
3759
3835
|
if (verbose) {
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3836
|
+
logger.logger.group();
|
|
3837
|
+
logger.logger.log('- target:', target);
|
|
3838
|
+
logger.logger.log('- gradle bin:', bin);
|
|
3839
|
+
logger.logger.log('- out:', out);
|
|
3840
|
+
logger.logger.groupEnd();
|
|
3765
3841
|
}
|
|
3766
3842
|
let gradleOpts = [];
|
|
3767
3843
|
if (cli.flags['gradleOpts']) {
|
|
3768
3844
|
gradleOpts = cli.flags['gradleOpts'].split(' ').map(s => s.trim()).filter(Boolean);
|
|
3769
3845
|
}
|
|
3770
3846
|
if (cli.flags['dryRun']) {
|
|
3771
|
-
|
|
3847
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$l);
|
|
3848
|
+
return;
|
|
3772
3849
|
}
|
|
3773
3850
|
await convertGradleToMaven(target, bin, out, verbose, gradleOpts);
|
|
3774
3851
|
}
|
|
@@ -3820,6 +3897,7 @@ async function wrapNpm(argv) {
|
|
|
3820
3897
|
}
|
|
3821
3898
|
|
|
3822
3899
|
const {
|
|
3900
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k,
|
|
3823
3901
|
NPM: NPM$a
|
|
3824
3902
|
} = constants;
|
|
3825
3903
|
const config$k = {
|
|
@@ -3848,7 +3926,8 @@ async function run$k(argv, importMeta, {
|
|
|
3848
3926
|
parentName
|
|
3849
3927
|
});
|
|
3850
3928
|
if (cli.flags['dryRun']) {
|
|
3851
|
-
|
|
3929
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
3930
|
+
return;
|
|
3852
3931
|
}
|
|
3853
3932
|
await wrapNpm(argv);
|
|
3854
3933
|
}
|
|
@@ -3864,6 +3943,7 @@ async function wrapNpx(argv) {
|
|
|
3864
3943
|
}
|
|
3865
3944
|
|
|
3866
3945
|
const {
|
|
3946
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$j,
|
|
3867
3947
|
NPX: NPX$1
|
|
3868
3948
|
} = constants;
|
|
3869
3949
|
const config$j = {
|
|
@@ -3892,11 +3972,15 @@ async function run$j(argv, importMeta, {
|
|
|
3892
3972
|
parentName
|
|
3893
3973
|
});
|
|
3894
3974
|
if (cli.flags['dryRun']) {
|
|
3895
|
-
|
|
3975
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
3976
|
+
return;
|
|
3896
3977
|
}
|
|
3897
3978
|
await wrapNpx(argv);
|
|
3898
3979
|
}
|
|
3899
3980
|
|
|
3981
|
+
const {
|
|
3982
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$i
|
|
3983
|
+
} = constants;
|
|
3900
3984
|
const config$i = {
|
|
3901
3985
|
commandName: 'oops',
|
|
3902
3986
|
description: 'Trigger an intentional error (for development)',
|
|
@@ -3926,7 +4010,8 @@ async function run$i(argv, importMeta, {
|
|
|
3926
4010
|
parentName
|
|
3927
4011
|
});
|
|
3928
4012
|
if (cli.flags['dryRun']) {
|
|
3929
|
-
|
|
4013
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4014
|
+
return;
|
|
3930
4015
|
}
|
|
3931
4016
|
throw new Error('This error was intentionally left blank');
|
|
3932
4017
|
}
|
|
@@ -4637,7 +4722,7 @@ function runAgentInstall(agent, agentExecPath, options) {
|
|
|
4637
4722
|
__proto__: null,
|
|
4638
4723
|
...options
|
|
4639
4724
|
};
|
|
4640
|
-
const isSilent = !
|
|
4725
|
+
const isSilent = !debug.isDebug();
|
|
4641
4726
|
const isSpinning = spinner?.isSpinning ?? false;
|
|
4642
4727
|
if (!isSilent) {
|
|
4643
4728
|
spinner?.stop();
|
|
@@ -4685,7 +4770,8 @@ async function updatePackageLockJson(pkgEnvDetails, options) {
|
|
|
4685
4770
|
logger?.log(`💡 Re-run ${COMMAND_TITLE$1} whenever ${pkgEnvDetails.lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
4686
4771
|
}
|
|
4687
4772
|
} catch (e) {
|
|
4688
|
-
spinner?.
|
|
4773
|
+
spinner?.stop();
|
|
4774
|
+
logger?.error(`${COMMAND_TITLE$1}: ${pkgEnvDetails.agent} install failed to update ${pkgEnvDetails.lockName}`);
|
|
4689
4775
|
logger?.error(e);
|
|
4690
4776
|
}
|
|
4691
4777
|
}
|
|
@@ -4698,44 +4784,44 @@ const {
|
|
|
4698
4784
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
4699
4785
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
4700
4786
|
async function applyOptimization(cwd, pin, prod) {
|
|
4701
|
-
const logger = console;
|
|
4702
4787
|
const pkgEnvDetails = await detectAndValidatePackageEnvironment(cwd, {
|
|
4703
|
-
logger,
|
|
4788
|
+
logger: logger.logger,
|
|
4704
4789
|
prod
|
|
4705
4790
|
});
|
|
4706
4791
|
if (!pkgEnvDetails) {
|
|
4707
4792
|
return;
|
|
4708
4793
|
}
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4794
|
+
// Lazily access constants.spinner.
|
|
4795
|
+
const {
|
|
4796
|
+
spinner
|
|
4797
|
+
} = constants;
|
|
4798
|
+
spinner.start('Socket optimizing...');
|
|
4713
4799
|
const state = await addOverrides(pkgEnvDetails.pkgPath, pkgEnvDetails, {
|
|
4714
|
-
logger,
|
|
4800
|
+
logger: logger.logger,
|
|
4715
4801
|
pin,
|
|
4716
4802
|
prod,
|
|
4717
|
-
spinner
|
|
4803
|
+
spinner
|
|
4718
4804
|
});
|
|
4719
|
-
spinner
|
|
4805
|
+
spinner.stop();
|
|
4720
4806
|
const addedCount = state.added.size;
|
|
4721
4807
|
const updatedCount = state.updated.size;
|
|
4722
4808
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
4723
4809
|
if (pkgJsonChanged) {
|
|
4724
4810
|
if (updatedCount > 0) {
|
|
4725
|
-
logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4811
|
+
logger.logger?.log(`${createActionMessage('Updated', updatedCount, state.updatedInWorkspaces.size)}${addedCount ? '.' : '🚀'}`);
|
|
4726
4812
|
}
|
|
4727
4813
|
if (addedCount > 0) {
|
|
4728
|
-
logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4814
|
+
logger.logger?.log(`${createActionMessage('Added', addedCount, state.addedInWorkspaces.size)} 🚀`);
|
|
4729
4815
|
}
|
|
4730
4816
|
} else {
|
|
4731
|
-
logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4817
|
+
logger.logger?.log('Congratulations! Already Socket.dev optimized 🎉');
|
|
4732
4818
|
}
|
|
4733
4819
|
if (pkgEnvDetails.agent === NPM$1 || pkgJsonChanged) {
|
|
4734
4820
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
4735
4821
|
// https://github.com/npm/cli/pull/8089
|
|
4736
4822
|
await updatePackageLockJson(pkgEnvDetails, {
|
|
4737
|
-
logger,
|
|
4738
|
-
spinner
|
|
4823
|
+
logger: logger.logger,
|
|
4824
|
+
spinner
|
|
4739
4825
|
});
|
|
4740
4826
|
}
|
|
4741
4827
|
}
|
|
@@ -4802,9 +4888,7 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4802
4888
|
} else {
|
|
4803
4889
|
overridesDataObjects.push(overridesDataByAgent.get(NPM$1)(pkgJson), overridesDataByAgent.get(YARN_CLASSIC)(pkgJson));
|
|
4804
4890
|
}
|
|
4805
|
-
|
|
4806
|
-
spinner.text = `Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`;
|
|
4807
|
-
}
|
|
4891
|
+
spinner?.setText(`Adding overrides${workspaceName ? ` to ${workspaceName}` : ''}...`);
|
|
4808
4892
|
const depAliasMap = new Map();
|
|
4809
4893
|
const nodeRange = `>=${pkgEnvDetails.minimumNodeVersion}`;
|
|
4810
4894
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
@@ -4923,6 +5007,9 @@ async function addOverrides(pkgPath, pkgEnvDetails, options) {
|
|
|
4923
5007
|
return state;
|
|
4924
5008
|
}
|
|
4925
5009
|
|
|
5010
|
+
const {
|
|
5011
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
5012
|
+
} = constants;
|
|
4926
5013
|
const config$h = {
|
|
4927
5014
|
commandName: 'optimize',
|
|
4928
5015
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
@@ -4968,7 +5055,8 @@ async function run$h(argv, importMeta, {
|
|
|
4968
5055
|
});
|
|
4969
5056
|
const cwd = process$1.cwd();
|
|
4970
5057
|
if (cli.flags['dryRun']) {
|
|
4971
|
-
|
|
5058
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5059
|
+
return;
|
|
4972
5060
|
}
|
|
4973
5061
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4974
5062
|
}
|
|
@@ -4981,22 +5069,24 @@ async function getOrganization(format = 'text') {
|
|
|
4981
5069
|
await printOrganizationsFromToken(apiToken, format);
|
|
4982
5070
|
}
|
|
4983
5071
|
async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
5072
|
+
// Lazily access constants.spinner.
|
|
5073
|
+
const {
|
|
5074
|
+
spinner
|
|
5075
|
+
} = constants;
|
|
5076
|
+
spinner.start('Fetching organizations...');
|
|
4987
5077
|
const socketSdk = await index.setupSdk(apiToken);
|
|
4988
5078
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4989
5079
|
if (!result.success) {
|
|
4990
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner
|
|
5080
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
4991
5081
|
return;
|
|
4992
5082
|
}
|
|
4993
|
-
spinner
|
|
5083
|
+
spinner.stop();
|
|
4994
5084
|
const organizations = Object.values(result.data.organizations);
|
|
4995
5085
|
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken);
|
|
4996
5086
|
switch (format) {
|
|
4997
5087
|
case 'json':
|
|
4998
5088
|
{
|
|
4999
|
-
|
|
5089
|
+
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
5000
5090
|
name: o.name,
|
|
5001
5091
|
id: o.id,
|
|
5002
5092
|
plan: o.plan
|
|
@@ -5017,27 +5107,30 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
5017
5107
|
mw2 = Math.max(mw2, o.id.length);
|
|
5018
5108
|
mw3 = Math.max(mw3, o.plan.length);
|
|
5019
5109
|
}
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5110
|
+
logger.logger.log('# Organizations\n');
|
|
5111
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5112
|
+
logger.logger.log(`| Name${' '.repeat(mw1 - 4)} | ID${' '.repeat(mw2 - 2)} | Plan${' '.repeat(mw3 - 4)} |`);
|
|
5113
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5024
5114
|
for (const o of organizations) {
|
|
5025
|
-
|
|
5115
|
+
logger.logger.log(`| ${(o.name || '').padEnd(mw1, ' ')} | ${(o.id || '').padEnd(mw2, ' ')} | ${(o.plan || '').padEnd(mw3, ' ')} |`);
|
|
5026
5116
|
}
|
|
5027
|
-
|
|
5117
|
+
logger.logger.log(`| ${'-'.repeat(mw1)} | ${'-'.repeat(mw2)} | ${'-'.repeat(mw3)} |`);
|
|
5028
5118
|
return;
|
|
5029
5119
|
}
|
|
5030
5120
|
default:
|
|
5031
5121
|
{
|
|
5032
|
-
|
|
5122
|
+
logger.logger.log(`List of organizations associated with your API key, ending with: ${colors.italic(lastFiveOfApiToken)}\n`);
|
|
5033
5123
|
// Just dump
|
|
5034
5124
|
for (const o of organizations) {
|
|
5035
|
-
|
|
5125
|
+
logger.logger.log(`- Name: ${colors.bold(o.name)}, ID: ${colors.bold(o.id)}, Plan: ${colors.bold(o.plan)}`);
|
|
5036
5126
|
}
|
|
5037
5127
|
}
|
|
5038
5128
|
}
|
|
5039
5129
|
}
|
|
5040
5130
|
|
|
5131
|
+
const {
|
|
5132
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$g
|
|
5133
|
+
} = constants;
|
|
5041
5134
|
const config$g = {
|
|
5042
5135
|
commandName: 'organizations',
|
|
5043
5136
|
description: 'List organizations associated with the API key used',
|
|
@@ -5075,14 +5168,15 @@ async function run$g(argv, importMeta, {
|
|
|
5075
5168
|
// options or missing arguments.
|
|
5076
5169
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5077
5170
|
process.exitCode = 2;
|
|
5078
|
-
|
|
5171
|
+
logger.logger.error(`
|
|
5079
5172
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5080
5173
|
- The json and markdown flags cannot be both set, pick one
|
|
5081
5174
|
`);
|
|
5082
5175
|
return;
|
|
5083
5176
|
}
|
|
5084
5177
|
if (cli.flags['dryRun']) {
|
|
5085
|
-
|
|
5178
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$g);
|
|
5179
|
+
return;
|
|
5086
5180
|
}
|
|
5087
5181
|
await getOrganization(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
5088
5182
|
}
|
|
@@ -5110,6 +5204,7 @@ async function runRawNpm(argv) {
|
|
|
5110
5204
|
}
|
|
5111
5205
|
|
|
5112
5206
|
const {
|
|
5207
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$f,
|
|
5113
5208
|
NPM
|
|
5114
5209
|
} = constants;
|
|
5115
5210
|
const config$f = {
|
|
@@ -5144,7 +5239,8 @@ async function run$f(argv, importMeta, {
|
|
|
5144
5239
|
parentName
|
|
5145
5240
|
});
|
|
5146
5241
|
if (cli.flags['dryRun']) {
|
|
5147
|
-
|
|
5242
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$f);
|
|
5243
|
+
return;
|
|
5148
5244
|
}
|
|
5149
5245
|
await runRawNpm(argv);
|
|
5150
5246
|
}
|
|
@@ -5172,6 +5268,7 @@ async function runRawNpx(argv) {
|
|
|
5172
5268
|
}
|
|
5173
5269
|
|
|
5174
5270
|
const {
|
|
5271
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$e,
|
|
5175
5272
|
NPX
|
|
5176
5273
|
} = constants;
|
|
5177
5274
|
const config$e = {
|
|
@@ -5206,18 +5303,26 @@ async function run$e(argv, importMeta, {
|
|
|
5206
5303
|
parentName
|
|
5207
5304
|
});
|
|
5208
5305
|
if (cli.flags['dryRun']) {
|
|
5209
|
-
|
|
5306
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$e);
|
|
5307
|
+
return;
|
|
5210
5308
|
}
|
|
5211
5309
|
await runRawNpx(argv);
|
|
5212
5310
|
}
|
|
5213
5311
|
|
|
5312
|
+
const {
|
|
5313
|
+
DRY_RUN_LABEL
|
|
5314
|
+
} = constants;
|
|
5214
5315
|
async function createReport(socketConfig, inputPaths, {
|
|
5215
5316
|
cwd,
|
|
5216
5317
|
dryRun
|
|
5217
5318
|
}) {
|
|
5319
|
+
// Lazily access constants.spinner.
|
|
5320
|
+
const {
|
|
5321
|
+
spinner
|
|
5322
|
+
} = constants;
|
|
5218
5323
|
const socketSdk = await index.setupSdk();
|
|
5219
5324
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
5220
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
5325
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
5221
5326
|
return res.data;
|
|
5222
5327
|
}).catch(cause => {
|
|
5223
5328
|
throw new Error('Failed getting supported files for report', {
|
|
@@ -5225,24 +5330,27 @@ async function createReport(socketConfig, inputPaths, {
|
|
|
5225
5330
|
});
|
|
5226
5331
|
});
|
|
5227
5332
|
const packagePaths = await npmPaths.getPackageFiles(cwd, inputPaths, socketConfig, supportedFiles);
|
|
5228
|
-
|
|
5333
|
+
const {
|
|
5334
|
+
length: packagePathsCount
|
|
5335
|
+
} = packagePaths;
|
|
5336
|
+
if (packagePathsCount && debug.isDebug()) {
|
|
5337
|
+
for (const pkgPath of packagePaths) {
|
|
5338
|
+
debug.debugLog(`Uploading: ${pkgPath}`);
|
|
5339
|
+
}
|
|
5340
|
+
}
|
|
5229
5341
|
if (dryRun) {
|
|
5230
|
-
|
|
5342
|
+
debug.debugLog(`${DRY_RUN_LABEL}: Skipped actual upload`);
|
|
5343
|
+
return undefined;
|
|
5344
|
+
}
|
|
5345
|
+
spinner.start(`Creating report with ${packagePathsCount} package ${words.pluralize('file', packagePathsCount)}`);
|
|
5346
|
+
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5347
|
+
const result = await handleApiCall(apiCall, 'creating report');
|
|
5348
|
+
if (!result.success) {
|
|
5349
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
5231
5350
|
return undefined;
|
|
5232
|
-
} else {
|
|
5233
|
-
const socketSdk = await index.setupSdk();
|
|
5234
|
-
const spinner$1 = new spinner.Spinner({
|
|
5235
|
-
text: `Creating report with ${packagePaths.length} package files`
|
|
5236
|
-
}).start();
|
|
5237
|
-
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, socketConfig?.issueRules);
|
|
5238
|
-
const result = await handleApiCall(apiCall, 'creating report');
|
|
5239
|
-
if (!result.success) {
|
|
5240
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner$1);
|
|
5241
|
-
return undefined;
|
|
5242
|
-
}
|
|
5243
|
-
spinner$1.successAndStop();
|
|
5244
|
-
return result;
|
|
5245
5351
|
}
|
|
5352
|
+
spinner.successAndStop();
|
|
5353
|
+
return result;
|
|
5246
5354
|
}
|
|
5247
5355
|
|
|
5248
5356
|
async function getSocketConfig(absoluteConfigPath) {
|
|
@@ -5269,10 +5377,12 @@ async function getSocketConfig(absoluteConfigPath) {
|
|
|
5269
5377
|
const MAX_TIMEOUT_RETRY = 5;
|
|
5270
5378
|
const HTTP_CODE_TIMEOUT = 524;
|
|
5271
5379
|
async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
5380
|
+
// Lazily access constants.spinner.
|
|
5381
|
+
const {
|
|
5382
|
+
spinner
|
|
5383
|
+
} = constants;
|
|
5384
|
+
spinner.start(`Fetching report with ID ${reportId} (this could take a while)`);
|
|
5272
5385
|
const socketSdk = await index.setupSdk();
|
|
5273
|
-
const spinner$1 = new spinner.Spinner({
|
|
5274
|
-
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
5275
|
-
}).start();
|
|
5276
5386
|
let result;
|
|
5277
5387
|
for (let retry = 1; !result; ++retry) {
|
|
5278
5388
|
try {
|
|
@@ -5280,42 +5390,43 @@ async function fetchReportData(reportId, includeAllIssues, strict) {
|
|
|
5280
5390
|
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
5281
5391
|
} catch (err) {
|
|
5282
5392
|
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof Error) || err.cause?.cause?.response?.statusCode !== HTTP_CODE_TIMEOUT) {
|
|
5393
|
+
spinner.stop();
|
|
5283
5394
|
throw err;
|
|
5284
5395
|
}
|
|
5285
5396
|
}
|
|
5286
5397
|
}
|
|
5287
5398
|
if (!result.success) {
|
|
5288
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner
|
|
5399
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
5289
5400
|
}
|
|
5290
5401
|
|
|
5291
|
-
// Conclude the status of the API call
|
|
5292
|
-
|
|
5402
|
+
// Conclude the status of the API call.
|
|
5293
5403
|
if (strict) {
|
|
5294
5404
|
if (result.data.healthy) {
|
|
5295
|
-
spinner
|
|
5405
|
+
spinner.success('Report result is healthy and great!');
|
|
5296
5406
|
} else {
|
|
5297
|
-
spinner
|
|
5407
|
+
spinner.error('Report result deemed unhealthy for project');
|
|
5298
5408
|
}
|
|
5299
5409
|
} else if (!result.data.healthy) {
|
|
5300
5410
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
5301
5411
|
const issueSummary = formatSeverityCount(severityCount);
|
|
5302
|
-
spinner
|
|
5412
|
+
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
5303
5413
|
} else {
|
|
5304
|
-
spinner
|
|
5414
|
+
spinner.success('Report has no issues');
|
|
5305
5415
|
}
|
|
5416
|
+
spinner.stop();
|
|
5306
5417
|
return result.data;
|
|
5307
5418
|
}
|
|
5308
5419
|
|
|
5309
5420
|
function formatReportDataOutput(reportId, data, commandName, outputJson, outputMarkdown, strict) {
|
|
5310
5421
|
if (outputJson) {
|
|
5311
|
-
|
|
5422
|
+
logger.logger.log(JSON.stringify(data, undefined, 2));
|
|
5312
5423
|
} else {
|
|
5313
5424
|
const format = new index.ColorOrMarkdown(outputMarkdown);
|
|
5314
|
-
|
|
5425
|
+
logger.logger.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
5315
5426
|
fallbackToUrl: true
|
|
5316
5427
|
}));
|
|
5317
5428
|
if (!outputMarkdown) {
|
|
5318
|
-
|
|
5429
|
+
logger.logger.log(colors.dim(`\nOr rerun ${colors.italic(commandName)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
5319
5430
|
}
|
|
5320
5431
|
}
|
|
5321
5432
|
if (strict && !data.healthy) {
|
|
@@ -5336,6 +5447,9 @@ async function viewReport(reportId, {
|
|
|
5336
5447
|
}
|
|
5337
5448
|
}
|
|
5338
5449
|
|
|
5450
|
+
const {
|
|
5451
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$d
|
|
5452
|
+
} = constants;
|
|
5339
5453
|
const config$d = {
|
|
5340
5454
|
commandName: 'create',
|
|
5341
5455
|
description: 'Create a project report',
|
|
@@ -5406,7 +5520,8 @@ async function run$d(argv, importMeta, {
|
|
|
5406
5520
|
|
|
5407
5521
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
5408
5522
|
if (cli.flags['dryRun']) {
|
|
5409
|
-
|
|
5523
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$d);
|
|
5524
|
+
return;
|
|
5410
5525
|
}
|
|
5411
5526
|
const socketConfig = await getSocketConfig(absoluteConfigPath);
|
|
5412
5527
|
const result = await createReport(socketConfig, cli.input, {
|
|
@@ -5425,17 +5540,19 @@ async function run$d(argv, importMeta, {
|
|
|
5425
5540
|
strict
|
|
5426
5541
|
});
|
|
5427
5542
|
} else if (json) {
|
|
5428
|
-
|
|
5429
|
-
return;
|
|
5543
|
+
logger.logger.log(JSON.stringify(result.data, undefined, 2));
|
|
5430
5544
|
} else {
|
|
5431
5545
|
const format = new index.ColorOrMarkdown(markdown);
|
|
5432
|
-
|
|
5546
|
+
logger.logger.log(`New report: ${format.hyperlink(result.data.id, result.data.url, {
|
|
5433
5547
|
fallbackToUrl: true
|
|
5434
5548
|
})}`);
|
|
5435
5549
|
}
|
|
5436
5550
|
}
|
|
5437
5551
|
}
|
|
5438
5552
|
|
|
5553
|
+
const {
|
|
5554
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$c
|
|
5555
|
+
} = constants;
|
|
5439
5556
|
const config$c = {
|
|
5440
5557
|
commandName: 'view',
|
|
5441
5558
|
description: 'View a project report',
|
|
@@ -5478,13 +5595,14 @@ async function run$c(argv, importMeta, {
|
|
|
5478
5595
|
// options or missing arguments.
|
|
5479
5596
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5480
5597
|
process.exitCode = 2;
|
|
5481
|
-
|
|
5598
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5482
5599
|
- Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5483
5600
|
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`);
|
|
5484
5601
|
return;
|
|
5485
5602
|
}
|
|
5486
5603
|
if (cli.flags['dryRun']) {
|
|
5487
|
-
|
|
5604
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5605
|
+
return;
|
|
5488
5606
|
}
|
|
5489
5607
|
await viewReport(reportId, {
|
|
5490
5608
|
all: Boolean(cli.flags['all']),
|
|
@@ -5524,10 +5642,11 @@ async function createRepo({
|
|
|
5524
5642
|
repoName,
|
|
5525
5643
|
visibility
|
|
5526
5644
|
}) {
|
|
5527
|
-
|
|
5528
|
-
const
|
|
5529
|
-
|
|
5530
|
-
}
|
|
5645
|
+
// Lazily access constants.spinner.
|
|
5646
|
+
const {
|
|
5647
|
+
spinner
|
|
5648
|
+
} = constants;
|
|
5649
|
+
spinner.start('Creating repository...');
|
|
5531
5650
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5532
5651
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5533
5652
|
outputJson,
|
|
@@ -5540,12 +5659,15 @@ async function createRepo({
|
|
|
5540
5659
|
visibility
|
|
5541
5660
|
}), 'creating repository');
|
|
5542
5661
|
if (result.success) {
|
|
5543
|
-
spinner
|
|
5662
|
+
spinner.successAndStop('Repository created successfully');
|
|
5544
5663
|
} else {
|
|
5545
|
-
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner
|
|
5664
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
5546
5665
|
}
|
|
5547
5666
|
}
|
|
5548
5667
|
|
|
5668
|
+
const {
|
|
5669
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$b
|
|
5670
|
+
} = constants;
|
|
5549
5671
|
const config$b = {
|
|
5550
5672
|
commandName: 'create',
|
|
5551
5673
|
description: 'Create a repository in an organization',
|
|
@@ -5616,13 +5738,14 @@ async function run$b(argv, importMeta, {
|
|
|
5616
5738
|
// options or missing arguments.
|
|
5617
5739
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5618
5740
|
process.exitCode = 2;
|
|
5619
|
-
|
|
5741
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5620
5742
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5621
5743
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
5622
5744
|
return;
|
|
5623
5745
|
}
|
|
5624
5746
|
if (cli.flags['dryRun']) {
|
|
5625
|
-
|
|
5747
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5748
|
+
return;
|
|
5626
5749
|
}
|
|
5627
5750
|
const apiToken = index.getDefaultToken();
|
|
5628
5751
|
if (!apiToken) {
|
|
@@ -5642,19 +5765,23 @@ async function run$b(argv, importMeta, {
|
|
|
5642
5765
|
}
|
|
5643
5766
|
|
|
5644
5767
|
async function deleteRepo(orgSlug, repoName, apiToken) {
|
|
5645
|
-
|
|
5646
|
-
const
|
|
5647
|
-
|
|
5648
|
-
}
|
|
5768
|
+
// Lazily access constants.spinner.
|
|
5769
|
+
const {
|
|
5770
|
+
spinner
|
|
5771
|
+
} = constants;
|
|
5772
|
+
spinner.start('Deleting repository...');
|
|
5649
5773
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5650
5774
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
5651
5775
|
if (result.success) {
|
|
5652
|
-
spinner
|
|
5776
|
+
spinner.successAndStop('Repository deleted successfully');
|
|
5653
5777
|
} else {
|
|
5654
|
-
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner
|
|
5778
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
5655
5779
|
}
|
|
5656
5780
|
}
|
|
5657
5781
|
|
|
5782
|
+
const {
|
|
5783
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$a
|
|
5784
|
+
} = constants;
|
|
5658
5785
|
const config$a = {
|
|
5659
5786
|
commandName: 'del',
|
|
5660
5787
|
description: 'Delete a repository in an organization',
|
|
@@ -5693,14 +5820,15 @@ async function run$a(argv, importMeta, {
|
|
|
5693
5820
|
// options or missing arguments.
|
|
5694
5821
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5695
5822
|
process.exitCode = 2;
|
|
5696
|
-
|
|
5823
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5697
5824
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5698
5825
|
- Repository name as the second argument ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5699
5826
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5700
5827
|
return;
|
|
5701
5828
|
}
|
|
5702
5829
|
if (cli.flags['dryRun']) {
|
|
5703
|
-
|
|
5830
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5831
|
+
return;
|
|
5704
5832
|
}
|
|
5705
5833
|
const apiToken = index.getDefaultToken();
|
|
5706
5834
|
if (!apiToken) {
|
|
@@ -5720,10 +5848,11 @@ async function listRepos({
|
|
|
5720
5848
|
per_page,
|
|
5721
5849
|
sort
|
|
5722
5850
|
}) {
|
|
5723
|
-
|
|
5724
|
-
const
|
|
5725
|
-
|
|
5726
|
-
}
|
|
5851
|
+
// Lazily access constants.spinner.
|
|
5852
|
+
const {
|
|
5853
|
+
spinner
|
|
5854
|
+
} = constants;
|
|
5855
|
+
spinner.start('Listing repositories...');
|
|
5727
5856
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5728
5857
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5729
5858
|
outputJson,
|
|
@@ -5735,10 +5864,10 @@ async function listRepos({
|
|
|
5735
5864
|
page
|
|
5736
5865
|
}), 'listing repositories');
|
|
5737
5866
|
if (!result.success) {
|
|
5738
|
-
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner
|
|
5867
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
5739
5868
|
return;
|
|
5740
5869
|
}
|
|
5741
|
-
spinner
|
|
5870
|
+
spinner.stop();
|
|
5742
5871
|
if (outputJson) {
|
|
5743
5872
|
const data = result.data.results.map(o => ({
|
|
5744
5873
|
id: o.id,
|
|
@@ -5747,7 +5876,7 @@ async function listRepos({
|
|
|
5747
5876
|
defaultBranch: o.default_branch,
|
|
5748
5877
|
archived: o.archived
|
|
5749
5878
|
}));
|
|
5750
|
-
|
|
5879
|
+
logger.logger.log(JSON.stringify(data, null, 2));
|
|
5751
5880
|
return;
|
|
5752
5881
|
}
|
|
5753
5882
|
const options = {
|
|
@@ -5768,9 +5897,12 @@ async function listRepos({
|
|
|
5768
5897
|
name: colors.magenta('Archived')
|
|
5769
5898
|
}]
|
|
5770
5899
|
};
|
|
5771
|
-
|
|
5900
|
+
logger.logger.log(chalkTable(options, result.data.results));
|
|
5772
5901
|
}
|
|
5773
5902
|
|
|
5903
|
+
const {
|
|
5904
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$9
|
|
5905
|
+
} = constants;
|
|
5774
5906
|
const config$9 = {
|
|
5775
5907
|
commandName: 'list',
|
|
5776
5908
|
description: 'List repositories in an organization',
|
|
@@ -5833,13 +5965,14 @@ async function run$9(argv, importMeta, {
|
|
|
5833
5965
|
// options or missing arguments.
|
|
5834
5966
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5835
5967
|
process.exitCode = 2;
|
|
5836
|
-
|
|
5968
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5837
5969
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5838
5970
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5839
5971
|
return;
|
|
5840
5972
|
}
|
|
5841
5973
|
if (cli.flags['dryRun']) {
|
|
5842
|
-
|
|
5974
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
5975
|
+
return;
|
|
5843
5976
|
}
|
|
5844
5977
|
const apiToken = index.getDefaultToken();
|
|
5845
5978
|
if (!apiToken) {
|
|
@@ -5868,10 +6001,11 @@ async function updateRepo({
|
|
|
5868
6001
|
repoName,
|
|
5869
6002
|
visibility
|
|
5870
6003
|
}) {
|
|
5871
|
-
|
|
5872
|
-
const
|
|
5873
|
-
|
|
5874
|
-
}
|
|
6004
|
+
// Lazily access constants.spinner.
|
|
6005
|
+
const {
|
|
6006
|
+
spinner
|
|
6007
|
+
} = constants;
|
|
6008
|
+
spinner.start('Updating repository...');
|
|
5875
6009
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5876
6010
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5877
6011
|
outputJson,
|
|
@@ -5884,12 +6018,15 @@ async function updateRepo({
|
|
|
5884
6018
|
visibility
|
|
5885
6019
|
}), 'updating repository');
|
|
5886
6020
|
if (result.success) {
|
|
5887
|
-
spinner
|
|
6021
|
+
spinner.successAndStop('Repository updated successfully');
|
|
5888
6022
|
} else {
|
|
5889
|
-
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner
|
|
6023
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
5890
6024
|
}
|
|
5891
6025
|
}
|
|
5892
6026
|
|
|
6027
|
+
const {
|
|
6028
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$8
|
|
6029
|
+
} = constants;
|
|
5893
6030
|
const config$8 = {
|
|
5894
6031
|
commandName: 'update',
|
|
5895
6032
|
description: 'Update a repository in an organization',
|
|
@@ -5960,14 +6097,15 @@ async function run$8(argv, importMeta, {
|
|
|
5960
6097
|
// options or missing arguments.
|
|
5961
6098
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
5962
6099
|
process.exitCode = 2;
|
|
5963
|
-
|
|
6100
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
5964
6101
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
5965
6102
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
|
|
5966
6103
|
- At least one TARGET (e.g. \`.\` or \`./package.json\`\n`);
|
|
5967
6104
|
return;
|
|
5968
6105
|
}
|
|
5969
6106
|
if (cli.flags['dryRun']) {
|
|
5970
|
-
|
|
6107
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6108
|
+
return;
|
|
5971
6109
|
}
|
|
5972
6110
|
const apiToken = index.getDefaultToken();
|
|
5973
6111
|
if (!apiToken) {
|
|
@@ -5988,14 +6126,15 @@ async function run$8(argv, importMeta, {
|
|
|
5988
6126
|
|
|
5989
6127
|
// @ts-ignore
|
|
5990
6128
|
async function viewRepo(orgSlug, repoName, apiToken) {
|
|
5991
|
-
|
|
5992
|
-
const
|
|
5993
|
-
|
|
5994
|
-
}
|
|
6129
|
+
// Lazily access constants.spinner.
|
|
6130
|
+
const {
|
|
6131
|
+
spinner
|
|
6132
|
+
} = constants;
|
|
6133
|
+
spinner.start('Fetching repository...');
|
|
5995
6134
|
const socketSdk = await index.setupSdk(apiToken);
|
|
5996
6135
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
5997
6136
|
if (!result.success) {
|
|
5998
|
-
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner
|
|
6137
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
5999
6138
|
return;
|
|
6000
6139
|
}
|
|
6001
6140
|
const options = {
|
|
@@ -6022,9 +6161,12 @@ async function viewRepo(orgSlug, repoName, apiToken) {
|
|
|
6022
6161
|
name: colors.magenta('Created at')
|
|
6023
6162
|
}]
|
|
6024
6163
|
};
|
|
6025
|
-
spinner
|
|
6164
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
6026
6165
|
}
|
|
6027
6166
|
|
|
6167
|
+
const {
|
|
6168
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$7
|
|
6169
|
+
} = constants;
|
|
6028
6170
|
const config$7 = {
|
|
6029
6171
|
commandName: 'view',
|
|
6030
6172
|
description: 'View repositories in an organization',
|
|
@@ -6065,13 +6207,14 @@ async function run$7(argv, importMeta, {
|
|
|
6065
6207
|
// options or missing arguments.
|
|
6066
6208
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6067
6209
|
process.exitCode = 2;
|
|
6068
|
-
|
|
6210
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6069
6211
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6070
6212
|
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`);
|
|
6071
6213
|
return;
|
|
6072
6214
|
}
|
|
6073
6215
|
if (cli.flags['dryRun']) {
|
|
6074
|
-
|
|
6216
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$7);
|
|
6217
|
+
return;
|
|
6075
6218
|
}
|
|
6076
6219
|
const apiToken = index.getDefaultToken();
|
|
6077
6220
|
if (!apiToken) {
|
|
@@ -6200,7 +6343,7 @@ function dirNameToSlug(name) {
|
|
|
6200
6343
|
async function suggestBranchSlug(repoDefaultBranch) {
|
|
6201
6344
|
const spawnResult = childProcess.spawnSync('git', ['branch', '--show-current']);
|
|
6202
6345
|
const currentBranch = spawnResult.stdout.toString('utf8').trim();
|
|
6203
|
-
if (spawnResult.status === 0
|
|
6346
|
+
if (currentBranch && spawnResult.status === 0) {
|
|
6204
6347
|
const proceed = await prompts.select({
|
|
6205
6348
|
message: 'Use the current git branch as target branch name?',
|
|
6206
6349
|
choices: [{
|
|
@@ -6258,10 +6401,14 @@ async function createFullScan({
|
|
|
6258
6401
|
targets,
|
|
6259
6402
|
tmp
|
|
6260
6403
|
}) {
|
|
6404
|
+
// Lazily access constants.spinner.
|
|
6405
|
+
const {
|
|
6406
|
+
spinner
|
|
6407
|
+
} = constants;
|
|
6261
6408
|
const socketSdk = await index.setupSdk();
|
|
6262
6409
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
6263
6410
|
if (!res.success) {
|
|
6264
|
-
handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
6411
|
+
handleUnsuccessfulApiResponse('getReportSupportedFiles', res, spinner);
|
|
6265
6412
|
assert(false, 'handleUnsuccessfulApiResponse should unconditionally throw');
|
|
6266
6413
|
}
|
|
6267
6414
|
return res.data;
|
|
@@ -6318,7 +6465,7 @@ async function createFullScan({
|
|
|
6318
6465
|
// options or missing arguments.
|
|
6319
6466
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6320
6467
|
process$1.exitCode = 2;
|
|
6321
|
-
|
|
6468
|
+
logger.logger.error(`
|
|
6322
6469
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6323
6470
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6324
6471
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6329,22 +6476,19 @@ async function createFullScan({
|
|
|
6329
6476
|
return;
|
|
6330
6477
|
}
|
|
6331
6478
|
if (updatedInput) {
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6479
|
+
logger.logger.log('Note: You can invoke this command next time to skip the interactive questions:');
|
|
6480
|
+
logger.logger.log('```');
|
|
6481
|
+
logger.logger.log(` socket scan create [other flags...] --repo ${repoName} --branch ${branchName} ${orgSlug} ${targets.join(' ')}`);
|
|
6482
|
+
logger.logger.log('```');
|
|
6336
6483
|
}
|
|
6337
6484
|
if (!apiToken) {
|
|
6338
6485
|
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.');
|
|
6339
6486
|
}
|
|
6340
6487
|
if (readOnly) {
|
|
6341
|
-
|
|
6488
|
+
logger.logger.log('[ReadOnly] Bailing now');
|
|
6342
6489
|
return;
|
|
6343
6490
|
}
|
|
6344
|
-
|
|
6345
|
-
const spinner$1 = new spinner.Spinner({
|
|
6346
|
-
text: spinnerText
|
|
6347
|
-
}).start();
|
|
6491
|
+
spinner.start('Creating a scan...');
|
|
6348
6492
|
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
6349
6493
|
repo: repoName,
|
|
6350
6494
|
branch: branchName,
|
|
@@ -6354,12 +6498,12 @@ async function createFullScan({
|
|
|
6354
6498
|
tmp
|
|
6355
6499
|
}, packagePaths, cwd), 'Creating scan');
|
|
6356
6500
|
if (!result.success) {
|
|
6357
|
-
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner
|
|
6501
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
6358
6502
|
return;
|
|
6359
6503
|
}
|
|
6360
|
-
spinner
|
|
6504
|
+
spinner.successAndStop('Scan created successfully');
|
|
6361
6505
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
6362
|
-
|
|
6506
|
+
logger.logger.log(`Available at: ${link}`);
|
|
6363
6507
|
const rl = readline.createInterface({
|
|
6364
6508
|
input: process$1.stdin,
|
|
6365
6509
|
output: process$1.stdout
|
|
@@ -6371,6 +6515,9 @@ async function createFullScan({
|
|
|
6371
6515
|
rl.close();
|
|
6372
6516
|
}
|
|
6373
6517
|
|
|
6518
|
+
const {
|
|
6519
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$6
|
|
6520
|
+
} = constants;
|
|
6374
6521
|
const config$6 = {
|
|
6375
6522
|
commandName: 'create',
|
|
6376
6523
|
description: 'Create a scan',
|
|
@@ -6487,7 +6634,7 @@ async function run$6(argv, importMeta, {
|
|
|
6487
6634
|
// options or missing arguments.
|
|
6488
6635
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6489
6636
|
process$1.exitCode = 2;
|
|
6490
|
-
|
|
6637
|
+
logger.logger.error(`
|
|
6491
6638
|
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6492
6639
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6493
6640
|
- Repository name using --repo ${!repoName ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
@@ -6500,7 +6647,8 @@ async function run$6(argv, importMeta, {
|
|
|
6500
6647
|
|
|
6501
6648
|
// Note exiting earlier to skirt a hidden auth requirement
|
|
6502
6649
|
if (cli.flags['dryRun']) {
|
|
6503
|
-
|
|
6650
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$6);
|
|
6651
|
+
return;
|
|
6504
6652
|
}
|
|
6505
6653
|
await createFullScan({
|
|
6506
6654
|
branchName: branchName,
|
|
@@ -6520,19 +6668,23 @@ async function run$6(argv, importMeta, {
|
|
|
6520
6668
|
}
|
|
6521
6669
|
|
|
6522
6670
|
async function deleteOrgFullScan(orgSlug, fullScanId, apiToken) {
|
|
6523
|
-
|
|
6524
|
-
const
|
|
6525
|
-
|
|
6526
|
-
}
|
|
6671
|
+
// Lazily access constants.spinner.
|
|
6672
|
+
const {
|
|
6673
|
+
spinner
|
|
6674
|
+
} = constants;
|
|
6675
|
+
spinner.start('Deleting scan...');
|
|
6527
6676
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6528
6677
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
6529
|
-
if (result.success) {
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner$1);
|
|
6678
|
+
if (!result.success) {
|
|
6679
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
6680
|
+
return;
|
|
6533
6681
|
}
|
|
6682
|
+
spinner.successAndStop('Scan deleted successfully');
|
|
6534
6683
|
}
|
|
6535
6684
|
|
|
6685
|
+
const {
|
|
6686
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$5
|
|
6687
|
+
} = constants;
|
|
6536
6688
|
const config$5 = {
|
|
6537
6689
|
commandName: 'del',
|
|
6538
6690
|
description: 'Delete a scan',
|
|
@@ -6572,13 +6724,14 @@ async function run$5(argv, importMeta, {
|
|
|
6572
6724
|
// options or missing arguments.
|
|
6573
6725
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6574
6726
|
process.exitCode = 2;
|
|
6575
|
-
|
|
6727
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6576
6728
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6577
6729
|
- Full Scan ID to delete as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6578
6730
|
return;
|
|
6579
6731
|
}
|
|
6580
6732
|
if (cli.flags['dryRun']) {
|
|
6581
|
-
|
|
6733
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$5);
|
|
6734
|
+
return;
|
|
6582
6735
|
}
|
|
6583
6736
|
const apiToken = index.getDefaultToken();
|
|
6584
6737
|
if (!apiToken) {
|
|
@@ -6589,14 +6742,15 @@ async function run$5(argv, importMeta, {
|
|
|
6589
6742
|
|
|
6590
6743
|
// @ts-ignore
|
|
6591
6744
|
async function listFullScans(orgSlug, input, apiToken) {
|
|
6592
|
-
|
|
6593
|
-
const
|
|
6594
|
-
|
|
6595
|
-
}
|
|
6745
|
+
// Lazily access constants.spinner.
|
|
6746
|
+
const {
|
|
6747
|
+
spinner
|
|
6748
|
+
} = constants;
|
|
6749
|
+
spinner.start('Listing scans...');
|
|
6596
6750
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6597
6751
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
6598
6752
|
if (!result.success) {
|
|
6599
|
-
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner
|
|
6753
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
6600
6754
|
return;
|
|
6601
6755
|
}
|
|
6602
6756
|
const options = {
|
|
@@ -6626,10 +6780,13 @@ async function listFullScans(orgSlug, input, apiToken) {
|
|
|
6626
6780
|
branch: d.branch
|
|
6627
6781
|
};
|
|
6628
6782
|
});
|
|
6629
|
-
spinner
|
|
6630
|
-
|
|
6783
|
+
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
6784
|
+
logger.logger.log(chalkTable(options, formattedResults));
|
|
6631
6785
|
}
|
|
6632
6786
|
|
|
6787
|
+
const {
|
|
6788
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$4
|
|
6789
|
+
} = constants;
|
|
6633
6790
|
const config$4 = {
|
|
6634
6791
|
commandName: 'list',
|
|
6635
6792
|
description: 'List the full scans for an organization',
|
|
@@ -6705,12 +6862,13 @@ async function run$4(argv, importMeta, {
|
|
|
6705
6862
|
// options or missing arguments.
|
|
6706
6863
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6707
6864
|
process.exitCode = 2;
|
|
6708
|
-
|
|
6865
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6709
6866
|
- Org name as the argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6710
6867
|
return;
|
|
6711
6868
|
}
|
|
6712
6869
|
if (cli.flags['dryRun']) {
|
|
6713
|
-
|
|
6870
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$4);
|
|
6871
|
+
return;
|
|
6714
6872
|
}
|
|
6715
6873
|
const apiToken = index.getDefaultToken();
|
|
6716
6874
|
if (!apiToken) {
|
|
@@ -6732,20 +6890,24 @@ async function run$4(argv, importMeta, {
|
|
|
6732
6890
|
}
|
|
6733
6891
|
|
|
6734
6892
|
async function getOrgScanMetadata(orgSlug, scanId, apiToken) {
|
|
6735
|
-
|
|
6736
|
-
const
|
|
6737
|
-
|
|
6738
|
-
}
|
|
6893
|
+
// Lazily access constants.spinner.
|
|
6894
|
+
const {
|
|
6895
|
+
spinner
|
|
6896
|
+
} = constants;
|
|
6897
|
+
spinner.start("Getting scan's metadata...");
|
|
6739
6898
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6740
6899
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
6741
6900
|
if (!result.success) {
|
|
6742
|
-
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner
|
|
6901
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
6743
6902
|
return;
|
|
6744
6903
|
}
|
|
6745
|
-
spinner
|
|
6746
|
-
|
|
6904
|
+
spinner.stop('Scan metadata:');
|
|
6905
|
+
logger.logger.log(result.data);
|
|
6747
6906
|
}
|
|
6748
6907
|
|
|
6908
|
+
const {
|
|
6909
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$3
|
|
6910
|
+
} = constants;
|
|
6749
6911
|
const config$3 = {
|
|
6750
6912
|
commandName: 'metadata',
|
|
6751
6913
|
description: "Get a full scan's metadata",
|
|
@@ -6785,13 +6947,14 @@ async function run$3(argv, importMeta, {
|
|
|
6785
6947
|
// options or missing arguments.
|
|
6786
6948
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6787
6949
|
process.exitCode = 2;
|
|
6788
|
-
|
|
6950
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6789
6951
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6790
6952
|
- Full Scan ID to inspect as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6791
6953
|
return;
|
|
6792
6954
|
}
|
|
6793
6955
|
if (cli.flags['dryRun']) {
|
|
6794
|
-
|
|
6956
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$3);
|
|
6957
|
+
return;
|
|
6795
6958
|
}
|
|
6796
6959
|
const apiToken = index.getDefaultToken();
|
|
6797
6960
|
if (!apiToken) {
|
|
@@ -6801,19 +6964,24 @@ async function run$3(argv, importMeta, {
|
|
|
6801
6964
|
}
|
|
6802
6965
|
|
|
6803
6966
|
async function getFullScan(orgSlug, fullScanId, file, apiToken) {
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6967
|
+
// Lazily access constants.spinner.
|
|
6968
|
+
const {
|
|
6969
|
+
spinner
|
|
6970
|
+
} = constants;
|
|
6971
|
+
spinner.start('Streaming scan...');
|
|
6807
6972
|
const socketSdk = await index.setupSdk(apiToken);
|
|
6808
6973
|
const data = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file === '-' ? undefined : file), 'Streaming a scan');
|
|
6809
6974
|
if (data?.success) {
|
|
6810
|
-
spinner
|
|
6975
|
+
spinner.stop(file ? `Full scan details written to ${file}` : '');
|
|
6811
6976
|
} else {
|
|
6812
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner
|
|
6977
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', data, spinner);
|
|
6813
6978
|
}
|
|
6814
6979
|
return data;
|
|
6815
6980
|
}
|
|
6816
6981
|
|
|
6982
|
+
const {
|
|
6983
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$2
|
|
6984
|
+
} = constants;
|
|
6817
6985
|
const config$2 = {
|
|
6818
6986
|
commandName: 'stream',
|
|
6819
6987
|
description: 'Stream the output of a scan',
|
|
@@ -6855,13 +7023,14 @@ async function run$2(argv, importMeta, {
|
|
|
6855
7023
|
// options or missing arguments.
|
|
6856
7024
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
6857
7025
|
process.exitCode = 2;
|
|
6858
|
-
|
|
7026
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
6859
7027
|
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
|
|
6860
7028
|
- Full Scan ID to fetch as second argument ${!fullScanId ? colors.red('(missing!)') : colors.green('(ok)')}\n`);
|
|
6861
7029
|
return;
|
|
6862
7030
|
}
|
|
6863
7031
|
if (cli.flags['dryRun']) {
|
|
6864
|
-
|
|
7032
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$2);
|
|
7033
|
+
return;
|
|
6865
7034
|
}
|
|
6866
7035
|
const apiToken = index.getDefaultToken();
|
|
6867
7036
|
if (!apiToken) {
|
|
@@ -6899,9 +7068,11 @@ async function getThreatFeed({
|
|
|
6899
7068
|
page,
|
|
6900
7069
|
perPage
|
|
6901
7070
|
}) {
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
7071
|
+
// Lazily access constants.spinner.
|
|
7072
|
+
const {
|
|
7073
|
+
spinner
|
|
7074
|
+
} = constants;
|
|
7075
|
+
spinner.start('Looking up the threat feed');
|
|
6905
7076
|
const formattedQueryParams = formatQueryParams({
|
|
6906
7077
|
per_page: perPage,
|
|
6907
7078
|
page,
|
|
@@ -6910,9 +7081,9 @@ async function getThreatFeed({
|
|
|
6910
7081
|
}).join('&');
|
|
6911
7082
|
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiToken);
|
|
6912
7083
|
const data = await response.json();
|
|
6913
|
-
spinner
|
|
7084
|
+
spinner.stop();
|
|
6914
7085
|
if (outputJson) {
|
|
6915
|
-
|
|
7086
|
+
logger.logger.log(data);
|
|
6916
7087
|
return;
|
|
6917
7088
|
}
|
|
6918
7089
|
const screen = new ScreenWidget();
|
|
@@ -6967,6 +7138,9 @@ function getMinDiff(start, end) {
|
|
|
6967
7138
|
return Math.floor((end - start) / 60000);
|
|
6968
7139
|
}
|
|
6969
7140
|
|
|
7141
|
+
const {
|
|
7142
|
+
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$1
|
|
7143
|
+
} = constants;
|
|
6970
7144
|
const config$1 = {
|
|
6971
7145
|
commandName: 'threat-feed',
|
|
6972
7146
|
description: 'Look up the threat feed',
|
|
@@ -7026,7 +7200,8 @@ async function run$1(argv, importMeta, {
|
|
|
7026
7200
|
parentName
|
|
7027
7201
|
});
|
|
7028
7202
|
if (cli.flags['dryRun']) {
|
|
7029
|
-
|
|
7203
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT$1);
|
|
7204
|
+
return;
|
|
7030
7205
|
}
|
|
7031
7206
|
const apiToken = index.getDefaultToken();
|
|
7032
7207
|
if (!apiToken) {
|
|
@@ -7049,7 +7224,7 @@ function addSocketWrapper(file) {
|
|
|
7049
7224
|
}
|
|
7050
7225
|
// TODO: pretty sure you need to source the file or restart
|
|
7051
7226
|
// any terminal session before changes are reflected.
|
|
7052
|
-
|
|
7227
|
+
logger.logger.log(`
|
|
7053
7228
|
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
7054
7229
|
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
7055
7230
|
`);
|
|
@@ -7060,7 +7235,7 @@ function checkSocketWrapperSetup(file) {
|
|
|
7060
7235
|
const fileContent = fs.readFileSync(file, 'utf8');
|
|
7061
7236
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
7062
7237
|
if (linesWithSocketAlias.length) {
|
|
7063
|
-
|
|
7238
|
+
logger.logger.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
7064
7239
|
return true;
|
|
7065
7240
|
}
|
|
7066
7241
|
return false;
|
|
@@ -7082,7 +7257,7 @@ function postinstallWrapper() {
|
|
|
7082
7257
|
}
|
|
7083
7258
|
}
|
|
7084
7259
|
function installSafeNpm(query) {
|
|
7085
|
-
|
|
7260
|
+
logger.logger.log(`
|
|
7086
7261
|
_____ _ _
|
|
7087
7262
|
| __|___ ___| |_ ___| |_
|
|
7088
7263
|
|__ | . | _| '_| -_| _|
|
|
@@ -7125,24 +7300,27 @@ function askQuestion(rl, query) {
|
|
|
7125
7300
|
function removeSocketWrapper(file) {
|
|
7126
7301
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
7127
7302
|
if (err) {
|
|
7128
|
-
|
|
7303
|
+
logger.logger.error('There was an error removing the alias:');
|
|
7304
|
+
logger.logger.error(err);
|
|
7129
7305
|
return;
|
|
7130
7306
|
}
|
|
7131
7307
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
7132
7308
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
7133
7309
|
fs.writeFile(file, updatedFileContent, function (err) {
|
|
7134
7310
|
if (err) {
|
|
7135
|
-
|
|
7311
|
+
logger.logger.error(err);
|
|
7136
7312
|
return;
|
|
7137
|
-
} else {
|
|
7138
|
-
// TODO: pretty sure you need to source the file or restart
|
|
7139
|
-
// any terminal session before changes are reflected.
|
|
7140
|
-
console.log(`\nThe alias was removed from ${file}. Running 'npm install' will now run the standard npm command.\n`);
|
|
7141
7313
|
}
|
|
7314
|
+
// TODO: pretty sure you need to source the file or restart
|
|
7315
|
+
// any terminal session before changes are reflected.
|
|
7316
|
+
logger.logger.log(`The alias was removed from ${file}. Running 'npm install' will now run the standard npm command.`);
|
|
7142
7317
|
});
|
|
7143
7318
|
});
|
|
7144
7319
|
}
|
|
7145
7320
|
|
|
7321
|
+
const {
|
|
7322
|
+
DRY_RUN_BAIL_TEXT
|
|
7323
|
+
} = constants;
|
|
7146
7324
|
const config = {
|
|
7147
7325
|
commandName: 'wrapper',
|
|
7148
7326
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
@@ -7199,12 +7377,13 @@ async function run(argv, importMeta, {
|
|
|
7199
7377
|
// options or missing arguments.
|
|
7200
7378
|
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
|
|
7201
7379
|
process.exitCode = 2;
|
|
7202
|
-
|
|
7380
|
+
logger.logger.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required flags:\n
|
|
7203
7381
|
- Must use --enabled or --disabled\n`);
|
|
7204
7382
|
return;
|
|
7205
7383
|
}
|
|
7206
7384
|
if (cli.flags['dryRun']) {
|
|
7207
|
-
|
|
7385
|
+
logger.logger.log(DRY_RUN_BAIL_TEXT);
|
|
7386
|
+
return;
|
|
7208
7387
|
}
|
|
7209
7388
|
|
|
7210
7389
|
// Lazily access constants.bashRcPath and constants.zshRcPath.
|
|
@@ -7228,7 +7407,7 @@ async function run(argv, importMeta, {
|
|
|
7228
7407
|
}
|
|
7229
7408
|
}
|
|
7230
7409
|
if (!fs.existsSync(bashRcPath) && !fs.existsSync(zshRcPath)) {
|
|
7231
|
-
|
|
7410
|
+
logger.logger.error('There was an issue setting up the alias in your bash profile');
|
|
7232
7411
|
}
|
|
7233
7412
|
}
|
|
7234
7413
|
|
|
@@ -7301,12 +7480,12 @@ void (async () => {
|
|
|
7301
7480
|
} else {
|
|
7302
7481
|
errorTitle = 'Unexpected error with no details';
|
|
7303
7482
|
}
|
|
7304
|
-
|
|
7483
|
+
logger.logger.error(`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
7305
7484
|
if (errorBody) {
|
|
7306
|
-
|
|
7485
|
+
logger.logger.error(`\n${errorBody}`);
|
|
7307
7486
|
}
|
|
7308
7487
|
await index.captureException(e);
|
|
7309
7488
|
}
|
|
7310
7489
|
})();
|
|
7311
|
-
//# debugId=
|
|
7490
|
+
//# debugId=58e6ceed-07a5-4b32-b0e9-9fef0ceef6d7
|
|
7312
7491
|
//# sourceMappingURL=cli.js.map
|