Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip
Browse files Browse the repository at this point in the history
charliegerard committed Jun 10, 2024
1 parent b595de1 commit e134b35
Showing 6 changed files with 39 additions and 70 deletions.
34 changes: 13 additions & 21 deletions lib/commands/fullscans/create.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @ts-nocheck
/* eslint-disable no-console */

import meow from 'meow'
import ora from 'ora'

import { outputFlags, validationFlags } from '../../flags/index.js'
import { handleApiCall } from '../../utils/api-helpers.js'
import { outputFlags } from '../../flags/index.js'
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
import { printFlagList } from '../../utils/formatting.js'
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'

@@ -28,10 +27,8 @@ export const create = {

/**
* @typedef CommandContext
* @property {boolean} includeAllIssues
* @property {boolean} outputJson
* @property {boolean} outputMarkdown
* @property {boolean} strict
*/

/**
@@ -43,20 +40,15 @@ export const create = {
*/
function setupCommand (name, description, argv, importMeta) {
const flags = {
...outputFlags,
...validationFlags,
...outputFlags
}

const cli = meow(`
Usage
$ ${name} <name>
$ ${name}
Options
${printFlagList(flags, 6)}
Examples
$ ${name} webtorrent
$ ${name} [email protected]
`, {
argv,
description,
@@ -65,23 +57,19 @@ function setupCommand (name, description, argv, importMeta) {
})

const {
all: includeAllIssues,
json: outputJson,
markdown: outputMarkdown,
strict,
markdown: outputMarkdown
} = cli.flags

return {
includeAllIssues,
outputJson,
outputMarkdown,
strict,
outputMarkdown
}
}

/**
* @typedef PackageData
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'createOrgFullScan'>["data"]} data
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'CreateOrgFullScan'>["data"]} data
*/

/**
@@ -98,9 +86,13 @@ async function createFullScan (spinner) {
tmp: true
}, ['package.json']), 'Creating full scan')

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

// console.log('RES: ', result.data)
console.log('\n Full scan created successfully \n')
console.log('Full scan details: \n')
console.log(result.data)

spinner.stop()

22 changes: 7 additions & 15 deletions lib/commands/fullscans/delete.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// @ts-nocheck
/* eslint-disable no-console */

import meow from 'meow'
import ora from 'ora'

import { outputFlags, validationFlags } from '../../flags/index.js'
import { outputFlags } from '../../flags/index.js'
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
import { InputError } from '../../utils/errors.js'
import { printFlagList } from '../../utils/formatting.js'
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'

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

const input = setupCommand(name, deleteFullScan.description, argv, importMeta)
const input = setupCommand(name, del.description, argv, importMeta)
if (input) {
const spinnerText = 'Deleting full scan...'
const spinner = ora(spinnerText).start()
@@ -29,10 +28,8 @@ export const deleteFullScan = {

/**
* @typedef CommandContext
* @property {boolean} includeAllIssues
* @property {boolean} outputJson
* @property {boolean} outputMarkdown
* @property {boolean} strict
* @property {string} orgSlug
* @property {string} fullScanId
*/
@@ -46,8 +43,7 @@ export const deleteFullScan = {
*/
function setupCommand (name, description, argv, importMeta) {
const flags = {
...outputFlags,
...validationFlags,
...outputFlags
}

const cli = meow(`
@@ -67,10 +63,8 @@ function setupCommand (name, description, argv, importMeta) {
})

const {
all: includeAllIssues,
json: outputJson,
markdown: outputMarkdown,
strict,
} = cli.flags

if (cli.input.length < 2) {
@@ -81,10 +75,8 @@ function setupCommand (name, description, argv, importMeta) {
const fullScanId = cli.input[1] || ''

return {
includeAllIssues,
outputJson,
outputMarkdown,
strict,
orgSlug,
fullScanId
}
@@ -105,12 +97,12 @@ async function deleteOrgFullScan (orgSlug, fullScanId, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting full scan')

console.log(result)

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

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

spinner.stop()

return {
4 changes: 2 additions & 2 deletions lib/commands/fullscans/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { create } from './create.js'
import { deleteFullScan } from './delete.js'
import { del } from './delete.js'
import { list } from './list.js'
import { stream } from './stream.js'
import { meowWithSubcommands } from '../../utils/meow-with-subcommands.js'
@@ -15,7 +15,7 @@ export const fullscans = {
create,
stream,
list,
deleteFullScan
del
},
{
argv,
29 changes: 11 additions & 18 deletions lib/commands/fullscans/list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// @ts-nocheck
/* eslint-disable no-console */

import meow from 'meow'
import ora from 'ora'

import { outputFlags, validationFlags } from '../../flags/index.js'
import { outputFlags } from '../../flags/index.js'
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
import { InputError } from '../../utils/errors.js'
import { printFlagList } from '../../utils/formatting.js'
@@ -18,7 +17,7 @@ export const list = {

const input = setupCommand(name, list.description, argv, importMeta)
if (input) {
const spinnerText = 'Listinga full scan...'
const spinnerText = 'Listing full scans...'
const spinner = ora(spinnerText).start()
await listOrgFullScan(input.orgSlug, spinner)
}
@@ -29,10 +28,8 @@ export const list = {

/**
* @typedef CommandContext
* @property {boolean} includeAllIssues
* @property {boolean} outputJson
* @property {boolean} outputMarkdown
* @property {boolean} strict
* @property {string} orgSlug
*/

@@ -45,8 +42,7 @@ export const list = {
*/
function setupCommand (name, description, argv, importMeta) {
const flags = {
...outputFlags,
...validationFlags,
...outputFlags
}

const cli = meow(`
@@ -66,30 +62,26 @@ function setupCommand (name, description, argv, importMeta) {
})

const {
all: includeAllIssues,
json: outputJson,
markdown: outputMarkdown,
strict,
markdown: outputMarkdown
} = cli.flags

if (cli.input.length < 1) {
if (!cli.input[0]) {
throw new InputError('Please specify an organization slug.')
}

const orgSlug = cli.input[0] || ''

return {
includeAllIssues,
outputJson,
outputMarkdown,
strict,
orgSlug
}
}

/**
* @typedef PackageData
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'listOrgFullScan'>["data"]} data
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList'>["data"]} data
*/

/**
@@ -99,14 +91,15 @@ function setupCommand (name, description, argv, importMeta) {
*/
async function listOrgFullScan (orgSlug, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
const result = await handleApiCall(socketSdk.listOrgFullScan(orgSlug), 'Deleting full scan')

console.log(result)
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug), 'Listing full scans')

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

console.log(`\n Full scans for ${orgSlug}: \n`)
result.data.results.map(scan => console.log(scan))

spinner.stop()

return {
18 changes: 5 additions & 13 deletions lib/commands/fullscans/stream.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// @ts-nocheck
/* eslint-disable no-console */

import meow from 'meow'
import ora from 'ora'

import { outputFlags, validationFlags } from '../../flags/index.js'
import { outputFlags } from '../../flags/index.js'
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
import { InputError } from '../../utils/errors.js'
import { printFlagList } from '../../utils/formatting.js'
@@ -29,10 +28,8 @@ export const stream = {

/**
* @typedef CommandContext
* @property {boolean} includeAllIssues
* @property {boolean} outputJson
* @property {boolean} outputMarkdown
* @property {boolean} strict
* @property {string} orgSlug
* @property {string} fullScanId
*/
@@ -46,8 +43,7 @@ export const stream = {
*/
function setupCommand (name, description, argv, importMeta) {
const flags = {
...outputFlags,
...validationFlags,
...outputFlags
}

const cli = meow(`
@@ -67,24 +63,20 @@ function setupCommand (name, description, argv, importMeta) {
})

const {
all: includeAllIssues,
json: outputJson,
markdown: outputMarkdown,
strict,
} = cli.flags

if (cli.input.length < 1) {
if (cli.input.length < 2) {
throw new InputError('Please specify an organization slug and a full scan ID.')
}

const orgSlug = cli.input[0] || ''
const fullScanId = cli.input[1] || ''

return {
includeAllIssues,
outputJson,
outputMarkdown,
strict,
orgSlug,
fullScanId
}
@@ -105,12 +97,12 @@ async function getOrgFullScan (orgSlug, fullScanId, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
const result = await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId), 'Streaming a full scan')

console.log(result)

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

console.log('\n Full scan details: \n')

spinner.stop()

return {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@
"dependencies": {
"@apideck/better-ajv-errors": "^0.3.6",
"@socketsecurity/config": "^2.0.0",
"@socketsecurity/sdk": "^0.7.3",
"@socketsecurity/sdk": "^0.9.0",
"chalk": "^5.1.2",
"globby": "^13.1.3",
"hpagent": "^1.2.0",

0 comments on commit e134b35

Please sign in to comment.