Skip to content

Commit

Permalink
♻️ Use trivial Azure location validator: at least one lowercase lette…
Browse files Browse the repository at this point in the history
…r followed by 0 or 1 digits then 0 or more lowercase letters)
  • Loading branch information
jemrobinson committed Jul 21, 2023
1 parent f0a2b03 commit d2705b1
Showing 1 changed file with 9 additions and 89 deletions.
98 changes: 9 additions & 89 deletions data_safe_haven/functions/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ def validate_aad_guid(aad_guid: Optional[str]) -> Optional[str]:
return aad_guid


def validate_azure_location(azure_location: Optional[str]) -> Optional[str]:
if azure_location is not None:
if not re.match(r"^[a-z]+[0-9]?[a-z]*$", azure_location):
raise typer.BadParameter(
"Expected valid Azure location, for example 'uksouth'"
)
return azure_location


def validate_azure_vm_sku(azure_vm_sku: Optional[str]) -> Optional[str]:
if azure_vm_sku is not None:
if not re.match(r"^(Standard|Basic)_\w+$", azure_vm_sku):
Expand Down Expand Up @@ -49,95 +58,6 @@ def validate_ip_address(
raise typer.BadParameter("Expected valid IPv4 address, for example '1.1.1.1'")


def validate_azure_location(location: Optional[str]) -> Optional[str]:
if not location:
return None
if location in (
"asia",
"asiapacific",
"australia",
"australiacentral",
"australiacentral2",
"australiaeast",
"australiasoutheast",
"brazil",
"brazilsouth",
"brazilsoutheast",
"brazilus",
"canada",
"canadacentral",
"canadaeast",
"centralindia",
"centralus",
"centraluseuap",
"centralusstage",
"devfabric",
"eastasia",
"eastasiastage",
"eastus",
"eastus2",
"eastus2euap",
"eastus2stage",
"eastusstage",
"eastusstg",
"europe",
"france",
"francecentral",
"francesouth",
"germany",
"germanynorth",
"germanywestcentral",
"global",
"india",
"japan",
"japaneast",
"japanwest",
"jioindiacentral",
"jioindiawest",
"korea",
"koreacentral",
"koreasouth",
"northcentralus",
"northcentralusstage",
"northeurope",
"norway",
"norwayeast",
"norwaywest",
"qatarcentral",
"singapore",
"southafrica",
"southafricanorth",
"southafricawest",
"southcentralus",
"southcentralusstage",
"southeastasia",
"southeastasiastage",
"southindia",
"swedencentral",
"switzerland",
"switzerlandnorth",
"switzerlandwest",
"uae",
"uaecentral",
"uaenorth",
"uk",
"uksouth",
"ukwest",
"unitedstates",
"unitedstateseuap",
"westcentralus",
"westeurope",
"westindia",
"westus",
"westus2",
"westus2stage",
"westus3",
"westusstage",
):
return location
raise typer.BadParameter("Expected valid Azure location, for example 'uksouth'")


def validate_timezone(timezone: Optional[str]) -> Optional[str]:
if timezone is not None:
if timezone not in pytz.all_timezones:
Expand Down

0 comments on commit d2705b1

Please sign in to comment.