Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
get_three_state_flag)
from azure.cli.command_modules.rdbms.validators import configuration_value_validator, validate_subnet, \
tls_validator, public_access_validator, maintenance_window_validator, ip_address_validator, \
retention_validator, firewall_rule_name_validator, validate_identity, validate_byok_identity, validate_identities, \
virtual_endpoint_name_validator, node_count_validator
retention_validator, validate_identity, validate_byok_identity, validate_identities, \
virtual_endpoint_name_validator, node_count_validator, postgres_firewall_rule_name_validator
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction

from .randomname.generate import generate_username
Expand Down Expand Up @@ -796,7 +796,7 @@ def _flexible_server_params(command_group):
for scope in ['create', 'delete', 'show', 'update']:
argument_context_string = '{} flexible-server firewall-rule {}'.format(command_group, scope)
with self.argument_context(argument_context_string) as c:
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'], validator=firewall_rule_name_validator,
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'], validator=postgres_firewall_rule_name_validator,
help='The name of the firewall rule. If name is omitted, default name will be chosen for firewall name. The firewall rule name can only contain 0-9, a-z, A-Z, \'-\' and \'_\'. Additionally, the name of the firewall rule must be at least 3 characters and no more than 128 characters in length. ')
c.argument('end_ip_address', options_list=['--end-ip-address'], validator=ip_address_validator,
help='The end IP address of the firewall rule. Must be IPv4 format. Use value \'0.0.0.0\' to represent all Azure-internal IP addresses. ')
Expand Down
9 changes: 9 additions & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,15 @@ def firewall_rule_name_validator(ns):
"and no more than 128 characters in length. ")


def postgres_firewall_rule_name_validator(ns):
if not ns.firewall_rule_name:
return
if not re.search(r'^[a-zA-Z0-9][-_a-zA-Z0-9]{0,79}(?<!-)$', ns.firewall_rule_name):
raise ValidationError("The firewall rule name can only contain 0-9, a-z, A-Z, \'-\' and \'_\'. "
"Additionally, the name of the firewall rule must be at least 1, "
"and no more than 80 characters in length. Firewall rule must not end with '-'.")


def validate_server_name(db_context, server_name, type_):
client = db_context.cf_availability(db_context.cmd.cli_ctx, '_')

Expand Down