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