-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcmd-audit-log.ts
106 lines (91 loc) · 2.66 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
101
102
103
104
105
106
import { stripIndents } from 'common-tags'
import colors from 'yoctocolors-cjs'
import { logger } from '@socketsecurity/registry/lib/logger'
import { handleAuditLog } from './handle-audit-log'
import constants from '../../constants'
import { commonFlags, outputFlags } from '../../flags'
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 [orgSlug = ''] = cli.input
if (!orgSlug) {
// Use exit status of 2 to indicate incorrect usage, generally invalid
// options or missing arguments.
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
process.exitCode = 2
logger.fail(
stripIndents`
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}
`
)
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)
})
}