diff --git a/package.json b/package.json index e28935ce1..aff482298 100644 --- a/package.json +++ b/package.json @@ -220,6 +220,12 @@ "shortTitle": "%containerApps.editEnvironmentVariableName.shortTitle%", "category": "Azure Container Apps" }, + { + "command": "containerApps.editEnvironmentVariableValue", + "title": "%containerApps.editEnvironmentVariableValue.title%", + "shortTitle": "%containerApps.editEnvironmentVariableValue.shortTitle%", + "category": "Azure Container Apps" + }, { "command": "containerApps.editEnvironmentVariables", "title": "%containerApps.editEnvironmentVariables%", @@ -512,10 +518,15 @@ "group": "1@1" }, { - "command": "containerApps.deleteEnvironmentVariable", + "command": "containerApps.editEnvironmentVariableValue", "when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /environmentVariableItem/i", "group": "1@2" }, + { + "command": "containerApps.deleteEnvironmentVariable", + "when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /environmentVariableItem/i", + "group": "2@1" + }, { "command": "containerApps.editScaleRange", "when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /scaleItem/i", diff --git a/package.nls.json b/package.nls.json index a093e6bfd..c0ecc08b7 100644 --- a/package.nls.json +++ b/package.nls.json @@ -15,6 +15,8 @@ "containerApps.addEnvironmentVariable": "Add Environment Variable...", "containerApps.editEnvironmentVariableName.title": "Edit Environment Variable Name...", "containerApps.editEnvironmentVariableName.shortTitle": "Edit Name...", + "containerApps.editEnvironmentVariableValue.title": "Edit Environment Variable Value...", + "containerApps.editEnvironmentVariableValue.shortTitle": "Edit Value...", "containerApps.editEnvironmentVariables": "Edit Environment Variables (.env)...", "containerApps.deleteEnvironmentVariable.title": "Delete Environment Variable...", "containerApps.deleteEnvironmentVariable.shortTitle": "Delete...", diff --git a/src/commands/environmentVariables/editEnvironmentVariable/EnvironmentVariableEditDraftStep.ts b/src/commands/environmentVariables/editEnvironmentVariable/EnvironmentVariableEditDraftStep.ts index 9eaedc642..f85ea1248 100644 --- a/src/commands/environmentVariables/editEnvironmentVariable/EnvironmentVariableEditDraftStep.ts +++ b/src/commands/environmentVariables/editEnvironmentVariable/EnvironmentVariableEditDraftStep.ts @@ -10,6 +10,7 @@ import { type ContainerAppItem } from "../../../tree/ContainerAppItem"; import { type RevisionsItemModel } from "../../../tree/revisionManagement/RevisionItem"; import { localize } from "../../../utils/localize"; import { RevisionDraftUpdateBaseStep } from "../../revisionDraft/RevisionDraftUpdateBaseStep"; +import { EnvironmentVariableType } from "../addEnvironmentVariable/EnvironmentVariableTypeListStep"; import { type EnvironmentVariableEditContext } from "./EnvironmentVariableEditContext"; export class EnvironmentVariableEditDraftStep extends RevisionDraftUpdateBaseStep { @@ -28,8 +29,19 @@ export class EnvironmentVariableEditDraftStep env.name === context.environmentVariable.name)); environmentVariable.name = context.newEnvironmentVariableName ?? environmentVariable.name; - environmentVariable.value = context.newEnvironmentVariableManualInput ?? environmentVariable.value; - environmentVariable.secretRef = context.secretName ?? environmentVariable.secretRef; + + switch (context.newEnvironmentVariableType) { + case EnvironmentVariableType.ManualInput: + environmentVariable.value = context.newEnvironmentVariableManualInput ?? ''; + environmentVariable.secretRef = undefined; + break; + case EnvironmentVariableType.SecretRef: + environmentVariable.value = ''; // The server doesn't allow this value to be undefined + environmentVariable.secretRef = context.secretName; + break; + default: + // If no new environmentVariableValue, do nothing (i.e. keep the existing values the same) + } await this.updateRevisionDraftWithTemplate(context); } diff --git a/src/commands/environmentVariables/editEnvironmentVariable/editEnvironmentVariableValue.ts b/src/commands/environmentVariables/editEnvironmentVariable/editEnvironmentVariableValue.ts new file mode 100644 index 000000000..5651f2829 --- /dev/null +++ b/src/commands/environmentVariables/editEnvironmentVariable/editEnvironmentVariableValue.ts @@ -0,0 +1,56 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Microsoft Corporation. All rights reserved. +* Licensed under the MIT License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import { AzureWizard, createSubscriptionContext, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; +import { type EnvironmentVariableItem } from "../../../tree/containers/EnvironmentVariableItem"; +import { createActivityContext } from "../../../utils/activityUtils"; +import { getManagedEnvironmentFromContainerApp } from "../../../utils/getResourceUtils"; +import { getVerifyProvidersStep } from "../../../utils/getVerifyProvidersStep"; +import { localize } from "../../../utils/localize"; +import { pickEnvironmentVariable } from "../../../utils/pickItem/pickEnvironmentVariables"; +import { isTemplateItemEditable, TemplateItemNotEditableError } from "../../../utils/revisionDraftUtils"; +import { RevisionDraftDeployPromptStep } from "../../revisionDraft/RevisionDraftDeployPromptStep"; +import { EnvironmentVariableTypeListStep } from "../addEnvironmentVariable/EnvironmentVariableTypeListStep"; +import { type EnvironmentVariableEditContext } from "./EnvironmentVariableEditContext"; +import { EnvironmentVariableEditDraftStep } from "./EnvironmentVariableEditDraftStep"; + +export async function editEnvironmentVariableValue(context: IActionContext, node?: EnvironmentVariableItem): Promise { + const item: EnvironmentVariableItem = node ?? await pickEnvironmentVariable(context, { autoSelectDraft: true }); + const { subscription, containerApp } = item; + + if (!isTemplateItemEditable(item)) { + throw new TemplateItemNotEditableError(item); + } + + const subscriptionContext: ISubscriptionContext = createSubscriptionContext(subscription); + + const wizardContext: EnvironmentVariableEditContext = { + ...context, + ...subscriptionContext, + ...await createActivityContext(), + subscription, + managedEnvironment: await getManagedEnvironmentFromContainerApp({ ...context, ...subscriptionContext }, containerApp), + containerApp, + containersIdx: item.containersIdx, + environmentVariable: item.envVariable, + isDraftCommand: true, + }; + wizardContext.telemetry.properties.revisionMode = containerApp.revisionsMode; + + const wizard: AzureWizard = new AzureWizard(wizardContext, { + title: localize('editEnvironmentVariableValue', 'Edit environment variable value for "{0}" (draft)', wizardContext.environmentVariable.name), + promptSteps: [ + new EnvironmentVariableTypeListStep(), + new RevisionDraftDeployPromptStep(), + ], + executeSteps: [ + getVerifyProvidersStep(), + new EnvironmentVariableEditDraftStep(item), + ], + }); + + await wizard.prompt(); + await wizard.execute(); +} diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index dbd775e9a..e89df6dac 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -19,6 +19,7 @@ import { editContainerApp } from './editContainerApp'; import { addEnvironmentVariable } from './environmentVariables/addEnvironmentVariable/addEnvironmentVariable'; import { deleteEnvironmentVariable } from './environmentVariables/deleteEnvironmentVariable/deleteEnvironmentVariable'; import { editEnvironmentVariableName } from './environmentVariables/editEnvironmentVariable/editEnvironmentVariableName'; +import { editEnvironmentVariableValue } from './environmentVariables/editEnvironmentVariable/editEnvironmentVariableValue'; import { editEnvironmentVariables } from './environmentVariables/editEnvironmentVariables/editEnvironmentVariables'; import { connectToGitHub } from './gitHub/connectToGitHub/connectToGitHub'; import { disconnectRepo } from './gitHub/disconnectRepo/disconnectRepo'; @@ -76,6 +77,7 @@ export function registerCommands(): void { // environment variables registerCommandWithTreeNodeUnwrapping('containerApps.addEnvironmentVariable', addEnvironmentVariable); registerCommandWithTreeNodeUnwrapping('containerApps.editEnvironmentVariableName', editEnvironmentVariableName); + registerCommandWithTreeNodeUnwrapping('containerApps.editEnvironmentVariableValue', editEnvironmentVariableValue); registerCommandWithTreeNodeUnwrapping('containerApps.editEnvironmentVariables', editEnvironmentVariables); registerCommandWithTreeNodeUnwrapping('containerApps.deleteEnvironmentVariable', deleteEnvironmentVariable); @@ -117,7 +119,7 @@ export function registerCommands(): void { registerCommandWithTreeNodeUnwrapping('containerApps.addScaleRule', addScaleRule); registerCommandWithTreeNodeUnwrapping('containerApps.deleteScaleRule', deleteScaleRule); - //log streaming + // log streaming registerCommandWithTreeNodeUnwrapping('containerApps.startStreamingLogs', startStreamingLogs); registerCommandWithTreeNodeUnwrapping('containerApps.stopStreamingLogs', stopStreamingLogs);