Skip to content

Commit 3a603d2

Browse files
committed
Allow optional license reporting of scan report
1 parent f60b83b commit 3a603d2

File tree

8 files changed

+74
-173
lines changed

8 files changed

+74
-173
lines changed

src/commands/scan/cmd-scan-report.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ describe('socket scan report', async () => {
2424
$ socket scan report <org slug> <scan ID> [path to output file]
2525
2626
API Token Requirements
27-
- Quota: 3 units
27+
- Quota: 2 units
2828
- Permissions: full-scans:list security-policy:read
2929
3030
Options
3131
--dryRun Do input validation for a command and exit 0 when input is ok
3232
--fold Fold reported alerts to some degree
3333
--help Print this help
3434
--json Output result as json
35+
--license Also report the license policy status. Default: false
3536
--markdown Output result as markdown
3637
--reportLevel Which policy level alerts should be reported
37-
--security Report the security policy status. Default: true
3838
--short Report only the healthy status
3939
4040
By default the result is a nested object that looks like this:
@@ -47,7 +47,8 @@ describe('socket scan report', async () => {
4747
Short responses: JSON: \`{healthy:bool}\`, markdown: \`healthy = bool\`, text: \`OK/ERR\`
4848
4949
Examples
50-
$ socket scan report FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json --fold=version"
50+
$ socket scan report FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json --fold=version
51+
$ socket scan report FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 --license --markdown --short"
5152
`
5253
)
5354
expect(`\n ${stderr}`).toMatchInlineSnapshot(`

src/commands/scan/cmd-scan-report.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,18 @@ const config: CliCommandConfig = {
3939
default: false,
4040
description: 'Report only the healthy status'
4141
},
42-
// license: {
43-
// type: 'boolean',
44-
// default: true,
45-
// description: 'Report the license policy status. Default: true'
46-
// },
47-
security: {
42+
license: {
4843
type: 'boolean',
49-
default: true,
50-
description: 'Report the security policy status. Default: true'
44+
default: false,
45+
description: 'Also report the license policy status. Default: false'
5146
}
5247
},
5348
help: (command, config) => `
5449
Usage
5550
$ ${command} <org slug> <scan ID> [path to output file]
5651
5752
API Token Requirements
58-
- Quota: 3 units
53+
- Quota: 2 units
5954
- Permissions: full-scans:list security-policy:read
6055
6156
Options
@@ -72,6 +67,7 @@ const config: CliCommandConfig = {
7267
7368
Examples
7469
$ ${command} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json --fold=version
70+
$ ${command} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 --license --markdown --short
7571
`
7672
}
7773

@@ -96,10 +92,9 @@ async function run(
9692
const {
9793
fold = 'none',
9894
json,
99-
// license,
95+
license,
10096
markdown,
101-
reportLevel = 'warn',
102-
security
97+
reportLevel = 'warn'
10398
} = cli.flags
10499

105100
const defaultOrgSlug = getConfigValue('defaultOrg')
@@ -150,8 +145,7 @@ async function run(
150145
await handleScanReport({
151146
orgSlug,
152147
scanId: scanId,
153-
includeLicensePolicy: false, // !!license,
154-
includeSecurityPolicy: typeof security === 'boolean' ? security : true,
148+
includeLicensePolicy: !!license,
155149
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
156150
filePath: file,
157151
fold: fold as 'none' | 'file' | 'pkg' | 'version',

src/commands/scan/fetch-report-data.ts

Lines changed: 23 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,20 @@ import type { components } from '@socketsecurity/sdk/types/api'
1515
/**
1616
* This fetches all the relevant pieces of data to generate a report, given a
1717
* full scan ID.
18-
* It can optionally only fetch the security or license side of things.
1918
*/
2019
export async function fetchReportData(
2120
orgSlug: string,
2221
scanId: string,
23-
// includeLicensePolicy: boolean,
24-
includeSecurityPolicy: boolean
22+
includeLicensePolicy: boolean
2523
): Promise<
2624
| {
2725
ok: true
2826
scan: Array<components['schemas']['SocketArtifact']>
29-
// licensePolicy: undefined | SocketSdkReturnType<'getOrgSecurityPolicy'>
3027
securityPolicy: undefined | SocketSdkReturnType<'getOrgSecurityPolicy'>
3128
}
3229
| {
3330
ok: false
3431
scan: undefined
35-
// licensePolicy: undefined
3632
securityPolicy: undefined
3733
}
3834
> {
@@ -46,7 +42,6 @@ export async function fetchReportData(
4642
const sockSdk = await setupSdk(apiToken)
4743

4844
let haveScan = false
49-
// let haveLicensePolicy = false
5045
let haveSecurityPolicy = false
5146

5247
// Lazily access constants.spinner.
@@ -55,54 +50,32 @@ export async function fetchReportData(
5550
function updateProgress() {
5651
const needs = [
5752
!haveScan ? 'scan' : undefined,
58-
// includeLicensePolicy && !haveLicensePolicy ? 'license policy' : undefined,
59-
includeSecurityPolicy && !haveSecurityPolicy
60-
? 'security policy'
61-
: undefined
53+
!haveSecurityPolicy ? 'security policy' : undefined
6254
].filter(Boolean)
63-
if (needs.length > 2) {
64-
// .toOxford()
65-
needs[needs.length - 1] = `and ${needs[needs.length - 1]}`
66-
}
6755
const haves = [
6856
haveScan ? 'scan' : undefined,
69-
// includeLicensePolicy && haveLicensePolicy ? 'license policy' : undefined,
70-
includeSecurityPolicy && haveSecurityPolicy
71-
? 'security policy'
72-
: undefined
57+
haveSecurityPolicy ? 'security policy' : undefined
7358
].filter(Boolean)
74-
if (haves.length > 2) {
75-
// .toOxford()
76-
haves[haves.length - 1] = `and ${haves[haves.length - 1]}`
77-
}
7859

7960
if (needs.length) {
8061
spinner.start(
81-
`Fetching ${needs.join(needs.length > 2 ? ', ' : ' and ')}...${haves.length ? ` Completed fetching ${haves.join(haves.length > 2 ? ', ' : ' and ')}.` : ''}`
62+
`Fetching ${needs.join(' and ')}...${haves.length ? ` Completed fetching ${haves.join(' and ')}.` : ''}`
8263
)
8364
} else {
84-
spinner.successAndStop(
85-
`Completed fetching ${haves.join(haves.length > 2 ? ', ' : ' and ')}.`
86-
)
65+
spinner.successAndStop(`Completed fetching ${haves.join(' and ')}.`)
8766
}
8867
}
8968

9069
updateProgress()
9170

92-
// @ts-ignore
93-
const [
94-
scan,
95-
// licensePolicyMaybe,
96-
securityPolicyMaybe
97-
]: [
71+
const [scan, securityPolicyMaybe]: [
9872
undefined | Array<components['schemas']['SocketArtifact']>,
99-
// undefined | SocketSdkResultType<'getOrgSecurityPolicy'>,
100-
undefined | SocketSdkResultType<'getOrgSecurityPolicy'>
73+
SocketSdkResultType<'getOrgSecurityPolicy'>
10174
] = await Promise.all([
10275
(async () => {
10376
try {
10477
const response = await queryApi(
105-
`orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}`,
78+
`orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}${includeLicensePolicy ? '?include_license_details=true' : ''}`,
10679
apiToken
10780
)
10881

@@ -138,26 +111,12 @@ export async function fetchReportData(
138111
throw e
139112
}
140113
})(),
141-
// includeLicensePolicy &&
142-
// (async () => {
143-
// const r = await sockSdk.getOrgSecurityPolicy(orgSlug)
144-
// haveLicensePolicy = true
145-
// updateProgress()
146-
// return await handleApiCall(
147-
// r,
148-
// "looking up organization's license policy"
149-
// )
150-
// })(),
151-
includeSecurityPolicy &&
152-
(async () => {
153-
const r = await sockSdk.getOrgSecurityPolicy(orgSlug)
154-
haveSecurityPolicy = true
155-
updateProgress()
156-
return await handleApiCall(
157-
r,
158-
"looking up organization's security policy"
159-
)
160-
})()
114+
(async () => {
115+
const r = await sockSdk.getOrgSecurityPolicy(orgSlug)
116+
haveSecurityPolicy = true
117+
updateProgress()
118+
return await handleApiCall(r, "looking up organization's security policy")
119+
})()
161120
]).finally(() => spinner.stop())
162121

163122
if (!Array.isArray(scan)) {
@@ -166,50 +125,27 @@ export async function fetchReportData(
166125
return {
167126
ok: false,
168127
scan: undefined,
169-
// licensePolicy: undefined,
170128
securityPolicy: undefined
171129
}
172130
}
173131

174-
// // Note: security->license once the api ships in the sdk
175-
// let licensePolicy: undefined | SocketSdkReturnType<'getOrgSecurityPolicy'> =
176-
// undefined
177-
// if (includeLicensePolicy) {
178-
// if (licensePolicyMaybe && licensePolicyMaybe.success) {
179-
// licensePolicy = licensePolicyMaybe
180-
// } else {
181-
// logger.error('Was unable to fetch license policy, bailing')
182-
// process.exitCode = 1
183-
// return {
184-
// ok: false,
185-
// scan: undefined,
186-
// licensePolicy: undefined,
187-
// securityPolicy: undefined
188-
// }
189-
// }
190-
// }
191-
192132
let securityPolicy: undefined | SocketSdkReturnType<'getOrgSecurityPolicy'> =
193133
undefined
194-
if (includeSecurityPolicy) {
195-
if (securityPolicyMaybe && securityPolicyMaybe.success) {
196-
securityPolicy = securityPolicyMaybe
197-
} else {
198-
logger.error('Was unable to fetch security policy, bailing')
199-
process.exitCode = 1
200-
return {
201-
ok: false,
202-
scan: undefined,
203-
// licensePolicy: undefined,
204-
securityPolicy: undefined
205-
}
134+
if (securityPolicyMaybe && securityPolicyMaybe.success) {
135+
securityPolicy = securityPolicyMaybe
136+
} else {
137+
logger.error('Was unable to fetch security policy, bailing')
138+
process.exitCode = 1
139+
return {
140+
ok: false,
141+
scan: undefined,
142+
securityPolicy: undefined
206143
}
207144
}
208145

209146
return {
210147
ok: true,
211148
scan,
212-
// licensePolicy,
213149
securityPolicy
214150
}
215151
}

0 commit comments

Comments
 (0)