-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.ts
101 lines (93 loc) · 3.89 KB
/
migrate.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
import {ux} from '@oclif/core'
import {commonApiRelatedArgs} from '../../../common/args.js'
import {confirm, input} from '@inquirer/prompts'
import {BaseCommand} from '../../../base-command.js'
import {nonSourceIntegrations} from '../../../command-helpers/connections/type-params-mapping.js'
import {
createIntegrationForConnection,
disconnectIntegrationForOrgIdAndIntegrationId,
} from '../../../api/integrations.js'
import {validatedInput, ValidationType} from '../../../utils/input-validation.js'
export default class Workflows extends BaseCommand<typeof Workflows> {
public static enableJsonFlag = true
static args = {
...commonApiRelatedArgs,
}
static description = 'Universal Broker - Existing Connection Migration Workflow'
static examples = [`<%= config.bin %> <%= command.id %>`]
async run(): Promise<string> {
try {
this.log('\n' + ux.colorize('red', Workflows.description))
const {installId, tenantId, appInstalledOnOrgId} = await this.setupFlow()
this.log(ux.colorize('cyan', `Now using Tenant ID ${tenantId} and Install ID ${installId}.\n`))
const deploymentId = await this.selectDeployment(tenantId, installId, appInstalledOnOrgId)
this.log(ux.colorize('cyan', `Now using Deployment ${deploymentId}.\n`))
// this.log(ux.colorize('cyan', `Let's create a ${connectionType} connection now.\n`))
const selectedConnection = await this.selectConnection(tenantId, installId, deploymentId)
this.log(
ux.colorize(
'cyan',
`Selected Connection ID ${selectedConnection.id}. Ready to migrate integration to use this Connection.\n`,
),
)
let orgId
let integrationId
if (!nonSourceIntegrations.has(selectedConnection.type)) {
orgId = await validatedInput({message: 'Enter the OrgID you want to migrate.'}, ValidationType.UUID)
integrationId = await validatedInput(
{
message: `Enter the integrationID you want to migrate. Must be of type ${selectedConnection.type}`,
},
ValidationType.UUID,
)
} else {
this.log(
ux.colorize(
'red',
`Integration Migration is currently not supported for this connection type ${selectedConnection.type}.`,
),
)
this.log(
ux.colorize(
'red',
`Follow normal integration procedure (workflows connections integrate) and simply turn off your existing Broker to enable Universal Broker connection.`,
),
)
return ''
}
const isMigrationConfirmed = await confirm({
message: `[CAUTION!] Are you sure you want to migrate integration ${integrationId ? integrationId + ' ' : ''}(type ${selectedConnection.type}) in org ${orgId}? Existing service could be impacted.`,
})
if (!isMigrationConfirmed) {
this.log(ux.colorize('red', 'Cancelling Connection migration.'))
return ''
}
await disconnectIntegrationForOrgIdAndIntegrationId(orgId, integrationId, selectedConnection.type)
const connectionIntegration = await createIntegrationForConnection(
tenantId,
selectedConnection.id,
selectedConnection.type,
orgId,
integrationId,
)
if (connectionIntegration.errors) {
this.error(ux.colorize('red', JSON.stringify(connectionIntegration.errors)))
}
this.log(
ux.colorize(
'cyan',
`Connection ${connectionIntegration.data.id} (type: ${selectedConnection.type}) integrated with integration ${integrationId} on Org ${orgId}.`,
),
)
this.log(ux.colorize('red', 'Connection Migrate Workflow completed.'))
} catch (error: any) {
if (error.name === 'ExitPromptError') {
this.log(ux.colorize('red', 'Goodbye.'))
} else {
// Handle other errors or rethrow
throw error
}
}
return JSON.stringify('')
}
}