-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-credentials.ts
80 lines (69 loc) · 2.08 KB
/
client-credentials.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
import { clientCredentials } from '@roll-network/api'
import { printTable } from 'console-table-printer'
import inquirer from 'inquirer'
import { ClientPool } from '@roll-network/api-client'
import { SDKPool, InteractionType } from '@roll-network/auth-sdk'
import { clientCredentialsConfig } from './config.js'
import logger from './logger.js'
const sdkPool = new SDKPool(clientCredentialsConfig)
export const getClient = async () => {
try {
await sdkPool.getSDK(InteractionType.Server).generateToken()
const clientPool = new ClientPool(
{ baseUrl: process.env.INTERNAL_API_URL, redactErrorData: false },
sdkPool,
)
const answers = await inquirer.prompt([
{
type: 'input',
name: 'id',
message: 'Client ID',
},
])
const client = await clientCredentials.getClient(
clientPool.getClient(InteractionType.Server).call,
answers,
)
printTable([client])
} catch (error) {
logger.fatal(JSON.stringify(error as Error))
}
}
export const getClients = async () => {
try {
await sdkPool.getSDK(InteractionType.Server).generateToken()
const clientPool = new ClientPool(
{ baseUrl: process.env.INTERNAL_API_URL, redactErrorData: false },
sdkPool,
)
const clients = await clientCredentials.getClients(
clientPool.getClient(InteractionType.Server).call,
)
printTable(clients)
} catch (error) {
logger.fatal(JSON.stringify(error as Error))
}
}
export const generateClientSecret = async () => {
try {
await sdkPool.getSDK(InteractionType.Server).generateToken()
const clientPool = new ClientPool(
{ baseUrl: process.env.INTERNAL_API_URL, redactErrorData: false },
sdkPool,
)
const answers = await inquirer.prompt([
{
type: 'input',
name: 'id',
message: 'Client ID',
},
])
const secret = await clientCredentials.generateClientSecret(
clientPool.getClient(InteractionType.Server).call,
answers,
)
printTable([secret])
} catch (error) {
logger.fatal(JSON.stringify(error as Error))
}
}