Skip to content

Commit f61558e

Browse files
authored
Add shortcut to switching to sovereign cloud within the tenant view (#926)
* initial commit * changes * rename and small changes * add new auth * fix bugs and add support for sovereign clouds * fix bugs * add another refresh * merge conflict fix * removed tools files and other requested changes * change * add in sovereign cloud shortcut * Add default * another change * add back comma * open setting on custom
1 parent 66eba91 commit f61558e

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@
260260
"title": "%azureTenantsView.signInToTenant%",
261261
"category": "Azure",
262262
"icon": "$(sign-in)"
263+
},
264+
{
265+
"command": "azureTenantsView.configureSovereignCloud",
266+
"title": "%azureTenantsView.configureSovereignCloud%",
267+
"category": "Azure",
268+
"icon": "$(gear)"
263269
}
264270
],
265271
"viewsContainers": {
@@ -399,6 +405,11 @@
399405
"when": "view == azureWorkspace",
400406
"group": "navigation@1"
401407
},
408+
{
409+
"command": "azureTenantsView.configureSovereignCloud",
410+
"when": "view == azureTenantsView",
411+
"group": "navigation@2"
412+
},
402413
{
403414
"command": "azureTenantsView.addAccount",
404415
"when": "view == azureTenantsView",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"azureWorkspace.refresh": "Refresh Workspace",
1919
"azureTenantsView.refresh": "Refresh Accounts & Tenants",
2020
"azureTenantsView.signInToTenant": "Sign in to Tenant",
21+
"azureTenantsView.configureSovereignCloud": "Configure Sovereign Cloud",
2122
"azureResourceGroups.selectedSubscriptions": "Selected Subscriptions",
2223
"azureResourceGroups.revealResource": "Reveal Resource",
2324
"azureResourceGroups.viewProperties": "View Properties",

src/commands/registerCommands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { reviewIssues } from './helpAndFeedback/reviewIssues';
2929
import { installExtension } from './installExtension';
3030
import { openInPortal } from './openInPortal';
3131
import { revealResource } from './revealResource';
32+
import { configureSovereignCloud } from './sovereignCloud/configureSovereignCloud';
3233
import { editTags } from './tags/editTags';
3334
import { viewProperties } from './viewProperties';
3435

@@ -117,6 +118,8 @@ export function registerCommands(): void {
117118
});
118119

119120
registerCommand('azureWorkspace.loadMore', async (context: IActionContext, node: AzExtTreeItem) => await ext.workspaceTree.loadMore(node, context));
121+
122+
registerCommand('azureTenantsView.configureSovereignCloud', configureSovereignCloud);
120123
}
121124

122125
async function handleAzExtTreeItemRefresh(context: IActionContext, node?: ResourceGroupsItem): Promise<void> {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { IActionContext } from "@microsoft/vscode-azext-utils";
7+
8+
export interface ConfigureSovereignCloudContext extends IActionContext {
9+
sovereignCloud?: string;
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { AzureWizardPromptStep, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
7+
import { ConfigureSovereignCloudContext } from "./ConfigureSovereignCloudContext";
8+
9+
export class SovereignCloudListStep extends AzureWizardPromptStep<ConfigureSovereignCloudContext> {
10+
public async prompt(context: ConfigureSovereignCloudContext): Promise<void> {
11+
const picks: IAzureQuickPickItem<string>[] = [
12+
{ label: 'Azure (Default)', data: '' },
13+
{ label: 'Azure China', data: 'ChinaCloud' },
14+
{ label: 'Azure US Government', data: 'USGovernment' },
15+
{ label: 'A custom Microsoft Sovereign Cloud', data: 'custom' }
16+
]
17+
18+
context.sovereignCloud = (await context.ui.showQuickPick(picks, { placeHolder: 'Select a sovereign cloud' })).data;
19+
}
20+
21+
public shouldPrompt(context: ConfigureSovereignCloudContext): boolean {
22+
return !context.sovereignCloud;
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
7+
import * as vscode from 'vscode';
8+
import { settingUtils } from "../../utils/settingUtils";
9+
import { ConfigureSovereignCloudContext } from "./ConfigureSovereignCloudContext";
10+
11+
export class SovereignCloudSetStep extends AzureWizardExecuteStep<ConfigureSovereignCloudContext> {
12+
public priority: number = 10;
13+
14+
public async execute(context: ConfigureSovereignCloudContext): Promise<void> {
15+
if (context.sovereignCloud === 'custom') {
16+
await vscode.commands.executeCommand('workbench.action.openSettings', 'microsoft-sovereign-cloud');
17+
} else {
18+
await settingUtils.updateGlobalSetting('environment', context.sovereignCloud, 'microsoft-sovereign-cloud');
19+
}
20+
}
21+
22+
public shouldExecute(): boolean {
23+
return true;
24+
}
25+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { AzureWizard } from "@microsoft/vscode-azext-utils";
7+
import { ext } from "../../extensionVariables";
8+
import { localize } from "../../utils/localize";
9+
import { ConfigureSovereignCloudContext } from "./ConfigureSovereignCloudContext";
10+
import { SovereignCloudListStep } from "./SovereignCloudListStep";
11+
import { SovereignCloudSetStep } from "./SovereignCloudSetStep";
12+
13+
export async function configureSovereignCloud(context: ConfigureSovereignCloudContext): Promise<void> {
14+
const wizardContext: ConfigureSovereignCloudContext = {
15+
...context,
16+
};
17+
18+
const title: string = localize('selectSovereignCloud', 'Select Sovereign Cloud');
19+
20+
const wizard: AzureWizard<ConfigureSovereignCloudContext> = new AzureWizard(wizardContext, {
21+
title,
22+
promptSteps: [new SovereignCloudListStep()],
23+
executeSteps: [new SovereignCloudSetStep()],
24+
});
25+
26+
await wizard.prompt();
27+
await wizard.execute();
28+
29+
// refresh resources and tenant view to accurrately reflect information for the selected sovereign cloud
30+
ext.actions.refreshAzureTree();
31+
ext.actions.refreshTenantTree();
32+
}

0 commit comments

Comments
 (0)