Skip to content

Commit

Permalink
Add static methods and export AppServicePlanRedundancyStep (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 authored Jul 19, 2024
1 parent 682442f commit f951f64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions appservice/src/createAppService/AppServicePlanRedundancyStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class AppServicePlanRedundancyStep extends AzureWizardPromptStep<IAppServ
}

// TODO(ccastrotrejo): This will be changed to use orgdomain with WI 12845265 once georegions API is updated with ANT78.
private isZoneRedundancyEnabled(location: string): boolean {
public static isZoneRedundancySupportedLocation(location: string): boolean {
const zoneRedundancySupportedLocations = [
'westus2',
'westus3',
Expand All @@ -46,25 +46,37 @@ export class AppServicePlanRedundancyStep extends AzureWizardPromptStep<IAppServ
'eastus2euap',
];

location = location.replace(/\s/, "").toLowerCase(); // Todo: Replace with LocationListStep's `generalizeLocationName` once exported and released
return zoneRedundancySupportedLocations.includes(location);
}

private isAllowedServicePlan(newPlanSku: SkuDescription): boolean {
const { family } = newPlanSku;
const allowedServicePlan = [
public static isZoneRedundancySupportedServicePlan(newPlanSkuOrFamily: SkuDescription | string): boolean {
const allowedServicePlans: string[] = [
'Pv2',
'Pv3',
'WS',
];

return !!family && allowedServicePlan.includes(family);
let family: string;
if ((newPlanSkuOrFamily as SkuDescription)?.family) {
// Nullish coallescing operator should be logically unnecessary, but helps TS compiler understand that this value won't be undefined
family = (newPlanSkuOrFamily as SkuDescription).family ?? '';
} else {
family = newPlanSkuOrFamily as string;
}

return allowedServicePlans.includes(family);
}

public static isZoneRedundancySupported(location: string, newPlanSkuOrFamily: SkuDescription | string): boolean {
return this.isZoneRedundancySupportedLocation(location) && this.isZoneRedundancySupportedServicePlan(newPlanSkuOrFamily);
}

public shouldPrompt(context: AppServiceWizardContext): boolean {
const { customLocation, _location, plan, newPlanSku } = context;
const { name } = _location || {};
if (plan === undefined && customLocation === undefined && name && newPlanSku) {
return this.isZoneRedundancyEnabled(name) && this.isAllowedServicePlan(newPlanSku);
return AppServicePlanRedundancyStep.isZoneRedundancySupported(name, newPlanSku);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion appservice/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './createAppService/AppInsightsListStep';
export { AppKind, WebsiteOS } from './createAppService/AppKind';
export * from './createAppService/AppServicePlanCreateStep';
export * from './createAppService/AppServicePlanListStep';
export * from './createAppService/AppServicePlanRedundancyStep';
export * from './createAppService/AppServicePlanSkuStep';
export * from './createAppService/CustomLocationListStep';
export * from './createAppService/IAppServiceWizardContext';
Expand Down Expand Up @@ -49,4 +50,3 @@ export * from './tree/LogFilesTreeItem';
export * from './tree/SiteFilesTreeItem';
export * from './tryGetSiteResource';
export * from './utils/azureClients';

0 comments on commit f951f64

Please sign in to comment.