-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcmd-audit-log.ts
100 lines (86 loc) · 2.46 KB
/
cmd-audit-log.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { logger } from '@socketsecurity/registry/lib/logger'
import { handleAuditLog } from './handle-audit-log'
import constants from '../../constants'
import { commonFlags, outputFlags } from '../../flags'
import { getConfigValue } from '../../utils/config'
import { handleBadInput } from '../../utils/handle-bad-input'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'
import type { CliCommandConfig } from '../../utils/meow-with-subcommands'
const { DRY_RUN_BAIL_TEXT } = constants
const config: CliCommandConfig = {
commandName: 'audit-log',
description: 'Look up the audit log for an organization',
hidden: false,
flags: {
type: {
type: 'string',
shortFlag: 't',
default: '',
description: 'Type of log event'
},
perPage: {
type: 'number',
shortFlag: 'pp',
default: 30,
description: 'Results per page - default is 30'
},
page: {
type: 'number',
shortFlag: 'p',
default: 1,
description: 'Page number - default is 1'
},
...commonFlags,
...outputFlags
},
help: (command, config) => `
Usage
$ ${command} <org slug>
This feature requires an Enterprise Plan. To learn more about getting access
to this feature and many more, please visit https://socket.dev/pricing
Options
${getFlagListOutput(config.flags, 6)}
Examples
$ ${command} FakeOrg
`
}
export const cmdAuditLog = {
description: config.description,
hidden: config.hidden,
run
}
async function run(
argv: string[] | readonly string[],
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit({
argv,
config,
importMeta,
parentName
})
const { json, markdown, page, perPage, type } = cli.flags
const logType = String(type || '')
const defaultOrgSlug = getConfigValue('defaultOrg')
const orgSlug = defaultOrgSlug || cli.input[0] || ''
const waswasInput = handleBadInput({
test: orgSlug,
message: 'Org name should be the first arg',
pass: 'ok',
fail: 'missing'
})
if (waswasInput) return
if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
return
}
await handleAuditLog({
orgSlug,
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
page: Number(page || 0),
perPage: Number(perPage || 0),
logType: logType.charAt(0).toUpperCase() + logType.slice(1)
})
}