-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget-token.ts
36 lines (31 loc) · 1.26 KB
/
get-token.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
import { ux, Flags } from '@oclif/core'
import { z } from 'zod'
import { BaseCommand } from '../../common/base-command.js'
import { promptRequiredParameters } from '../../common/prompts.js'
import { INPUT_LIMIT } from '../../common/validators.js'
import { TokenDto } from '../../services/affinidi/iam/iam.api.js'
import { iamService } from '../../services/affinidi/iam/service.js'
export class GetToken extends BaseCommand<typeof GetToken> {
static summary = 'Gets the details of a Personal Access Token (PAT)'
static examples = [
'<%= config.bin %> <%= command.id %> -i <uuid>',
'<%= config.bin %> <%= command.id %> --token-id <uuid>',
]
static flags = {
'token-id': Flags.string({
char: 'i',
summary: 'ID of the Personal Access Token',
}),
}
public async run(): Promise<TokenDto> {
const { flags } = await this.parse(GetToken)
const promptFlags = await promptRequiredParameters(['token-id'], flags)
const schema = z.string().max(INPUT_LIMIT).uuid()
const tokenId = schema.parse(promptFlags['token-id'])
ux.action.start('Fetching Personal Access Token details')
const out = await iamService.getToken(tokenId)
ux.action.stop('Fetched successfully!')
if (!this.jsonEnabled()) this.logJson(out)
return out
}
}