@socketsecurity/cli 0.11.0 → 0.12.0
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/README.md +22 -22
- package/bin/npm +2 -0
- package/bin/npx +2 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3928 -0
- package/dist/errors.d.ts +7 -0
- package/dist/link.d.ts +2 -0
- package/dist/link.js +45 -0
- package/dist/npm-cli.d.ts +2 -0
- package/dist/npm-cli.js +84 -0
- package/dist/npm-injection.d.ts +1 -0
- package/dist/npm-injection.js +913 -0
- package/dist/npm-injection2.d.ts +25 -0
- package/dist/npm-injection2.js +899 -0
- package/dist/npx-cli.d.ts +2 -0
- package/dist/npx-cli.js +60 -0
- package/dist/path-resolve.d.ts +12 -0
- package/dist/path-resolve.js +139 -0
- package/dist/sdk.d.ts +27 -0
- package/dist/sdk.js +224 -0
- package/dist/settings.d.ts +9 -0
- package/dist/type-helpers.d.ts +3 -0
- package/dist/vendor.js +25421 -0
- package/package.json +108 -52
- package/{lib/shadow/translations.json → translations.json} +20 -20
- package/cli.js +0 -72
- package/lib/commands/audit-log/index.js +0 -162
- package/lib/commands/cdxgen/index.js +0 -211
- package/lib/commands/dependencies/index.js +0 -150
- package/lib/commands/index.js +0 -15
- package/lib/commands/info/index.js +0 -287
- package/lib/commands/login/index.js +0 -170
- package/lib/commands/logout/index.js +0 -35
- package/lib/commands/npm/index.js +0 -27
- package/lib/commands/npx/index.js +0 -22
- package/lib/commands/organizations/index.js +0 -81
- package/lib/commands/raw-npm/index.js +0 -59
- package/lib/commands/raw-npx/index.js +0 -59
- package/lib/commands/report/create.js +0 -251
- package/lib/commands/report/index.js +0 -24
- package/lib/commands/report/view.js +0 -176
- package/lib/commands/repos/create.js +0 -166
- package/lib/commands/repos/delete.js +0 -93
- package/lib/commands/repos/index.js +0 -30
- package/lib/commands/repos/list.js +0 -170
- package/lib/commands/repos/update.js +0 -166
- package/lib/commands/repos/view.js +0 -128
- package/lib/commands/scan/create.js +0 -245
- package/lib/commands/scan/delete.js +0 -112
- package/lib/commands/scan/index.js +0 -30
- package/lib/commands/scan/list.js +0 -192
- package/lib/commands/scan/metadata.js +0 -113
- package/lib/commands/scan/stream.js +0 -115
- package/lib/commands/wrapper/index.js +0 -199
- package/lib/flags/command.js +0 -14
- package/lib/flags/index.js +0 -3
- package/lib/flags/output.js +0 -16
- package/lib/flags/validation.js +0 -14
- package/lib/shadow/bin/npm +0 -2
- package/lib/shadow/bin/npx +0 -2
- package/lib/shadow/link.cjs +0 -50
- package/lib/shadow/npm-cli.cjs +0 -27
- package/lib/shadow/npm-injection.cjs +0 -649
- package/lib/shadow/npx-cli.cjs +0 -27
- package/lib/shadow/package.json +0 -3
- package/lib/shadow/tty-server.cjs +0 -222
- package/lib/shadow/update-notifier.mjs +0 -3
- package/lib/utils/api-helpers.js +0 -42
- package/lib/utils/chalk-markdown.js +0 -125
- package/lib/utils/errors.js +0 -14
- package/lib/utils/flags.js +0 -27
- package/lib/utils/format-issues.js +0 -99
- package/lib/utils/formatting.js +0 -47
- package/lib/utils/issue-rules.cjs +0 -180
- package/lib/utils/meow-with-subcommands.js +0 -87
- package/lib/utils/misc.js +0 -61
- package/lib/utils/path-resolve.js +0 -204
- package/lib/utils/sdk.js +0 -99
- package/lib/utils/settings.js +0 -69
- package/lib/utils/type-helpers.cjs +0 -13
- package/lib/utils/update-notifier.js +0 -18
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import meow from 'meow'
|
|
5
|
-
import ora from 'ora'
|
|
6
|
-
|
|
7
|
-
import { outputFlags } from '../../flags/index.js'
|
|
8
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
9
|
-
import { prepareFlags } from '../../utils/flags.js'
|
|
10
|
-
import { printFlagList } from '../../utils/formatting.js'
|
|
11
|
-
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
12
|
-
|
|
13
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
14
|
-
export const update = {
|
|
15
|
-
description: 'Update a repository in an organization',
|
|
16
|
-
async run (argv, importMeta, { parentName }) {
|
|
17
|
-
const name = parentName + ' update'
|
|
18
|
-
|
|
19
|
-
const input = setupCommand(name, update.description, argv, importMeta)
|
|
20
|
-
if (input) {
|
|
21
|
-
const spinnerText = 'Updating repository... \n'
|
|
22
|
-
const spinner = ora(spinnerText).start()
|
|
23
|
-
await updateRepository(input.orgSlug, input, spinner)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const repositoryUpdateFlags = prepareFlags({
|
|
29
|
-
repoName: {
|
|
30
|
-
type: 'string',
|
|
31
|
-
shortFlag: 'n',
|
|
32
|
-
default: '',
|
|
33
|
-
description: 'Repository name',
|
|
34
|
-
},
|
|
35
|
-
repoDescription: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
shortFlag: 'd',
|
|
38
|
-
default: '',
|
|
39
|
-
description: 'Repository description',
|
|
40
|
-
},
|
|
41
|
-
homepage: {
|
|
42
|
-
type: 'string',
|
|
43
|
-
shortFlag: 'h',
|
|
44
|
-
default: '',
|
|
45
|
-
description: 'Repository url',
|
|
46
|
-
},
|
|
47
|
-
defaultBranch: {
|
|
48
|
-
type: 'string',
|
|
49
|
-
shortFlag: 'b',
|
|
50
|
-
default: 'main',
|
|
51
|
-
description: 'Repository default branch',
|
|
52
|
-
},
|
|
53
|
-
visibility: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
shortFlag: 'v',
|
|
56
|
-
default: 'private',
|
|
57
|
-
description: 'Repository visibility (Default Private)',
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// Internal functions
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @typedef CommandContext
|
|
65
|
-
* @property {boolean} outputJson
|
|
66
|
-
* @property {boolean} outputMarkdown
|
|
67
|
-
* @property {string} orgSlug
|
|
68
|
-
* @property {string} name
|
|
69
|
-
* @property {string} description
|
|
70
|
-
* @property {string} homepage
|
|
71
|
-
* @property {string} default_branch
|
|
72
|
-
* @property {string} visibility
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @param {string} name
|
|
77
|
-
* @param {string} description
|
|
78
|
-
* @param {readonly string[]} argv
|
|
79
|
-
* @param {ImportMeta} importMeta
|
|
80
|
-
* @returns {void|CommandContext}
|
|
81
|
-
*/
|
|
82
|
-
function setupCommand (name, description, argv, importMeta) {
|
|
83
|
-
const flags = {
|
|
84
|
-
...outputFlags,
|
|
85
|
-
...repositoryUpdateFlags
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const cli = meow(`
|
|
89
|
-
Usage
|
|
90
|
-
$ ${name} <org slug>
|
|
91
|
-
|
|
92
|
-
Options
|
|
93
|
-
${printFlagList(flags, 6)}
|
|
94
|
-
|
|
95
|
-
Examples
|
|
96
|
-
$ ${name} FakeOrg
|
|
97
|
-
`, {
|
|
98
|
-
argv,
|
|
99
|
-
description,
|
|
100
|
-
importMeta,
|
|
101
|
-
flags
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
const {
|
|
105
|
-
json: outputJson,
|
|
106
|
-
markdown: outputMarkdown,
|
|
107
|
-
repoName,
|
|
108
|
-
repoDescription,
|
|
109
|
-
homepage,
|
|
110
|
-
defaultBranch,
|
|
111
|
-
visibility
|
|
112
|
-
} = cli.flags
|
|
113
|
-
|
|
114
|
-
const [orgSlug = ''] = cli.input
|
|
115
|
-
|
|
116
|
-
if (!orgSlug) {
|
|
117
|
-
console.error(`${chalk.bgRed('Input error')}: Please provide an organization slug and repository name \n`)
|
|
118
|
-
cli.showHelp()
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!repoName) {
|
|
123
|
-
console.error(`${chalk.bgRed('Input error')}: Repository name is required. \n`)
|
|
124
|
-
cli.showHelp()
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
outputJson,
|
|
130
|
-
outputMarkdown,
|
|
131
|
-
orgSlug,
|
|
132
|
-
name: repoName,
|
|
133
|
-
description: repoDescription,
|
|
134
|
-
homepage,
|
|
135
|
-
default_branch: defaultBranch,
|
|
136
|
-
visibility
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @typedef RepositoryData
|
|
142
|
-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'updateOrgRepo'>["data"]} data
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @param {string} orgSlug
|
|
147
|
-
* @param {CommandContext} input
|
|
148
|
-
* @param {import('ora').Ora} spinner
|
|
149
|
-
* @returns {Promise<void|RepositoryData>}
|
|
150
|
-
*/
|
|
151
|
-
async function updateRepository (orgSlug, input, spinner) {
|
|
152
|
-
const socketSdk = await setupSdk(getDefaultKey())
|
|
153
|
-
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository')
|
|
154
|
-
|
|
155
|
-
if (!result.success) {
|
|
156
|
-
return handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
spinner.stop()
|
|
160
|
-
|
|
161
|
-
console.log('\n✅ Repository updated successfully \n')
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
data: result.data
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import chalkTable from 'chalk-table'
|
|
6
|
-
import meow from 'meow'
|
|
7
|
-
import ora from 'ora'
|
|
8
|
-
|
|
9
|
-
import { outputFlags } from '../../flags/index.js'
|
|
10
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
11
|
-
import { printFlagList } from '../../utils/formatting.js'
|
|
12
|
-
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
13
|
-
|
|
14
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
15
|
-
export const view = {
|
|
16
|
-
description: 'View repositories in an organization',
|
|
17
|
-
async run (argv, importMeta, { parentName }) {
|
|
18
|
-
const name = parentName + ' view'
|
|
19
|
-
|
|
20
|
-
const input = setupCommand(name, view.description, argv, importMeta)
|
|
21
|
-
if (input) {
|
|
22
|
-
const spinnerText = 'Fetching repository... \n'
|
|
23
|
-
const spinner = ora(spinnerText).start()
|
|
24
|
-
await viewRepository(input.orgSlug, input.repositoryName, spinner)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Internal functions
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @typedef CommandContext
|
|
33
|
-
* @property {boolean} outputJson
|
|
34
|
-
* @property {boolean} outputMarkdown
|
|
35
|
-
* @property {string} orgSlug
|
|
36
|
-
* @property {string} repositoryName
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param {string} name
|
|
41
|
-
* @param {string} description
|
|
42
|
-
* @param {readonly string[]} argv
|
|
43
|
-
* @param {ImportMeta} importMeta
|
|
44
|
-
* @returns {void|CommandContext}
|
|
45
|
-
*/
|
|
46
|
-
function setupCommand (name, description, argv, importMeta) {
|
|
47
|
-
const flags = {
|
|
48
|
-
...outputFlags
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const cli = meow(`
|
|
52
|
-
Usage
|
|
53
|
-
$ ${name} <org slug>
|
|
54
|
-
|
|
55
|
-
Options
|
|
56
|
-
${printFlagList(flags, 6)}
|
|
57
|
-
|
|
58
|
-
Examples
|
|
59
|
-
$ ${name} FakeOrg
|
|
60
|
-
`, {
|
|
61
|
-
argv,
|
|
62
|
-
description,
|
|
63
|
-
importMeta,
|
|
64
|
-
flags
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
const {
|
|
68
|
-
json: outputJson,
|
|
69
|
-
markdown: outputMarkdown
|
|
70
|
-
} = cli.flags
|
|
71
|
-
|
|
72
|
-
if (!cli.input[0]) {
|
|
73
|
-
console.error(`${chalk.bgRed('Input error')}: Please provide an organization slug and repository name \n`)
|
|
74
|
-
cli.showHelp()
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const [orgSlug = '', repositoryName = ''] = cli.input
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
outputJson,
|
|
82
|
-
outputMarkdown,
|
|
83
|
-
orgSlug,
|
|
84
|
-
repositoryName
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @typedef RepositoryData
|
|
90
|
-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgRepo'>["data"]} data
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @param {string} orgSlug
|
|
95
|
-
* @param {string} repoName
|
|
96
|
-
* @param {import('ora').Ora} spinner
|
|
97
|
-
* @returns {Promise<void|RepositoryData>}
|
|
98
|
-
*/
|
|
99
|
-
async function viewRepository (orgSlug, repoName, spinner) {
|
|
100
|
-
const socketSdk = await setupSdk(getDefaultKey())
|
|
101
|
-
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository')
|
|
102
|
-
|
|
103
|
-
if (!result.success) {
|
|
104
|
-
return handleUnsuccessfulApiResponse('getOrgRepo', result, spinner)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
spinner.stop()
|
|
108
|
-
|
|
109
|
-
const options = {
|
|
110
|
-
columns: [
|
|
111
|
-
{ field: 'id', name: chalk.magenta('ID') },
|
|
112
|
-
{ field: 'name', name: chalk.magenta('Name') },
|
|
113
|
-
{ field: 'visibility', name: chalk.magenta('Visibility') },
|
|
114
|
-
{ field: 'default_branch', name: chalk.magenta('Default branch') },
|
|
115
|
-
{ field: 'homepage', name: chalk.magenta('Homepage') },
|
|
116
|
-
{ field: 'archived', name: chalk.magenta('Archived') },
|
|
117
|
-
{ field: 'created_at', name: chalk.magenta('Created at') }
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const table = chalkTable(options, [result.data])
|
|
122
|
-
|
|
123
|
-
console.log(table, '\n')
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
data: result.data
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import { stdin as inputText, stdout as output } from 'node:process'
|
|
4
|
-
import * as readline from 'node:readline/promises'
|
|
5
|
-
|
|
6
|
-
import chalk from 'chalk'
|
|
7
|
-
import meow from 'meow'
|
|
8
|
-
import open from 'open'
|
|
9
|
-
import ora from 'ora'
|
|
10
|
-
import { ErrorWithCause } from 'pony-cause'
|
|
11
|
-
|
|
12
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
13
|
-
import { prepareFlags } from '../../utils/flags.js'
|
|
14
|
-
import { printFlagList } from '../../utils/formatting.js'
|
|
15
|
-
import { createDebugLogger } from '../../utils/misc.js'
|
|
16
|
-
import { getPackageFilesFullScans } from '../../utils/path-resolve.js'
|
|
17
|
-
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
18
|
-
|
|
19
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
20
|
-
export const create = {
|
|
21
|
-
description: 'Create a scan',
|
|
22
|
-
async run (argv, importMeta, { parentName }) {
|
|
23
|
-
const name = parentName + ' create'
|
|
24
|
-
|
|
25
|
-
const input = await setupCommand(name, create.description, argv, importMeta)
|
|
26
|
-
if (input) {
|
|
27
|
-
const spinnerText = 'Creating a scan... \n'
|
|
28
|
-
const spinner = ora(spinnerText).start()
|
|
29
|
-
|
|
30
|
-
await createFullScan(input, spinner)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const createFullScanFlags = prepareFlags({
|
|
36
|
-
repo: {
|
|
37
|
-
type: 'string',
|
|
38
|
-
shortFlag: 'r',
|
|
39
|
-
default: '',
|
|
40
|
-
description: 'Repository name',
|
|
41
|
-
},
|
|
42
|
-
branch: {
|
|
43
|
-
type: 'string',
|
|
44
|
-
shortFlag: 'b',
|
|
45
|
-
default: '',
|
|
46
|
-
description: 'Branch name',
|
|
47
|
-
},
|
|
48
|
-
commitMessage: {
|
|
49
|
-
type: 'string',
|
|
50
|
-
shortFlag: 'm',
|
|
51
|
-
default: '',
|
|
52
|
-
description: 'Commit message',
|
|
53
|
-
},
|
|
54
|
-
commitHash: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
shortFlag: 'ch',
|
|
57
|
-
default: '',
|
|
58
|
-
description: 'Commit hash',
|
|
59
|
-
},
|
|
60
|
-
pullRequest: {
|
|
61
|
-
type: 'number',
|
|
62
|
-
shortFlag: 'pr',
|
|
63
|
-
description: 'Commit hash',
|
|
64
|
-
},
|
|
65
|
-
committers: {
|
|
66
|
-
type: 'string',
|
|
67
|
-
shortFlag: 'c',
|
|
68
|
-
default: '',
|
|
69
|
-
description: 'Committers',
|
|
70
|
-
},
|
|
71
|
-
defaultBranch: {
|
|
72
|
-
type: 'boolean',
|
|
73
|
-
shortFlag: 'db',
|
|
74
|
-
default: false,
|
|
75
|
-
description: 'Make default branch',
|
|
76
|
-
},
|
|
77
|
-
pendingHead: {
|
|
78
|
-
type: 'boolean',
|
|
79
|
-
shortFlag: 'ph',
|
|
80
|
-
default: false,
|
|
81
|
-
description: 'Set as pending head',
|
|
82
|
-
},
|
|
83
|
-
tmp: {
|
|
84
|
-
type: 'boolean',
|
|
85
|
-
shortFlag: 't',
|
|
86
|
-
default: false,
|
|
87
|
-
description: 'Set the visibility (true/false) of the scan in your dashboard',
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
// Internal functions
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @typedef CommandContext
|
|
95
|
-
* @property {string} orgSlug
|
|
96
|
-
* @property {string} repoName
|
|
97
|
-
* @property {string} branchName
|
|
98
|
-
* @property {string} committers
|
|
99
|
-
* @property {string} commitMessage
|
|
100
|
-
* @property {string} commitHash
|
|
101
|
-
* @property {number | undefined} pullRequest
|
|
102
|
-
* @property {boolean} defaultBranch
|
|
103
|
-
* @property {boolean} pendingHead
|
|
104
|
-
* @property {boolean} tmp
|
|
105
|
-
* @property {string[]} packagePaths
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @param {string} name
|
|
110
|
-
* @param {string} description
|
|
111
|
-
* @param {readonly string[]} argv
|
|
112
|
-
* @param {ImportMeta} importMeta
|
|
113
|
-
* @returns {Promise<void|CommandContext>}
|
|
114
|
-
*/
|
|
115
|
-
async function setupCommand (name, description, argv, importMeta) {
|
|
116
|
-
const flags = {
|
|
117
|
-
...createFullScanFlags
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const cli = meow(`
|
|
121
|
-
Usage
|
|
122
|
-
$ ${name} [...options]
|
|
123
|
-
|
|
124
|
-
Options
|
|
125
|
-
${printFlagList(flags, 6)}
|
|
126
|
-
|
|
127
|
-
Examples
|
|
128
|
-
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
|
|
129
|
-
`, {
|
|
130
|
-
argv,
|
|
131
|
-
description,
|
|
132
|
-
importMeta,
|
|
133
|
-
flags
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
const {
|
|
137
|
-
repo: repoName,
|
|
138
|
-
branch: branchName,
|
|
139
|
-
commitMessage,
|
|
140
|
-
defaultBranch,
|
|
141
|
-
pendingHead,
|
|
142
|
-
tmp,
|
|
143
|
-
committers,
|
|
144
|
-
commitHash,
|
|
145
|
-
pullRequest
|
|
146
|
-
} = cli.flags
|
|
147
|
-
|
|
148
|
-
if (!cli.input[0]) {
|
|
149
|
-
cli.showHelp()
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const [orgSlug = ''] = cli.input
|
|
154
|
-
|
|
155
|
-
const cwd = process.cwd()
|
|
156
|
-
const socketSdk = await setupSdk()
|
|
157
|
-
const supportedFiles = await socketSdk.getReportSupportedFiles()
|
|
158
|
-
.then(res => {
|
|
159
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, ora())
|
|
160
|
-
return res.data
|
|
161
|
-
}).catch(
|
|
162
|
-
/** @type {(cause: Error) => never} */
|
|
163
|
-
(cause) => {
|
|
164
|
-
throw new ErrorWithCause('Failed getting supported files for report', { cause })
|
|
165
|
-
})
|
|
166
|
-
const debugLog = createDebugLogger(false)
|
|
167
|
-
const packagePaths = await getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog)
|
|
168
|
-
|
|
169
|
-
if (!repoName || !branchName || !packagePaths.length) {
|
|
170
|
-
console.error(`${chalk.bgRed('Input error')}: Please provide the required fields: \n
|
|
171
|
-
- Repository name using --repo, \n
|
|
172
|
-
- Branch name using --branch \n
|
|
173
|
-
- At least one file path (e.g. ./package.json) .\n`)
|
|
174
|
-
cli.showHelp()
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
orgSlug,
|
|
180
|
-
repoName,
|
|
181
|
-
branchName,
|
|
182
|
-
commitMessage,
|
|
183
|
-
defaultBranch,
|
|
184
|
-
pendingHead,
|
|
185
|
-
tmp,
|
|
186
|
-
packagePaths,
|
|
187
|
-
commitHash,
|
|
188
|
-
committers,
|
|
189
|
-
pullRequest
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @typedef FullScanData
|
|
195
|
-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'CreateOrgFullScan'>["data"]} data
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @param {CommandContext} input
|
|
200
|
-
* @param {import('ora').Ora} spinner
|
|
201
|
-
* @returns {Promise<void|FullScanData>}
|
|
202
|
-
*/
|
|
203
|
-
async function createFullScan (input, spinner) {
|
|
204
|
-
const socketSdk = await setupSdk(getDefaultKey())
|
|
205
|
-
const {
|
|
206
|
-
orgSlug,
|
|
207
|
-
repoName,
|
|
208
|
-
branchName,
|
|
209
|
-
commitMessage,
|
|
210
|
-
defaultBranch,
|
|
211
|
-
pendingHead,
|
|
212
|
-
tmp,
|
|
213
|
-
packagePaths
|
|
214
|
-
} = input
|
|
215
|
-
|
|
216
|
-
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
217
|
-
repo: repoName,
|
|
218
|
-
branch: branchName,
|
|
219
|
-
commit_message: commitMessage,
|
|
220
|
-
make_default_branch: defaultBranch,
|
|
221
|
-
set_as_pending_head: pendingHead,
|
|
222
|
-
tmp
|
|
223
|
-
}, packagePaths), 'Creating scan')
|
|
224
|
-
|
|
225
|
-
if (!result.success) {
|
|
226
|
-
return handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner)
|
|
227
|
-
}
|
|
228
|
-
spinner.stop()
|
|
229
|
-
|
|
230
|
-
console.log('\n✅ Scan created successfully \n')
|
|
231
|
-
const link = chalk.hex('#00FFFF').underline(`${result.data.html_report_url}`)
|
|
232
|
-
console.log(`Available at: ${link} \n`)
|
|
233
|
-
|
|
234
|
-
const rl = readline.createInterface({ input: inputText, output })
|
|
235
|
-
|
|
236
|
-
const answer = await rl.question('Would you like to open it in your browser? (y/n) ')
|
|
237
|
-
|
|
238
|
-
answer.toLowerCase() === 'y' && open(`${result.data.html_report_url}`)
|
|
239
|
-
|
|
240
|
-
rl.close()
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
data: result.data
|
|
244
|
-
}
|
|
245
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import meow from 'meow'
|
|
5
|
-
import ora from 'ora'
|
|
6
|
-
|
|
7
|
-
import { outputFlags } from '../../flags/index.js'
|
|
8
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
9
|
-
import { printFlagList } from '../../utils/formatting.js'
|
|
10
|
-
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
11
|
-
|
|
12
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
13
|
-
export const del = {
|
|
14
|
-
description: 'Delete a scan',
|
|
15
|
-
async run (argv, importMeta, { parentName }) {
|
|
16
|
-
const name = parentName + ' del'
|
|
17
|
-
|
|
18
|
-
const input = setupCommand(name, del.description, argv, importMeta)
|
|
19
|
-
if (input) {
|
|
20
|
-
const spinnerText = 'Deleting scan...'
|
|
21
|
-
const spinner = ora(spinnerText).start()
|
|
22
|
-
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Internal functions
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @typedef CommandContext
|
|
31
|
-
* @property {boolean} outputJson
|
|
32
|
-
* @property {boolean} outputMarkdown
|
|
33
|
-
* @property {string} orgSlug
|
|
34
|
-
* @property {string} fullScanId
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {string} name
|
|
39
|
-
* @param {string} description
|
|
40
|
-
* @param {readonly string[]} argv
|
|
41
|
-
* @param {ImportMeta} importMeta
|
|
42
|
-
* @returns {void|CommandContext}
|
|
43
|
-
*/
|
|
44
|
-
function setupCommand (name, description, argv, importMeta) {
|
|
45
|
-
const flags = {
|
|
46
|
-
...outputFlags
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const cli = meow(`
|
|
50
|
-
Usage
|
|
51
|
-
$ ${name} <org slug> <scan ID>
|
|
52
|
-
|
|
53
|
-
Options
|
|
54
|
-
${printFlagList(flags, 6)}
|
|
55
|
-
|
|
56
|
-
Examples
|
|
57
|
-
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
58
|
-
`, {
|
|
59
|
-
argv,
|
|
60
|
-
description,
|
|
61
|
-
importMeta,
|
|
62
|
-
flags
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
json: outputJson,
|
|
67
|
-
markdown: outputMarkdown,
|
|
68
|
-
} = cli.flags
|
|
69
|
-
|
|
70
|
-
if (cli.input.length < 2) {
|
|
71
|
-
console.error(`${chalk.bgRed('Input error')}: Please specify an organization slug and a scan ID.\n`)
|
|
72
|
-
cli.showHelp()
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const [orgSlug = '', fullScanId = ''] = cli.input
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
outputJson,
|
|
80
|
-
outputMarkdown,
|
|
81
|
-
orgSlug,
|
|
82
|
-
fullScanId
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @typedef FullScanData
|
|
88
|
-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'deleteOrgFullScan'>["data"]} data
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @param {string} orgSlug
|
|
93
|
-
* @param {string} fullScanId
|
|
94
|
-
* @param {import('ora').Ora} spinner
|
|
95
|
-
* @returns {Promise<void|FullScanData>}
|
|
96
|
-
*/
|
|
97
|
-
async function deleteOrgFullScan (orgSlug, fullScanId, spinner) {
|
|
98
|
-
const socketSdk = await setupSdk(getDefaultKey())
|
|
99
|
-
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan')
|
|
100
|
-
|
|
101
|
-
if (!result.success) {
|
|
102
|
-
return handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
console.log('\n ✅ Scan deleted successfully. \n')
|
|
106
|
-
|
|
107
|
-
spinner.stop()
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
data: result.data
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { create } from './create.js'
|
|
2
|
-
import { del } from './delete.js'
|
|
3
|
-
import { list } from './list.js'
|
|
4
|
-
import { metadata } from './metadata.js'
|
|
5
|
-
import { stream } from './stream.js'
|
|
6
|
-
import { meowWithSubcommands } from '../../utils/meow-with-subcommands.js'
|
|
7
|
-
|
|
8
|
-
const description = 'Scans related commands'
|
|
9
|
-
|
|
10
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
11
|
-
export const scan = {
|
|
12
|
-
description,
|
|
13
|
-
run: async (argv, importMeta, { parentName }) => {
|
|
14
|
-
await meowWithSubcommands(
|
|
15
|
-
{
|
|
16
|
-
create,
|
|
17
|
-
stream,
|
|
18
|
-
list,
|
|
19
|
-
del,
|
|
20
|
-
metadata
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
argv,
|
|
24
|
-
description,
|
|
25
|
-
importMeta,
|
|
26
|
-
name: parentName + ' scan',
|
|
27
|
-
}
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
}
|