Skip to content

Commit a0e2a22

Browse files
committed
add validation
1 parent 14084ad commit a0e2a22

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/azure-cli/azure/cli/command_modules/acr/_constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
ACR_AUDIENCE_RESOURCE_NAME = "containerregistry"
3131

32-
# Regex pattern to validate that registry name is alphanumeric and between 5 and 50 characters
32+
# Regex pattern to validate that registry name is alphanumeric and between 5 and 50 characters.
33+
# Dashes "-" are allowed to accomodate for domain name label scope, but is blocked on registry creation "acr create"
3334
ACR_NAME_VALIDATION_REGEX = r'^[a-zA-Z0-9-]{5,50}$'
3435

3536
ALLOWED_TASK_FILE_TYPES = ('.yaml', '.yml', '.toml', '.json', '.sh', '.bash', '.zsh', '.ps1',

src/azure-cli/azure/cli/command_modules/acr/_validators.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ def validate_registry_name(cmd, namespace):
116116
if pos > 0:
117117
logger.warning("The login server endpoint suffix '%s' is automatically omitted.", acr_suffix)
118118
namespace.registry_name = registry[:pos]
119+
# If registry contains - due to Domain Name Label Scope, such as "myregistry-dnlhash123.azurecr.io", strip "-dnlhash123"
120+
dnl_hash = registry.find("-")
121+
if registry and dnl_hash > 0:
122+
logger.warning("The domain name label suffix '%s' is automatically omitted.", registry[dnl_hash:])
123+
namespace.registry_name = registry[:dnl_hash]
124+
119125
registry = namespace.registry_name
120126
if not re.match(ACR_NAME_VALIDATION_REGEX, registry):
121127
raise InvalidArgumentValueError(BAD_REGISTRY_NAME)

src/azure-cli/azure/cli/command_modules/acr/custom.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def acr_create(cmd,
6868

6969
if re.match(r'\w*[A-Z]\w*', registry_name):
7070
raise InvalidArgumentValueError("argument error: Registry name must use only lowercase.")
71+
72+
if re.match(r'\w*[-]\w*', registry_name):
73+
raise InvalidArgumentValueError("argument error: Registry name cannot contain dashes.")
7174

7275
Registry, Sku, NetworkRuleSet = cmd.get_models('Registry', 'Sku', 'NetworkRuleSet')
7376
registry = Registry(location=location, sku=Sku(name=sku), admin_user_enabled=admin_enabled,

0 commit comments

Comments
 (0)