Skip to content

Commit

Permalink
Add shortcut to switching to sovereign cloud within the tenant view (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
motm32 authored Dec 6, 2024
1 parent 66eba91 commit f61558e
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@
"title": "%azureTenantsView.signInToTenant%",
"category": "Azure",
"icon": "$(sign-in)"
},
{
"command": "azureTenantsView.configureSovereignCloud",
"title": "%azureTenantsView.configureSovereignCloud%",
"category": "Azure",
"icon": "$(gear)"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -399,6 +405,11 @@
"when": "view == azureWorkspace",
"group": "navigation@1"
},
{
"command": "azureTenantsView.configureSovereignCloud",
"when": "view == azureTenantsView",
"group": "navigation@2"
},
{
"command": "azureTenantsView.addAccount",
"when": "view == azureTenantsView",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -117,6 +118,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' }
]

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();
}

0 comments on commit f61558e

Please sign in to comment.