Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
charliegerard committed Jun 13, 2024
1 parent 0a72de2 commit 8e73c51
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
10 changes: 5 additions & 5 deletions lib/commands/fullscans/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import { getDefaultKey, setupSdk } from '../../utils/sdk.js'

/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
export const create = {
description: 'Create a full scan',
description: 'Create a scan',
async run (argv, importMeta, { parentName }) {
const name = parentName + ' create'

const input = await setupCommand(name, create.description, argv, importMeta)
if (input) {
const spinnerText = 'Creating a full scan... \n'
const spinnerText = 'Creating a scan... \n'
const spinner = ora(spinnerText).start()

await createFullScan(input, spinner)
Expand Down Expand Up @@ -85,7 +85,7 @@ const createFullScanFlags = prepareFlags({
type: 'boolean',
shortFlag: 't',
default: false,
description: 'Set the visibility (true/false) of the full scan in your dashboard',
description: 'Set the visibility (true/false) of the scan in your dashboard',
}
})

Expand Down Expand Up @@ -213,14 +213,14 @@ async function createFullScan (input, spinner) {
make_default_branch: defaultBranch,
set_as_pending_head: pendingHead,
tmp
}, packagePaths), 'Creating full scan')
}, packagePaths), 'Creating scan')

if (!result.success) {
return handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner)
}
spinner.stop()

console.log('\n✅ Full scan created successfully \n')
console.log('\n✅ Scan created successfully \n')
const link = chalk.hex('#00FFFF').underline(`${result.data.html_report_url}`)
console.log(`Available at: ${link} \n`)

Expand Down
15 changes: 9 additions & 6 deletions lib/commands/fullscans/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { getDefaultKey, setupSdk } from '../../utils/sdk.js'

/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
export const del = {
description: 'Delete a full scan',
description: 'Delete a scan',
async run (argv, importMeta, { parentName }) {
const name = parentName + ' del'

const input = setupCommand(name, del.description, argv, importMeta)
if (input) {
const spinnerText = 'Deleting full scan...'
const spinnerText = 'Deleting scan...'
const spinner = ora(spinnerText).start()
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner)
}
Expand Down Expand Up @@ -48,7 +48,7 @@ function setupCommand (name, description, argv, importMeta) {

const cli = meow(`
Usage
$ ${name} <org slug> <full scan ID>
$ ${name} <org slug> <scan ID>
Options
${printFlagList(flags, 6)}
Expand All @@ -68,7 +68,10 @@ function setupCommand (name, description, argv, importMeta) {
} = cli.flags

if (cli.input.length < 2) {
throw new InputError('Please specify an organization slug and a full scan ID.')
throw new InputError(`Please specify an organization slug and a scan ID. \n
Example:
socket scan del FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
`)
}

const orgSlug = cli.input[0] || ''
Expand All @@ -95,13 +98,13 @@ function setupCommand (name, description, argv, importMeta) {
*/
async function deleteOrgFullScan (orgSlug, fullScanId, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting full scan')
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan')

if (!result.success) {
return handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner)
}

console.log('\n ✅ Full scan deleted successfully. \n')
console.log('\n ✅ Scan deleted successfully. \n')

spinner.stop()

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/fullscans/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { list } from './list.js'
import { stream } from './stream.js'
import { meowWithSubcommands } from '../../utils/meow-with-subcommands.js'

const description = 'Full scans related commands'
const description = 'Scans related commands'

/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
export const fullscans = {
Expand Down
10 changes: 5 additions & 5 deletions lib/commands/fullscans/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { getDefaultKey, setupSdk } from '../../utils/sdk.js'

/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
export const list = {
description: 'List full scans',
description: 'List scans',
async run (argv, importMeta, { parentName }) {
const name = parentName + ' list'

const input = setupCommand(name, list.description, argv, importMeta)
if (input) {
const spinnerText = 'Listing full scans... \n'
const spinnerText = 'Listing scans... \n'
const spinner = ora(spinnerText).start()
await listOrgFullScan(input.orgSlug, input, spinner)
}
Expand Down Expand Up @@ -155,19 +155,19 @@ function setupCommand (name, description, argv, importMeta) {
async function listOrgFullScan (orgSlug, input, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
// @ts-ignore
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing full scans')
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans')

if (!result.success) {
return handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner)
}
spinner.stop()

console.log(`\n Listing full scans for: ${orgSlug} \n`)
console.log(`\n Listing scans for: ${orgSlug} \n`)

const options = {
columns: [
{ field: 'id', name: chalk.magenta('ID') },
{ field: 'report_url', name: chalk.magenta('Report URL') },
{ field: 'report_url', name: chalk.magenta('Scan URL') },
{ field: 'branch', name: chalk.magenta('Branch') },
{ field: 'created_at', name: chalk.magenta('Created at') }
]
Expand Down
16 changes: 9 additions & 7 deletions lib/commands/fullscans/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { getDefaultKey, setupSdk } from '../../utils/sdk.js'

/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
export const stream = {
description: 'Stream a full scan',
description: 'Stream a scan',
async run (argv, importMeta, { parentName }) {
const name = parentName + ' stream'

const input = setupCommand(name, stream.description, argv, importMeta)
if (input) {
const spinnerText = 'Streaming full scan... \n'
const spinnerText = 'Streaming scan... \n'
const spinner = ora(spinnerText).start()
await getOrgFullScan(input.orgSlug, input.fullScanId, input.file, spinner)
}
Expand Down Expand Up @@ -49,7 +49,7 @@ function setupCommand (name, description, argv, importMeta) {

const cli = meow(`
Usage
$ ${name} <org slug> <full scan ID> <file>
$ ${name} <org slug> <scan ID> <file>
Options
${printFlagList(flags, 6)}
Expand All @@ -69,7 +69,10 @@ function setupCommand (name, description, argv, importMeta) {
} = cli.flags

if (cli.input.length < 2) {
throw new InputError('Please specify an organization slug and a full scan ID.')
throw new InputError(`Please specify an organization slug and a scan ID.\n
Example:
socket scan stream FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
`)
}

const orgSlug = cli.input[0] || ''
Expand All @@ -93,14 +96,13 @@ function setupCommand (name, description, argv, importMeta) {
/**
* @param {string} orgSlug
* @param {string} fullScanId
* @param {string|undefined} file
* @param {string | undefined} file
* @param {import('ora').Ora} spinner
* @returns {Promise<void|FullScanData>}
*/
async function getOrgFullScan (orgSlug, fullScanId, file, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
// @ts-ignore
const result = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a full scan')
const result = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan')

if (!result?.success) {
return handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"dependencies": {
"@apideck/better-ajv-errors": "^0.3.6",
"@socketsecurity/config": "^2.0.0",
"@socketsecurity/sdk": "^0.9.0",
"@socketsecurity/sdk": "^1.0.1",
"chalk": "^5.1.2",
"chalk-table": "^1.0.2",
"globby": "^13.1.3",
Expand Down

0 comments on commit 8e73c51

Please sign in to comment.