-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaudit.ts
77 lines (66 loc) · 2.47 KB
/
audit.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
import Command from '../../core/command'
import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities'
import buildOutput from '../../core/content-type/audit'
import { getStack, getUsers, getContentType } from '../../utils'
export default class AuditCommand extends Command {
static description = 'Display recent changes to a Content Type'
static examples = [
'$ csdx content-type:audit --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page"',
'$ csdx content-type:audit --alias "management token" --content-type "home_page"'
]
static flags: any = {
stack: flags.string({
char: 's',
description: 'Stack UID',
exclusive: ['token-alias', 'alias'],
parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key'])
}),
'stack-api-key': flags.string({
char: 'k',
description: 'Stack API Key',
exclusive: ['token-alias', 'alias']
}),
'token-alias': flags.string({
char: 'a',
description: 'Management token alias',
parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias'])
}),
alias: flags.string({
char: 'a',
description: 'Alias of the management token'
}),
'content-type': flags.string({
char: 'c',
description: 'Content Type UID',
required: true,
parse: printFlagDeprecation(['-c'], ['--content-type'])
})
}
async run() {
try {
const { flags } = await this.parse(AuditCommand)
this.setup(flags)
this.contentTypeManagementClient = await managementSDKClient({
host: this.cmaHost,
'X-CS-CLI': this.context?.analyticsInfo
})
const spinner = cliux.loaderV2(Command.RequestDataMessage)
await getContentType({
managementSdk: this.contentTypeManagementClient,
apiKey: this.apiKey,
uid: flags['content-type'],
spinner
});
const [stack, audit, users] = await Promise.all([
getStack(this.contentTypeManagementClient, this.apiKey, spinner),
this.client.getContentTypeAuditLogs(this.apiKey, flags['content-type'], spinner),
getUsers(this.contentTypeManagementClient, this.apiKey, spinner)
])
cliux.loaderV2('', spinner)
const output = buildOutput(audit.logs, users)
this.printOutput(output, 'Audit Logs', flags['content-type'], stack.name)
} catch (error: any) {
this.error(error, { exit: 1, suggestions: error.suggestions })
}
}
}