|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { AzureWizardExecuteStep, nonNullProp } from "@microsoft/vscode-azext-utils"; |
| 7 | +import type { Progress } from "vscode"; |
| 8 | +import { ext } from "../../../extensionVariables"; |
| 9 | +import { ContainerAppModel, getContainerEnvelopeWithSecrets } from "../../../tree/ContainerAppItem"; |
| 10 | +import { localize } from "../../../utils/localize"; |
| 11 | +import { updateContainerApp } from "../../../utils/updateContainerApp"; |
| 12 | +import type { ISecretContext } from "../ISecretContext"; |
| 13 | + |
| 14 | +export class SecretCreateStep extends AzureWizardExecuteStep<ISecretContext> { |
| 15 | + public priority: number = 200; |
| 16 | + |
| 17 | + public async execute(context: ISecretContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> { |
| 18 | + const containerApp: ContainerAppModel = nonNullProp(context, 'containerApp'); |
| 19 | + const containerAppEnvelope = await getContainerEnvelopeWithSecrets(context, context.subscription, containerApp); |
| 20 | + |
| 21 | + containerAppEnvelope.configuration.secrets ||= []; |
| 22 | + containerAppEnvelope.configuration.secrets.push({ |
| 23 | + name: context.newSecretName, |
| 24 | + value: context.newSecretValue |
| 25 | + }); |
| 26 | + |
| 27 | + const addSecret: string = localize('addSecret', 'Add secret "{0}" to container app "{1}"', context.newSecretName, containerApp.name); |
| 28 | + const creatingSecret: string = localize('creatingSecret', 'Creating secret...'); |
| 29 | + |
| 30 | + context.activityTitle = addSecret; |
| 31 | + progress.report({ message: creatingSecret }); |
| 32 | + |
| 33 | + await updateContainerApp(context, context.subscription, containerAppEnvelope); |
| 34 | + |
| 35 | + const addedSecret: string = localize('addedSecret', 'Added secret "{0}" to container app "{1}"', context.newSecretName, containerApp.name); |
| 36 | + ext.outputChannel.appendLog(addedSecret); |
| 37 | + } |
| 38 | + |
| 39 | + public shouldExecute(context: ISecretContext): boolean { |
| 40 | + return !!context.newSecretName && !!context.newSecretValue; |
| 41 | + } |
| 42 | +} |
0 commit comments