-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.ts
60 lines (52 loc) · 1.8 KB
/
create.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
import {Command, ux} from '@oclif/core'
import {
commonUniversalBrokerArgs,
commonUniversalBrokerDeploymentId,
commonApiRelatedArgs,
getCommonIds,
} from '../../common/args.js'
import {printFormattedJSON} from '../../utils/display.js'
import {connectionsData} from '../../command-helpers/connections/flags.js'
import {createConnectionForDeployment} from '../../api/connections.js'
export default class Connections extends Command {
static args = {
...commonUniversalBrokerArgs(),
...commonUniversalBrokerDeploymentId(true),
...commonApiRelatedArgs,
}
static flags = {
...connectionsData,
}
static description = 'Universal Broker Connections - Create operation'
static examples = [
`[with exported TENANT_ID,INSTALL_ID]`,
`<%= config.bin %> <%= command.id %> DEPLOYMENT_ID --type github`,
`[inline TENANT_ID,INSTALL_ID]`,
`<%= config.bin %> <%= command.id %> TENANT_ID INSTALL_ID DEPLOYMENT_ID --type github`,
]
async run(): Promise<string> {
this.log('\n' + ux.colorize('red', Connections.description))
const {args, flags} = await this.parse(Connections)
const {tenantId, installId} = getCommonIds(args)
const attributes = structuredClone(flags) as Omit<typeof flags, 'name' | 'type'>
delete attributes.name
delete attributes.type
const connection = await createConnectionForDeployment(
tenantId,
installId,
args.deploymentId,
flags.name,
flags.type,
attributes,
)
const connectionResponse = connection.data
this.log(
ux.colorize(
'cyan',
`Creating Universal Broker Connection for Deployment ${args.deploymentId} for Tenant ${tenantId}, Install ${installId}`,
),
)
this.log(printFormattedJSON(connectionResponse))
return JSON.stringify(connectionResponse)
}
}