Skip to content

the regex used to validate an event hub namespace name seems to be incorrect #31108

@Chris-Marcantonio

Description

@Chris-Marcantonio

Describe the bug

The documentation available, as well as context hints in the Azure portal indicate that an event hub namespace name can be between 6 and 50 characters long. For example, see:

https://learn.microsoft.com/en-us/azure/templates/microsoft.eventhub/namespaces?pivots=deployment-language-bicep#microsofteventhubnamespaces

And when entering a name in the Azure portal, there is a tip that says "The value must be between 6 and 50 characters long" in red.

However, if you look at the regex in the link above, it is shown as:

^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$

Which I believe is wrong. And this doesn't appear to be just a documentation bug...when I run an az cli command against something, I get an error that shows the same regex, and that my name does not match it, despite it being 7 characters long:

InvalidArgumentValue: -n: Invalid format: 'dev-lab' does not fully match regular expression pattern '^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$'

I'm pretty sure that {6,50} in the middle should in fact be {4,48} in order to properly match a name that is between 6 and 50 characters long. For example, it fails to properly validate a name length of 6 or 7 characters, but passes for something 8 characters:

PS /> if ("foobar" -match "^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$") { Write-Host "yep" }
PS /> if ("foobar1" -match "^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$") { Write-Host "yep" }
PS /> if ("foobar12" -match "^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$") { Write-Host "yep" }
yep
PS />

And there is a similar failure for lengths that are tested against what should be a length limit of 50:

PS /> $foo = "abcdefghijklmnopqrstuvwxyzXxXx01234567890123456789xx"
PS /> $foo.length
52
PS /> if ($foo -match "^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$") { Write-Host "yep" }
yep
PS />

If I adjust that regex to:

^[a-zA-Z][a-zA-Z0-9-]{4,48}[a-zA-Z0-9]$

then things work as expected:

PS /> if ("fooba" -match "^[a-zA-Z][a-zA-Z0-9-]{4,48}[a-zA-Z0-9]$") { Write-Host "yep" }
PS /> if ("foobar" -match "^[a-zA-Z][a-zA-Z0-9-]{4,48}[a-zA-Z0-9]$") { Write-Host "yep" }
yep
PS />
PS /> $foo = "abcdefghijklmnopqrstuvwxyzXxXx01234567890123456789"
PS /> $foo.length
50
PS /> if ($foo -match "^[a-zA-Z][a-zA-Z0-9-]{4,48}[a-zA-Z0-9]$") { Write-Host "yep" }
yep
PS />
PS /> $foo = "abcdefghijklmnopqrstuvwxyzXxXx01234567890123456789x"
PS /> $foo.length
51
PS /> if ($foo -match "^[a-zA-Z][a-zA-Z0-9-]{4,48}[a-zA-Z0-9]$") { Write-Host "yep" }
PS />

Related command

az eventhubs namespace show

Errors

InvalidArgumentValue: -n: Invalid format: 'dev-lab' does not fully match regular expression pattern '^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$'

Issue script & Debug output

PS /> az eventhubs namespace show --ids REDACTED --debug
cli.knack.cli: Command arguments: ['eventhubs', 'namespace', 'show', '--ids', 'REDACTED', '--debug']
cli.knack.cli: init debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x100a031a0>, <function OutputProducer.on_global_arguments at 0x100d42480>, <function CLIQuery.on_global_arguments at 0x100d7bc40>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'eventhubs': ['azure.cli.command_modules.eventhubs']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: eventhubs 0.135 17 34
cli.azure.cli.core: Total (1) 0.135 17 34
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name Load Time Groups Commands Directory
cli.azure.cli.core: Total (0) 0.000 0 0
cli.azure.cli.core: Loaded 17 groups, 34 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : eventhubs namespace show
cli.azure.cli.core: Command table: eventhubs namespace show
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x1021f2200>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'REDACTED'.
az_command_data_logger: command args: eventhubs namespace show --ids {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x102227920>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x102285c60>, <function register_cache_arguments..add_cache_arguments at 0x102285da0>, <function register_upcoming_breaking_change_info..update_breaking_change_info at 0x102285e40>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x100d42520>, <function CLIQuery.handle_query_parameter at 0x100d7bce0>, <function register_ids_argument..parse_ids_arguments at 0x102285d00>]
cli.azure.cli.core.azclierror: Traceback (most recent call last):
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/aaz/_command_ctx.py", line 53, in format_args
self.args._schema._fmt(ctx=self, value=self.args)
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/aaz/_arg_fmt.py", line 402, in call
raise err from err
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/aaz/_arg_fmt.py", line 399, in call
value[field_name] = field_schema._fmt(ctx, value[field_name])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/aaz/_arg_fmt.py", line 56, in call
raise AAZInvalidArgValueError(
azure.cli.core.aaz.exceptions.AAZInvalidArgValueError: InvalidArgumentValue: -n: Invalid format: 'dev-lab' does not fully match regular expression pattern '^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/init.py", line 666, in execute
raise ex
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/init.py", line 734, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/init.py", line 703, in _run_job
result = cmd_copy(params)
^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/aaz/_command.py", line 155, in call
return self._handler(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/command_modules/eventhubs/aaz/latest/eventhubs/namespace/_show.py", line 32, in _handler
super()._handler(command_args)
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/aaz/_command.py", line 165, in _handler
self.ctx.format_args()
File "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/core/aaz/_command_ctx.py", line 55, in format_args
raise InvalidArgumentValueError(str(err))
azure.cli.core.azclierror.InvalidArgumentValueError: InvalidArgumentValue: -n: Invalid format: 'dev-lab' does not fully match regular expression pattern '^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$'

cli.azure.cli.core.azclierror: InvalidArgumentValue: -n: Invalid format: 'dev-lab' does not fully match regular expression pattern '^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$'
az_command_data_logger: InvalidArgumentValue: -n: Invalid format: 'dev-lab' does not fully match regular expression pattern '^[a-zA-Z][a-zA-Z0-9-]{6,50}[a-zA-Z0-9]$'
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x1021f2480>]
az_command_data_logger: exit code: 1
cli.main: Command ran in 0.371 seconds (init: 0.163, invoke: 0.207)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 4064 in cache file under /Users/REDACTED/.azure/telemetry/20250321152414410
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "/opt/homebrew/Cellar/azure-cli/2.70.0/libexec/bin/python /opt/homebrew/Cellar/azure-cli/2.70.0/libexec/lib/python3.12/site-packages/azure/cli/telemetry/init.py /Users/REDACTED/.azure /Users/REDACTED/.azure/telemetry/20250321152414410"
telemetry.process: Return from creating process 42974
telemetry.main: Finish creating telemetry upload process.
PS />

Expected behavior

The name used is valid, so it should not fail validation to that regex.

Environment Summary

azure-cli: stable 2.70.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Auto-AssignAuto assign by botEvent Hubsaz eventhubsService AttentionThis issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions