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 shortcut to switching to sovereign cloud within the tenant view #926

Merged
merged 19 commits into from
Dec 6, 2024
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@
"title": "%azureTenantsView.signInToTenant%",
"category": "Azure",
"icon": "$(sign-in)"
},
{
"command": "azureTenantsView.configureSovereignCloud",
"title": "%azureTenantsView.configureSovereignCloud%",
"category": "Azure",
"icon": "$(gear)"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -392,6 +398,11 @@
"submenu": "azureWorkspaceCreate",
"when": "view == azureWorkspace",
"group": "navigation@1"
},
{
"command": "azureTenantsView.configureSovereignCloud",
"when": "view == azureTenantsView",
"group": "navigation@2"
}
],
"view/item/context": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"azureWorkspace.refresh": "Refresh Workspace",
"azureTenantsView.refresh": "Refresh Accounts & Tenants",
"azureTenantsView.signInToTenant": "Sign in to Tenant",
"azureTenantsView.configureSovereignCloud": "Configure Sovereign Cloud",
"azureResourceGroups.selectedSubscriptions": "Selected Subscriptions",
"azureResourceGroups.revealResource": "Reveal Resource",
"azureResourceGroups.viewProperties": "View Properties",
Expand Down
3 changes: 3 additions & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { reviewIssues } from './helpAndFeedback/reviewIssues';
import { installExtension } from './installExtension';
import { openInPortal } from './openInPortal';
import { revealResource } from './revealResource';
import { configureSovereignCloud } from './sovereignCloud/configureSovereignCloud';
import { editTags } from './tags/editTags';
import { viewProperties } from './viewProperties';

Expand Down Expand Up @@ -116,6 +117,8 @@ export function registerCommands(): void {
});

registerCommand('azureWorkspace.loadMore', async (context: IActionContext, node: AzExtTreeItem) => await ext.workspaceTree.loadMore(node, context));

registerCommand('azureTenantsView.configureSovereignCloud', configureSovereignCloud);
}

async function handleAzExtTreeItemRefresh(context: IActionContext, node?: ResourceGroupsItem): Promise<void> {
Expand Down
10 changes: 10 additions & 0 deletions src/commands/sovereignCloud/ConfigureSovereignCloudContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IActionContext } from "@microsoft/vscode-azext-utils";

export interface ConfigureSovereignCloudContext extends IActionContext {
sovereignCloud?: string;
}
24 changes: 24 additions & 0 deletions src/commands/sovereignCloud/SovereignCloudListStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardPromptStep, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { ConfigureSovereignCloudContext } from "./ConfigureSovereignCloudContext";

export class SovereignCloudListStep extends AzureWizardPromptStep<ConfigureSovereignCloudContext> {
public async prompt(context: ConfigureSovereignCloudContext): Promise<void> {
const picks: IAzureQuickPickItem<string>[] = [
{ label: 'Azure (Default)', data: '' },
{ label: 'Azure China', data: 'ChinaCloud' },
{ label: 'Azure US Government', data: 'USGovernment' },
{ label: 'A custom Microsoft Sovereign Cloud', data: 'custom' }
Copy link
Member

@alexweininger alexweininger Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they pick custom, should we take them to the setting page so they can actually configure it? We can make this change later though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah we should change the custom since it will cause an error at the moment

]

context.sovereignCloud = (await context.ui.showQuickPick(picks, { placeHolder: 'Select a sovereign cloud' })).data;
}

public shouldPrompt(context: ConfigureSovereignCloudContext): boolean {
return !context.sovereignCloud;
}
}
25 changes: 25 additions & 0 deletions src/commands/sovereignCloud/SovereignCloudSetStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { settingUtils } from "../../utils/settingUtils";
import { ConfigureSovereignCloudContext } from "./ConfigureSovereignCloudContext";

export class SovereignCloudSetStep extends AzureWizardExecuteStep<ConfigureSovereignCloudContext> {
public priority: number = 10;

public async execute(context: ConfigureSovereignCloudContext): Promise<void> {
if (context.sovereignCloud === 'custom') {
await vscode.commands.executeCommand('workbench.action.openSettings', 'microsoft-sovereign-cloud');
} else {
await settingUtils.updateGlobalSetting('environment', context.sovereignCloud, 'microsoft-sovereign-cloud');
}
}

public shouldExecute(): boolean {
return true;
}
}
32 changes: 32 additions & 0 deletions src/commands/sovereignCloud/configureSovereignCloud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizard } from "@microsoft/vscode-azext-utils";
import { ext } from "../../extensionVariables";
import { localize } from "../../utils/localize";
import { ConfigureSovereignCloudContext } from "./ConfigureSovereignCloudContext";
import { SovereignCloudListStep } from "./SovereignCloudListStep";
import { SovereignCloudSetStep } from "./SovereignCloudSetStep";

export async function configureSovereignCloud(context: ConfigureSovereignCloudContext): Promise<void> {
const wizardContext: ConfigureSovereignCloudContext = {
...context,
};

const title: string = localize('selectSovereignCloud', 'Select Sovereign Cloud');

const wizard: AzureWizard<ConfigureSovereignCloudContext> = new AzureWizard(wizardContext, {
title,
promptSteps: [new SovereignCloudListStep()],
executeSteps: [new SovereignCloudSetStep()],
});

await wizard.prompt();
await wizard.execute();

// refresh resources and tenant view to accurrately reflect information for the selected sovereign cloud
ext.actions.refreshAzureTree();
ext.actions.refreshTenantTree();
}
Loading