Skip to content

Commit

Permalink
Add additional validation rule
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 committed Feb 4, 2025
1 parent ad82851 commit 961f1b6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions appservice/src/createAppService/SiteNameStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ export class SiteNameStep extends AzureNameStep<SiteNameStepWizardContext> {

// Todo: Leave reference to GitHub comment
private async asyncValidateSiteName(context: SiteNameStepWizardContext, sdkClient: WebSiteManagementClient, name: string): Promise<string | undefined> {
let validationMessage: string | undefined;
name = name.trim();

let validationMessage: string | undefined;
if (!context.newSiteDomainNameLabelScope || context.newSiteDomainNameLabelScope === DomainNameLabelScope.Global) {
validationMessage ??= await this.asyncValidateGlobalSiteName(sdkClient, name);
}

if (context.newSiteDomainNameLabelScope) {
validationMessage ??= await this.asyncValidateSiteNameByDomainScope(context, context.newSiteDomainNameLabelScope, name, context.resourceGroup?.name ?? context.newResourceGroupName);
validationMessage ??= await this.asyncValidateUniqueARMId(context, sdkClient, name, context.resourceGroup?.name ?? context.newResourceGroupName);
Expand Down Expand Up @@ -179,7 +181,18 @@ export class SiteNameStep extends AzureNameStep<SiteNameStepWizardContext> {
nameAvailable?: boolean;
reason?: string;
};
return !checkNameResponse.nameAvailable ? checkNameResponse.message : undefined;

if (!checkNameResponse.nameAvailable) {
// If site name input is >=47 chars, ignore result of regional CNA because it inherently has a shorter character limit than Global CNA
if (domainNameScope === DomainNameLabelScope.Global && checkNameResponse.message && checkNameResponse.message.length >= 47) {
if (/must be less than \d{2} chars/i.test(checkNameResponse.message)) {
return undefined;
}
}
return checkNameResponse.message;
}

return undefined;
}

private async asyncValidateGlobalSiteName(client: WebSiteManagementClient, name: string): Promise<string | undefined> {
Expand Down

0 comments on commit 961f1b6

Please sign in to comment.