mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add Azure region enum and helper methods to azurecore (#10776)
* Add Azure region enum and helper methods * change module definition * Add comments * fix names * Optional param
This commit is contained in:
58
extensions/azurecore/src/azurecore.d.ts
vendored
58
extensions/azurecore/src/azurecore.d.ts
vendored
@@ -11,12 +11,64 @@ import { azureResource } from './azureResource/azure-resource';
|
|||||||
* IMPORTANT: THIS IS NOT A HARD DEFINITION unlike vscode; therefore no enums or classes should be defined here
|
* IMPORTANT: THIS IS NOT A HARD DEFINITION unlike vscode; therefore no enums or classes should be defined here
|
||||||
* (const enums get evaluated when typescript -> javascript so those are fine)
|
* (const enums get evaluated when typescript -> javascript so those are fine)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
export const enum extension {
|
export const enum extension {
|
||||||
name = 'Microsoft.azurecore'
|
name = 'Microsoft.azurecore'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of the Azure datacenter regions. See https://docs.microsoft.com/dotnet/api/microsoft.azure.management.resourcemanager.fluent.core.region
|
||||||
|
*/
|
||||||
|
export const enum AzureRegion {
|
||||||
|
australiacentral = 'australiacentral',
|
||||||
|
australiacentral2 = 'australiacentral2',
|
||||||
|
australiaeast = 'australiaeast',
|
||||||
|
australiasoutheast = 'australiasoutheast',
|
||||||
|
brazilsouth = 'brazilsouth',
|
||||||
|
canadacentral = 'canadacentral',
|
||||||
|
canadaeast = 'canadaeast',
|
||||||
|
centralindia = 'centralindia',
|
||||||
|
centralus = 'centralus',
|
||||||
|
eastasia = 'eastasia',
|
||||||
|
eastus = 'eastus',
|
||||||
|
eastus2 = 'eastus2',
|
||||||
|
francecentral = 'francecentral',
|
||||||
|
francesouth = 'francesouth',
|
||||||
|
germanynorth = 'germanynorth',
|
||||||
|
germanywestcentral = 'germanywestcentral',
|
||||||
|
japaneast = 'japaneast',
|
||||||
|
japanwest = 'japanwest',
|
||||||
|
koreacentral = 'koreacentral',
|
||||||
|
koreasouth = 'koreasouth',
|
||||||
|
northcentralus = 'northcentralus',
|
||||||
|
northeurope = 'northeurope',
|
||||||
|
norwayeast = 'norwayeast',
|
||||||
|
norwaywest = 'norwaywest',
|
||||||
|
southafricanorth = 'southafricanorth',
|
||||||
|
southafricawest = 'southafricawest',
|
||||||
|
southcentralus = 'southcentralus',
|
||||||
|
southeastasia = 'southeastasia',
|
||||||
|
southindia = 'southindia',
|
||||||
|
switzerlandnorth = 'switzerlandnorth',
|
||||||
|
switzerlandwest = 'switzerlandwest',
|
||||||
|
uaecentral = 'uaecentral',
|
||||||
|
uaenorth = 'uaenorth',
|
||||||
|
uksouth = 'uksouth',
|
||||||
|
ukwest = 'ukwest',
|
||||||
|
westcentralus = 'westcentralus',
|
||||||
|
westeurope = 'westeurope',
|
||||||
|
westindia = 'westindia',
|
||||||
|
westus = 'westus',
|
||||||
|
westus2 = 'westus2',
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IExtension {
|
||||||
|
/**
|
||||||
|
* Converts a region value (@see AzureRegion) into the localized Display Name
|
||||||
|
* @param region The region value
|
||||||
|
*/
|
||||||
|
getRegionDisplayName(region?: string): string;
|
||||||
|
provideResources(): azureResource.IAzureResourceProvider[];
|
||||||
|
}
|
||||||
|
|
||||||
export type GetSubscriptionsResult = { subscriptions: azureResource.AzureResourceSubscription[], errors: Error[] };
|
export type GetSubscriptionsResult = { subscriptions: azureResource.AzureResourceSubscription[], errors: Error[] };
|
||||||
export type GetResourceGroupsResult = { resourceGroups: azureResource.AzureResourceResourceGroup[], errors: Error[] };
|
export type GetResourceGroupsResult = { resourceGroups: azureResource.AzureResourceResourceGroup[], errors: Error[] };
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import { SqlInstanceArcResourceService } from './azureResource/providers/sqlinst
|
|||||||
import { PostgresServerArcProvider } from './azureResource/providers/postgresArcServer/postgresServerProvider';
|
import { PostgresServerArcProvider } from './azureResource/providers/postgresArcServer/postgresServerProvider';
|
||||||
import { PostgresServerArcService } from './azureResource/providers/postgresArcServer/postgresServerService';
|
import { PostgresServerArcService } from './azureResource/providers/postgresArcServer/postgresServerService';
|
||||||
import { azureResource } from './azureResource/azure-resource';
|
import { azureResource } from './azureResource/azure-resource';
|
||||||
|
import * as azurecore from './azurecore';
|
||||||
|
import * as utils from './utils';
|
||||||
import * as loc from './localizedConstants';
|
import * as loc from './localizedConstants';
|
||||||
|
|
||||||
let extensionContext: vscode.ExtensionContext;
|
let extensionContext: vscode.ExtensionContext;
|
||||||
@@ -62,7 +64,7 @@ function pushDisposable(disposable: vscode.Disposable): void {
|
|||||||
|
|
||||||
// this method is called when your extension is activated
|
// this method is called when your extension is activated
|
||||||
// your extension is activated the very first time the command is executed
|
// your extension is activated the very first time the command is executed
|
||||||
export async function activate(context: vscode.ExtensionContext) {
|
export async function activate(context: vscode.ExtensionContext): Promise<azurecore.IExtension> {
|
||||||
extensionContext = context;
|
extensionContext = context;
|
||||||
const apiWrapper = new ApiWrapper();
|
const apiWrapper = new ApiWrapper();
|
||||||
let appContext = new AppContext(extensionContext, apiWrapper);
|
let appContext = new AppContext(extensionContext, apiWrapper);
|
||||||
@@ -82,7 +84,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
registerAzureResourceCommands(appContext, azureResourceTree);
|
registerAzureResourceCommands(appContext, azureResourceTree);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
provideResources() {
|
provideResources(): azureResource.IAzureResourceProvider[] {
|
||||||
const arcFeaturedEnabled = apiWrapper.getExtensionConfiguration().get('enableArcFeatures');
|
const arcFeaturedEnabled = apiWrapper.getExtensionConfiguration().get('enableArcFeatures');
|
||||||
const providers: azureResource.IAzureResourceProvider[] = [
|
const providers: azureResource.IAzureResourceProvider[] = [
|
||||||
new AzureResourceDatabaseServerProvider(new AzureResourceDatabaseServerService(), apiWrapper, extensionContext),
|
new AzureResourceDatabaseServerProvider(new AzureResourceDatabaseServerService(), apiWrapper, extensionContext),
|
||||||
@@ -97,7 +99,8 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return providers;
|
return providers;
|
||||||
}
|
},
|
||||||
|
getRegionDisplayName: utils.getRegionDisplayName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,3 +10,44 @@ export const extensionName = localize('azurecore.extensionName', "Azure Accounts
|
|||||||
|
|
||||||
export const requiresReload = localize('azurecore.requiresReload', "Modifying this setting requires reloading the window for all changes to take effect.");
|
export const requiresReload = localize('azurecore.requiresReload', "Modifying this setting requires reloading the window for all changes to take effect.");
|
||||||
export const reload = localize('azurecore.reload', "Reload");
|
export const reload = localize('azurecore.reload', "Reload");
|
||||||
|
|
||||||
|
export const australiaCentral = localize('azurecore.australiacentral', "Australia Central");
|
||||||
|
export const australiaCentral2 = localize('azurecore.australiacentral2', "Australia Central 2");
|
||||||
|
export const australiaEast = localize('azurecore.australiaeast', "Australia East");
|
||||||
|
export const australiaSouthEast = localize('azurecore.australiasoutheast', "Australia Southeast");
|
||||||
|
export const brazilSouth = localize('azurecore.brazilsouth', "Brazil South");
|
||||||
|
export const canadaCentral = localize('azurecore.canadacentral', "Canada Central");
|
||||||
|
export const canadaEast = localize('azurecore.canadaeast', "Canada East");
|
||||||
|
export const centralIndia = localize('azurecore.centralindia', "Central India");
|
||||||
|
export const centralUS = localize('azurecore.centralus', "Central US");
|
||||||
|
export const eastAsia = localize('azurecore.eastasia', "East Asia");
|
||||||
|
export const eastUS = localize('azurecore.eastus', "East US");
|
||||||
|
export const eastUS2 = localize('azurecore.eastus2', "East US 2");
|
||||||
|
export const franceCentral = localize('azurecore.francecentral', "France Central");
|
||||||
|
export const franceSouth = localize('azurecore.francesouth', "France South");
|
||||||
|
export const germanyNorth = localize('azurecore.germanynorth', "Germany North");
|
||||||
|
export const germanyWestCentral = localize('azurecore.germanywestcentral', "Germany West Central");
|
||||||
|
export const japanEast = localize('azurecore.japaneast', "Japan East");
|
||||||
|
export const japanWest = localize('azurecore.japanwest', "Japan West");
|
||||||
|
export const koreaCentral = localize('azurecore.koreacentral', "Korea Central");
|
||||||
|
export const koreaSouth = localize('azurecore.koreasouth', "Korea South");
|
||||||
|
export const northCentralUS = localize('azurecore.northcentralus', "North Central US");
|
||||||
|
export const northEurope = localize('azurecore.northeurope', "North Europe");
|
||||||
|
export const norwayEast = localize('azurecore.norwayeast', "Norway East");
|
||||||
|
export const norwayWest = localize('azurecore.norwaywest', "Norway West");
|
||||||
|
export const southAfricaNorth = localize('azurecore.southafricanorth', "South Africa North");
|
||||||
|
export const southAfricaWest = localize('azurecore.southafricawest', "South Africa West");
|
||||||
|
export const southCentralUS = localize('azurecore.southcentralus', "South Central US");
|
||||||
|
export const southEastAsia = localize('azurecore.southeastasia', "Southeast Asia");
|
||||||
|
export const southIndia = localize('azurecore.southindia', "South India");
|
||||||
|
export const switzerlandNorth = localize('azurecore.switzerlandnorth', "Switzerland North");
|
||||||
|
export const switzerlandWest = localize('azurecore.switzerlandwest', "Switzerland West");
|
||||||
|
export const uaeCentral = localize('azurecore.uaecentral', "UAE Central");
|
||||||
|
export const uaeNorth = localize('azurecore.uaenorth', "UAE North");
|
||||||
|
export const ukSouth = localize('azurecore.uksouth', "UK South");
|
||||||
|
export const ukWest = localize('azurecore.ukwest', "UK West");
|
||||||
|
export const westCentralUS = localize('azurecore.westcentralus', "West Central US");
|
||||||
|
export const westEurope = localize('azurecore.westeurope', "West Europe");
|
||||||
|
export const westIndia = localize('azurecore.westindia', "West India");
|
||||||
|
export const westUS = localize('azurecore.westus', "West US");
|
||||||
|
export const westUS2 = localize('azurecore.westus2', "West US 2");
|
||||||
|
|||||||
39
extensions/azurecore/src/test/utils.test.ts
Normal file
39
extensions/azurecore/src/test/utils.test.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import * as should from 'should';
|
||||||
|
import 'mocha';
|
||||||
|
import { getRegionDisplayName } from '../utils';
|
||||||
|
import { AzureRegion } from '../azurecore';
|
||||||
|
import * as loc from '../localizedConstants';
|
||||||
|
|
||||||
|
describe('Azurecore Utils Tests', function (): void {
|
||||||
|
describe('getRegionDisplayName', function(): void {
|
||||||
|
it('Returns expected name for valid regions', function(): void {
|
||||||
|
should(getRegionDisplayName(AzureRegion.eastasia)).equal(loc.eastAsia);
|
||||||
|
should(getRegionDisplayName(AzureRegion.japaneast)).equal(loc.japanEast);
|
||||||
|
should(getRegionDisplayName(AzureRegion.westus2)).equal(loc.westUS2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Returns expected name for region regardless of case', function(): void {
|
||||||
|
should(getRegionDisplayName(AzureRegion.eastasia.toLocaleUpperCase())).equal(loc.eastAsia);
|
||||||
|
should(getRegionDisplayName(AzureRegion.japaneast.toLocaleUpperCase())).equal(loc.japanEast);
|
||||||
|
should(getRegionDisplayName(AzureRegion.westus2.toLocaleUpperCase())).equal(loc.westUS2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Returns original name for unknown region', function(): void {
|
||||||
|
const unknownRegion = 'UnknownRegion';
|
||||||
|
should(getRegionDisplayName(unknownRegion)).equal(unknownRegion);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Returns empty name for undefined region', function(): void {
|
||||||
|
should(getRegionDisplayName(undefined)).equal('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Returns empty name for empty region', function(): void {
|
||||||
|
should(getRegionDisplayName('')).equal('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
100
extensions/azurecore/src/utils.ts
Normal file
100
extensions/azurecore/src/utils.ts
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import * as loc from './localizedConstants';
|
||||||
|
import { AzureRegion } from './azurecore';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a region value (@see AzureRegion) into the localized Display Name
|
||||||
|
* @param region The region value
|
||||||
|
*/
|
||||||
|
export function getRegionDisplayName(region?: string): string {
|
||||||
|
region = (region ?? '');
|
||||||
|
|
||||||
|
switch (region.toLocaleLowerCase()) {
|
||||||
|
case AzureRegion.australiacentral:
|
||||||
|
return loc.australiaCentral;
|
||||||
|
case AzureRegion.australiacentral2:
|
||||||
|
return loc.australiaCentral2;
|
||||||
|
case AzureRegion.australiaeast:
|
||||||
|
return loc.australiaEast;
|
||||||
|
case AzureRegion.australiasoutheast:
|
||||||
|
return loc.australiaSouthEast;
|
||||||
|
case AzureRegion.brazilsouth:
|
||||||
|
return loc.brazilSouth;
|
||||||
|
case AzureRegion.canadacentral:
|
||||||
|
return loc.canadaCentral;
|
||||||
|
case AzureRegion.canadaeast:
|
||||||
|
return loc.canadaEast;
|
||||||
|
case AzureRegion.centralindia:
|
||||||
|
return loc.centralIndia;
|
||||||
|
case AzureRegion.centralus:
|
||||||
|
return loc.centralUS;
|
||||||
|
case AzureRegion.eastasia:
|
||||||
|
return loc.eastAsia;
|
||||||
|
case AzureRegion.eastus:
|
||||||
|
return loc.eastUS;
|
||||||
|
case AzureRegion.eastus2:
|
||||||
|
return loc.eastUS2;
|
||||||
|
case AzureRegion.francecentral:
|
||||||
|
return loc.franceCentral;
|
||||||
|
case AzureRegion.francesouth:
|
||||||
|
return loc.franceSouth;
|
||||||
|
case AzureRegion.germanynorth:
|
||||||
|
return loc.germanyNorth;
|
||||||
|
case AzureRegion.germanywestcentral:
|
||||||
|
return loc.germanyWestCentral;
|
||||||
|
case AzureRegion.japaneast:
|
||||||
|
return loc.japanEast;
|
||||||
|
case AzureRegion.japanwest:
|
||||||
|
return loc.japanWest;
|
||||||
|
case AzureRegion.koreacentral:
|
||||||
|
return loc.koreaCentral;
|
||||||
|
case AzureRegion.koreasouth:
|
||||||
|
return loc.koreaSouth;
|
||||||
|
case AzureRegion.northcentralus:
|
||||||
|
return loc.northCentralUS;
|
||||||
|
case AzureRegion.northeurope:
|
||||||
|
return loc.northEurope;
|
||||||
|
case AzureRegion.norwayeast:
|
||||||
|
return loc.norwayEast;
|
||||||
|
case AzureRegion.norwaywest:
|
||||||
|
return loc.norwayWest;
|
||||||
|
case AzureRegion.southafricanorth:
|
||||||
|
return loc.southAfricaNorth;
|
||||||
|
case AzureRegion.southafricawest:
|
||||||
|
return loc.southAfricaWest;
|
||||||
|
case AzureRegion.southcentralus:
|
||||||
|
return loc.southCentralUS;
|
||||||
|
case AzureRegion.southeastasia:
|
||||||
|
return loc.southEastAsia;
|
||||||
|
case AzureRegion.southindia:
|
||||||
|
return loc.southIndia;
|
||||||
|
case AzureRegion.switzerlandnorth:
|
||||||
|
return loc.switzerlandNorth;
|
||||||
|
case AzureRegion.switzerlandwest:
|
||||||
|
return loc.switzerlandWest;
|
||||||
|
case AzureRegion.uaecentral:
|
||||||
|
return loc.uaeCentral;
|
||||||
|
case AzureRegion.uaenorth:
|
||||||
|
return loc.uaeNorth;
|
||||||
|
case AzureRegion.uksouth:
|
||||||
|
return loc.ukSouth;
|
||||||
|
case AzureRegion.ukwest:
|
||||||
|
return loc.ukWest;
|
||||||
|
case AzureRegion.westcentralus:
|
||||||
|
return loc.westCentralUS;
|
||||||
|
case AzureRegion.westeurope:
|
||||||
|
return loc.westEurope;
|
||||||
|
case AzureRegion.westindia:
|
||||||
|
return loc.westIndia;
|
||||||
|
case AzureRegion.westus:
|
||||||
|
return loc.westUS;
|
||||||
|
case AzureRegion.westus2:
|
||||||
|
return loc.westUS2;
|
||||||
|
}
|
||||||
|
console.warn(`Unknown Azure region ${region}`);
|
||||||
|
return region;
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import { createSection, getDropdownComponent, InputComponentInfo, InputComponent
|
|||||||
import { WizardPageBase } from '../../wizardPageBase';
|
import { WizardPageBase } from '../../wizardPageBase';
|
||||||
import { AksName_VariableName, Location_VariableName, ResourceGroup_VariableName, SubscriptionId_VariableName, VMCount_VariableName, VMSize_VariableName } from '../constants';
|
import { AksName_VariableName, Location_VariableName, ResourceGroup_VariableName, SubscriptionId_VariableName, VMCount_VariableName, VMSize_VariableName } from '../constants';
|
||||||
import { DeployClusterWizard } from '../deployClusterWizard';
|
import { DeployClusterWizard } from '../deployClusterWizard';
|
||||||
|
import { AzureRegion } from '../../../../../azurecore/src/azurecore';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
const MissingRequiredInformationErrorMessage = localize('deployCluster.MissingRequiredInfoError', "Please fill out the required fields marked with red asterisks.");
|
const MissingRequiredInformationErrorMessage = localize('deployCluster.MissingRequiredInfoError', "Please fill out the required fields marked with red asterisks.");
|
||||||
|
|
||||||
@@ -60,20 +61,20 @@ export class AzureSettingsPage extends WizardPageBase<DeployClusterWizard> {
|
|||||||
label: localize('deployCluster.Location', "Location"),
|
label: localize('deployCluster.Location', "Location"),
|
||||||
required: true,
|
required: true,
|
||||||
variableName: Location_VariableName,
|
variableName: Location_VariableName,
|
||||||
defaultValue: 'eastus',
|
defaultValue: AzureRegion.eastus,
|
||||||
editable: true,
|
editable: true,
|
||||||
// The options are not localized because this is an editable dropdown,
|
// The options are not localized because this is an editable dropdown,
|
||||||
// It would cause confusion to user about what value to type in, if they type in the localized value, we don't know how to process.
|
// It would cause confusion to user about what value to type in, if they type in the localized value, we don't know how to process.
|
||||||
options: [
|
options: [
|
||||||
'centralus',
|
AzureRegion.centralus,
|
||||||
'eastus',
|
AzureRegion.eastus,
|
||||||
'eastus2',
|
AzureRegion.eastus2,
|
||||||
'northcentralus',
|
AzureRegion.northcentralus,
|
||||||
'southcentralus',
|
AzureRegion.southcentralus,
|
||||||
'westus',
|
AzureRegion.westus,
|
||||||
'westus2',
|
AzureRegion.westus2,
|
||||||
'canadacentral',
|
AzureRegion.canadacentral,
|
||||||
'canadaeast'
|
AzureRegion.canadaeast
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
type: FieldType.ReadonlyText,
|
type: FieldType.ReadonlyText,
|
||||||
|
|||||||
@@ -930,9 +930,9 @@ async function handleSelectedSubscriptionChanged(context: AzureAccountFieldConte
|
|||||||
* Map of known Azure location friendly names to their internal names
|
* Map of known Azure location friendly names to their internal names
|
||||||
*/
|
*/
|
||||||
const knownAzureLocationNameMappings = new Map<string, string>([
|
const knownAzureLocationNameMappings = new Map<string, string>([
|
||||||
['East US', 'eastus'],
|
['East US', azurecore.AzureRegion.eastus],
|
||||||
['East US 2', 'eastus2'],
|
['East US 2', azurecore.AzureRegion.eastus2],
|
||||||
['Central US', 'centralus']
|
['Central US', azurecore.AzureRegion.centralus]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user