-
Notifications
You must be signed in to change notification settings - Fork 12
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 deleteEnvironmentVariable
command
#798
Open
MicroFish91
wants to merge
3
commits into
mwf/mature-lime
Choose a base branch
from
mwf/running-coffee
base: mwf/mature-lime
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...mmands/environmentVariables/deleteEnvironmentVariable/EnvironmentVariableDeleteContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type EnvironmentVar } from "@azure/arm-appcontainers"; | ||
import { type SetTelemetryProps } from "../../../telemetry/SetTelemetryProps"; | ||
import { type ContainerUpdateTelemetryProps as TelemetryProps } from "../../../telemetry/commandTelemetryProps"; | ||
import { type EnvironmentVariablesBaseContext } from "../EnvironmentVariablesContext"; | ||
|
||
export interface EnvironmentVariableDeleteBaseContext extends EnvironmentVariablesBaseContext { | ||
// Require the environment variable upfront so we can delete | ||
environmentVariable: EnvironmentVar; | ||
} | ||
|
||
export type EnvironmentVariableDeleteContext = EnvironmentVariableDeleteBaseContext & SetTelemetryProps<TelemetryProps>; |
34 changes: 34 additions & 0 deletions
34
...ands/environmentVariables/deleteEnvironmentVariable/EnvironmentVariableDeleteDraftStep.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type Container } from "@azure/arm-appcontainers"; | ||
import { type Progress } from "vscode"; | ||
import { type ContainerAppItem } from "../../../tree/ContainerAppItem"; | ||
import { type RevisionsItemModel } from "../../../tree/revisionManagement/RevisionItem"; | ||
import { localize } from "../../../utils/localize"; | ||
import { RevisionDraftUpdateBaseStep } from "../../revisionDraft/RevisionDraftUpdateBaseStep"; | ||
import { type EnvironmentVariableDeleteContext } from "./EnvironmentVariableDeleteContext"; | ||
|
||
export class EnvironmentVariableDeleteDraftStep<T extends EnvironmentVariableDeleteContext> extends RevisionDraftUpdateBaseStep<T> { | ||
public priority: number = 590; | ||
|
||
constructor(baseItem: ContainerAppItem | RevisionsItemModel) { | ||
super(baseItem); | ||
} | ||
|
||
public async execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> { | ||
progress.report({ message: localize('deletingEnv', 'Deleting environment variable (draft)...') }); | ||
this.revisionDraftTemplate.containers ??= []; | ||
|
||
const container: Container = this.revisionDraftTemplate.containers[context.containersIdx] ?? {}; | ||
container.env = container.env?.filter(env => env.name !== context.environmentVariable.name) ?? []; | ||
|
||
await this.updateRevisionDraftWithTemplate(context); | ||
} | ||
|
||
public shouldExecute(context: T): boolean { | ||
return !!context.environmentVariable; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/commands/environmentVariables/deleteEnvironmentVariable/deleteEnvironmentVariable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { type Revision } from "@azure/arm-appcontainers"; | ||
import { AzureWizard, createSubscriptionContext, DeleteConfirmationStep, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; | ||
import { type ContainerAppModel } from "../../../tree/ContainerAppItem"; | ||
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 { getParentResourceFromItem, isTemplateItemEditable, TemplateItemNotEditableError } from "../../../utils/revisionDraftUtils"; | ||
import { type EnvironmentVariableDeleteContext } from "./EnvironmentVariableDeleteContext"; | ||
import { EnvironmentVariableDeleteDraftStep } from "./EnvironmentVariableDeleteDraftStep"; | ||
|
||
export async function deleteEnvironmentVariable(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 parentResource: ContainerAppModel | Revision = getParentResourceFromItem(item); | ||
|
||
const wizardContext: EnvironmentVariableDeleteContext = { | ||
...context, | ||
...subscriptionContext, | ||
...await createActivityContext(), | ||
subscription, | ||
managedEnvironment: await getManagedEnvironmentFromContainerApp({ ...context, ...subscriptionContext }, containerApp), | ||
containerApp, | ||
containersIdx: item.containersIdx, | ||
environmentVariable: item.envVariable, | ||
}; | ||
wizardContext.telemetry.properties.revisionMode = containerApp.revisionsMode; | ||
|
||
const confirmMessage: string = localize('confirmDeleteEnv', 'Are you sure you want to delete environment variable "{0}" (draft)?', item.envVariable.name); | ||
const wizard: AzureWizard<EnvironmentVariableDeleteContext> = new AzureWizard(wizardContext, { | ||
title: localize('deleteEnvironmentVariable', 'Delete environment variable "{0}" from "{1}" (draft)', item.envVariable.name, parentResource.name), | ||
promptSteps: [ | ||
new DeleteConfirmationStep(confirmMessage), | ||
], | ||
executeSteps: [ | ||
getVerifyProvidersStep<EnvironmentVariableDeleteContext>(), | ||
new EnvironmentVariableDeleteDraftStep(item), | ||
], | ||
}); | ||
|
||
await wizard.prompt(); | ||
await wizard.execute(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this just be part of the edit context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, which of the edit contexts are you referring to?