Skip to content

Commit cabda2c

Browse files
author
Matthew Boentoro
committed
{RDBMS} az postgres flexible-server firewall-rule create: modify firewall rule name validator
1 parent 05a5d8f commit cabda2c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/azure-cli/azure/cli/command_modules/rdbms/_params.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
get_three_state_flag)
1717
from azure.cli.command_modules.rdbms.validators import configuration_value_validator, validate_subnet, \
1818
tls_validator, public_access_validator, maintenance_window_validator, ip_address_validator, \
19-
retention_validator, firewall_rule_name_validator, validate_identity, validate_byok_identity, validate_identities, \
20-
virtual_endpoint_name_validator, node_count_validator
19+
retention_validator, validate_identity, validate_byok_identity, validate_identities, \
20+
virtual_endpoint_name_validator, node_count_validator, postgres_firewall_rule_name_validator
2121
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction
2222

2323
from .randomname.generate import generate_username
@@ -796,7 +796,7 @@ def _flexible_server_params(command_group):
796796
for scope in ['create', 'delete', 'show', 'update']:
797797
argument_context_string = '{} flexible-server firewall-rule {}'.format(command_group, scope)
798798
with self.argument_context(argument_context_string) as c:
799-
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'], validator=firewall_rule_name_validator,
799+
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'], validator=postgres_firewall_rule_name_validator,
800800
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. ')
801801
c.argument('end_ip_address', options_list=['--end-ip-address'], validator=ip_address_validator,
802802
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. ')

src/azure-cli/azure/cli/command_modules/rdbms/validators.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,15 @@ def firewall_rule_name_validator(ns):
682682
"and no more than 128 characters in length. ")
683683

684684

685+
def postgres_firewall_rule_name_validator(ns):
686+
if not ns.firewall_rule_name:
687+
return
688+
if not re.search(r'^[a-zA-Z0-9][-_a-zA-Z0-9]{0,79}(?<!-)$', ns.firewall_rule_name):
689+
raise ValidationError("The firewall rule name can only contain 0-9, a-z, A-Z, \'-\' and \'_\'. "
690+
"Additionally, the name of the firewall rule must be at least 1 characters "
691+
"and no more than 80 characters in length. Firewall rule must not end with '-'.")
692+
693+
685694
def validate_server_name(db_context, server_name, type_):
686695
client = db_context.cf_availability(db_context.cmd.cli_ctx, '_')
687696

0 commit comments

Comments
 (0)