|
1 |
| -import chalk from 'chalk' |
2 |
| -import meow from 'meow' |
3 |
| -import ora from 'ora' |
4 |
| -import fetch from 'node-fetch' |
5 |
| -import util from 'util' |
6 |
| - |
7 |
| -import { outputFlags } from '../../flags' |
8 |
| -// import { |
9 |
| -// handleApiCall, |
10 |
| -// handleUnsuccessfulApiResponse |
11 |
| -// } from '../../utils/api-helpers' |
12 |
| -import { printFlagList } from '../../utils/formatting' |
13 |
| -import { getDefaultKey } from '../../utils/sdk' |
14 |
| - |
15 |
| -import type { CliSubcommand } from '../../utils/meow-with-subcommands' |
16 |
| -import type { Ora } from 'ora' |
17 |
| -import { AuthError } from '../../utils/errors' |
18 |
| - |
19 |
| -export const get: CliSubcommand = { |
20 |
| - description: 'Get a diff scan for an organization', |
21 |
| - async run(argv, importMeta, { parentName }) { |
22 |
| - const name = `${parentName} get` |
23 |
| - const input = setupCommand(name, get.description, argv, importMeta) |
24 |
| - if (input) { |
25 |
| - const apiKey = getDefaultKey() |
26 |
| - if(!apiKey){ |
27 |
| - throw new AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.") |
28 |
| - } |
29 |
| - const spinnerText = 'Getting diff scan... \n' |
30 |
| - const spinner = ora(spinnerText).start() |
31 |
| - await getDiffScan(input.before, input.after, spinner, apiKey) |
32 |
| - } |
33 |
| - } |
34 |
| -} |
35 |
| - |
36 |
| -const getDiffScanFlags: { [key: string]: any } = { |
37 |
| - before: { |
38 |
| - type: 'string', |
39 |
| - shortFlag: 'b', |
40 |
| - default: '', |
41 |
| - description: 'The full scan ID of the base scan' |
42 |
| - }, |
43 |
| - after: { |
44 |
| - type: 'string', |
45 |
| - shortFlag: 'a', |
46 |
| - default: '', |
47 |
| - description: 'The full scan ID of the head scan' |
48 |
| - }, |
49 |
| - preview: { |
50 |
| - type: 'boolean', |
51 |
| - shortFlag: 'p', |
52 |
| - default: true, |
53 |
| - description: 'A boolean flag to persist or not the diff scan result' |
54 |
| - }, |
55 |
| -} |
56 |
| - |
57 |
| -// Internal functions |
58 |
| - |
59 |
| -type CommandContext = { |
60 |
| - outputJson: boolean |
61 |
| - outputMarkdown: boolean |
62 |
| - before: string |
63 |
| - after: string |
64 |
| - preview: boolean |
65 |
| -} |
66 |
| - |
67 |
| -function setupCommand( |
68 |
| - name: string, |
69 |
| - description: string, |
70 |
| - argv: readonly string[], |
71 |
| - importMeta: ImportMeta |
72 |
| -): CommandContext | undefined { |
73 |
| - const flags: { [key: string]: any } = { |
74 |
| - ...outputFlags, |
75 |
| - ...getDiffScanFlags |
76 |
| - } |
77 |
| - |
78 |
| - const cli = meow( |
79 |
| - ` |
80 |
| - Usage |
81 |
| - $ ${name} |
82 |
| -
|
83 |
| - Options |
84 |
| - ${printFlagList(flags, 6)} |
85 |
| -
|
86 |
| - Examples |
87 |
| - $ ${name} |
88 |
| - `, |
89 |
| - { |
90 |
| - argv, |
91 |
| - description, |
92 |
| - importMeta, |
93 |
| - flags |
94 |
| - } |
95 |
| - ) |
96 |
| - |
97 |
| - const { |
98 |
| - json: outputJson, |
99 |
| - markdown: outputMarkdown, |
100 |
| - before, |
101 |
| - after, |
102 |
| - preview, |
103 |
| - } = cli.flags |
104 |
| - |
105 |
| - if (!before || !after) { |
106 |
| - console.error( |
107 |
| - `${chalk.bgRed('Input error')}: Please specify a before and after full scan ID.\n` |
108 |
| - ) |
109 |
| - cli.showHelp() |
110 |
| - return |
111 |
| - } |
112 |
| - |
113 |
| - return <CommandContext>{ |
114 |
| - outputJson, |
115 |
| - outputMarkdown, |
116 |
| - before, |
117 |
| - after, |
118 |
| - preview |
119 |
| - } |
120 |
| -} |
121 |
| - |
122 |
| -async function getDiffScan( |
123 |
| - before: string, |
124 |
| - after: string, |
125 |
| - spinner: Ora, |
126 |
| - apiKey: string |
127 |
| -): Promise<void> { |
128 |
| -// const socketSdk = await setupSdk(apiKey) |
129 |
| -// const result = await handleApiCall( |
130 |
| -// socketSdk.getOrgFullScanList(orgSlug, input), |
131 |
| -// 'Listing scans' |
132 |
| -// ) |
| 1 | +// import chalk from 'chalk' |
| 2 | +// import meow from 'meow' |
| 3 | +// import ora from 'ora' |
| 4 | +// import fetch from 'node-fetch' |
| 5 | +// import util from 'util' |
| 6 | + |
| 7 | +// import { outputFlags } from '../../flags' |
| 8 | +// // import { |
| 9 | +// // handleApiCall, |
| 10 | +// // handleUnsuccessfulApiResponse |
| 11 | +// // } from '../../utils/api-helpers' |
| 12 | +// import { printFlagList } from '../../utils/formatting' |
| 13 | +// import { getDefaultKey } from '../../utils/sdk' |
| 14 | + |
| 15 | +// import type { CliSubcommand } from '../../utils/meow-with-subcommands' |
| 16 | +// import type { Ora } from 'ora' |
| 17 | +// import { AuthError } from '../../utils/errors' |
| 18 | + |
| 19 | +// export const get: CliSubcommand = { |
| 20 | +// description: 'Get a diff scan for an organization', |
| 21 | +// async run(argv, importMeta, { parentName }) { |
| 22 | +// const name = `${parentName} get` |
| 23 | +// const input = setupCommand(name, get.description, argv, importMeta) |
| 24 | +// if (input) { |
| 25 | +// const apiKey = getDefaultKey() |
| 26 | +// if(!apiKey){ |
| 27 | +// throw new AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.") |
| 28 | +// } |
| 29 | +// const spinnerText = 'Getting diff scan... \n' |
| 30 | +// const spinner = ora(spinnerText).start() |
| 31 | +// await getDiffScan(input.before, input.after, spinner, apiKey) |
| 32 | +// } |
| 33 | +// } |
| 34 | +// } |
| 35 | + |
| 36 | +// const getDiffScanFlags: { [key: string]: any } = { |
| 37 | +// before: { |
| 38 | +// type: 'string', |
| 39 | +// shortFlag: 'b', |
| 40 | +// default: '', |
| 41 | +// description: 'The full scan ID of the base scan' |
| 42 | +// }, |
| 43 | +// after: { |
| 44 | +// type: 'string', |
| 45 | +// shortFlag: 'a', |
| 46 | +// default: '', |
| 47 | +// description: 'The full scan ID of the head scan' |
| 48 | +// }, |
| 49 | +// preview: { |
| 50 | +// type: 'boolean', |
| 51 | +// shortFlag: 'p', |
| 52 | +// default: true, |
| 53 | +// description: 'A boolean flag to persist or not the diff scan result' |
| 54 | +// }, |
| 55 | +// } |
| 56 | + |
| 57 | +// // Internal functions |
| 58 | + |
| 59 | +// type CommandContext = { |
| 60 | +// outputJson: boolean |
| 61 | +// outputMarkdown: boolean |
| 62 | +// before: string |
| 63 | +// after: string |
| 64 | +// preview: boolean |
| 65 | +// } |
| 66 | + |
| 67 | +// function setupCommand( |
| 68 | +// name: string, |
| 69 | +// description: string, |
| 70 | +// argv: readonly string[], |
| 71 | +// importMeta: ImportMeta |
| 72 | +// ): CommandContext | undefined { |
| 73 | +// const flags: { [key: string]: any } = { |
| 74 | +// ...outputFlags, |
| 75 | +// ...getDiffScanFlags |
| 76 | +// } |
133 | 77 |
|
134 |
| - const response = await fetch(`https://api.socket.dev/v0/orgs/SocketDev/full-scans/diff?before=${before}&after=${after}&preview`, { |
135 |
| - method: 'GET', |
136 |
| - headers: { |
137 |
| - 'Authorization': 'Basic ' + btoa(`${apiKey}:${apiKey}`) |
138 |
| - } |
139 |
| - }); |
140 |
| - const data = await response.json(); |
| 78 | +// const cli = meow( |
| 79 | +// ` |
| 80 | +// Usage |
| 81 | +// $ ${name} |
| 82 | + |
| 83 | +// Options |
| 84 | +// ${printFlagList(flags, 6)} |
| 85 | + |
| 86 | +// Examples |
| 87 | +// $ ${name} |
| 88 | +// `, |
| 89 | +// { |
| 90 | +// argv, |
| 91 | +// description, |
| 92 | +// importMeta, |
| 93 | +// flags |
| 94 | +// } |
| 95 | +// ) |
141 | 96 |
|
142 |
| -// if (!result.success) { |
143 |
| -// handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner) |
| 97 | +// const { |
| 98 | +// json: outputJson, |
| 99 | +// markdown: outputMarkdown, |
| 100 | +// before, |
| 101 | +// after, |
| 102 | +// preview, |
| 103 | +// } = cli.flags |
| 104 | + |
| 105 | +// if (!before || !after) { |
| 106 | +// console.error( |
| 107 | +// `${chalk.bgRed.white('Input error')}: Please specify a before and after full scan ID. To get full scans IDs, you can run the command "socket scan list <your org slug>". \n` |
| 108 | +// ) |
| 109 | +// cli.showHelp() |
144 | 110 | // return
|
145 | 111 | // }
|
146 |
| - spinner.stop() |
147 | 112 |
|
148 |
| - // before: dfc4cf0c-aefd-4081-9e4e-7385257f26e2 |
149 |
| - // after: 922e45f5-8a7b-4b16-95a5-e98ad00470f1 |
150 |
| - |
151 |
| - console.log(`\n Diff scan result: \n`) |
152 |
| -// console.log(data); |
153 |
| - |
154 |
| - console.log(util.inspect(data, {showHidden: false, depth: null, colors: true})) |
155 |
| -} |
| 113 | +// return <CommandContext>{ |
| 114 | +// outputJson, |
| 115 | +// outputMarkdown, |
| 116 | +// before, |
| 117 | +// after, |
| 118 | +// preview |
| 119 | +// } |
| 120 | +// } |
| 121 | + |
| 122 | +// async function getDiffScan( |
| 123 | +// before: string, |
| 124 | +// after: string, |
| 125 | +// spinner: Ora, |
| 126 | +// apiKey: string |
| 127 | +// ): Promise<void> { |
| 128 | +// // const socketSdk = await setupSdk(apiKey) |
| 129 | +// // const result = await handleApiCall( |
| 130 | +// // socketSdk.getOrgFullScanList(orgSlug, input), |
| 131 | +// // 'Listing scans' |
| 132 | +// // ) |
| 133 | + |
| 134 | +// const response = await fetch(`https://api.socket.dev/v0/orgs/SocketDev/full-scans/diff?before=${before}&after=${after}&preview`, { |
| 135 | +// method: 'GET', |
| 136 | +// headers: { |
| 137 | +// 'Authorization': 'Basic ' + btoa(`${apiKey}:${apiKey}`) |
| 138 | +// } |
| 139 | +// }); |
| 140 | +// const data = await response.json(); |
| 141 | + |
| 142 | +// // if (!result.success) { |
| 143 | +// // handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner) |
| 144 | +// // return |
| 145 | +// // } |
| 146 | +// spinner.stop() |
| 147 | + |
| 148 | +// // before: dfc4cf0c-aefd-4081-9e4e-7385257f26e2 |
| 149 | +// // after: 922e45f5-8a7b-4b16-95a5-e98ad00470f1 |
| 150 | + |
| 151 | +// console.log(`\n Diff scan result: \n`) |
| 152 | +// // console.log(data); |
| 153 | + |
| 154 | +// console.log(util.inspect(data, {showHidden: false, depth: null, colors: true})) |
| 155 | +// } |
0 commit comments