MCPcopy Index your code
hub / github.com/SmartThingsCommunity/smartthings-cli / handler

Function handler

src/commands/schema/update.ts:61–115  ·  view source on GitHub ↗
(argv: ArgumentsCamelCase<CommandArgs>)

Source from the content-addressed store, hash-verified

59 .epilog(buildEpilog({ command, apiDocs: 'putAppsByEndpointAppId' }))
60
61const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
62 const command = await apiOrganizationCommand(argv)
63
64 const id = await chooseSchemaApp(command, argv.id)
65
66 const { schemaApp: original, organizationWasUpdated } = await getSchemaAppEnsuringOrganization(command, id, argv)
67 if (original.certificationStatus === 'wwst' ||
68 original.certificationStatus === 'cst' ||
69 original.certificationStatus === 'review') {
70 const cancelMsgBase =
71 'Schema Apps that have already been certified cannot be updated via the CLI'
72 const cancelMsg = organizationWasUpdated
73 ? cancelMsgBase + ' so further updates are not possible.'
74 : cancelMsgBase + '.'
75 return cancelCommand(cancelMsg)
76 }
77
78 const getInputFromUser = async (): Promise<SchemaAppRequest> =>
79 getSchemaAppUpdateFromUser(command, original, !!argv.dryRun)
80
81 // We use `inputItem` instead of `inputAndOutputItem` because the API does not return the
82 // updated object like most other APIs.
83 const [request, defaultIOFormat] =
84 await inputItem<SchemaAppWithOrganization>(argv, userInputProcessor(getInputFromUser))
85 if (argv.dryRun) {
86 const outputFormatter = buildOutputFormatter(command.flags, command.cliConfig, defaultIOFormat)
87 await writeOutput(outputFormatter(request), command.flags.output)
88 return
89 }
90
91 if (argv.authorize) {
92 if (request.hostingType === 'lambda') {
93 if (request.lambdaArn) {
94 await addSchemaPermission(request.lambdaArn, argv.principal, argv.statement)
95 }
96 if (request.lambdaArnAP) {
97 await addSchemaPermission(request.lambdaArnAP, argv.principal, argv.statement)
98 }
99 if (request.lambdaArnCN) {
100 await addSchemaPermission(request.lambdaArnCN, argv.principal, argv.statement)
101 }
102 if (request.lambdaArnEU) {
103 await addSchemaPermission(request.lambdaArnEU, argv.principal, argv.statement)
104 }
105 } else {
106 return fatalError('Authorization is not applicable to WebHook schema connectors.')
107 }
108 }
109 const { organizationId, ...data } = request
110 const result = await command.client.schema.update(id, data, organizationId)
111 if (result.status !== 'success') {
112 return fatalError(`Error ${result.status} updating ${id}.`)
113 }
114 console.log(`Schema ${id} updated.`)
115}
116
117const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler }
118export default cmd

Callers

nothing calls this directly

Calls 8

apiOrganizationCommandFunction · 0.85
cancelCommandFunction · 0.85
userInputProcessorFunction · 0.85
buildOutputFormatterFunction · 0.85
writeOutputFunction · 0.85
addSchemaPermissionFunction · 0.85
fatalErrorFunction · 0.85

Tested by

no test coverage detected