Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editEnvironmentVariableValue command #821

Open
wants to merge 2 commits into
base: mwf/positive-fuchsia
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends EnvironmentVariableEditContext> extends RevisionDraftUpdateBaseStep<T> {
Expand All @@ -28,8 +29,19 @@ export class EnvironmentVariableEditDraftStep<T extends EnvironmentVariableEditC

const environmentVariable: EnvironmentVar = nonNullValue(container.env.find(env => 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> {
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<EnvironmentVariableEditContext> = new AzureWizard(wizardContext, {
title: localize('editEnvironmentVariableValue', 'Edit environment variable value for "{0}" (draft)', wizardContext.environmentVariable.name),
promptSteps: [
new EnvironmentVariableTypeListStep(),
new RevisionDraftDeployPromptStep(),
],
executeSteps: [
getVerifyProvidersStep<EnvironmentVariableEditContext>(),
new EnvironmentVariableEditDraftStep(item),
],
});

await wizard.prompt();
await wizard.execute();
}
4 changes: 3 additions & 1 deletion src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down