diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/_help.py b/src/azure-cli/azure/cli/command_modules/postgresql/_help.py index b1e475004b9..984d706694f 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/_help.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/_help.py @@ -430,15 +430,15 @@ - name: > Create a firewall rule allowing connections from a specific IP address. text: > - az postgres flexible-server firewall-rule create --resource-group testGroup --name testserver --rule-name allowip --start-ip-address 107.46.14.221 + az postgres flexible-server firewall-rule create --resource-group testGroup --server-name testserver --name allowip --start-ip-address 107.46.14.221 - name: > Create a firewall rule allowing connections from an IP address range. text: > - az postgres flexible-server firewall-rule create --resource-group testGroup --name testserver --rule-name allowiprange --start-ip-address 107.46.14.0 --end-ip-address 107.46.14.221 + az postgres flexible-server firewall-rule create --resource-group testGroup --server-name testserver --name allowiprange --start-ip-address 107.46.14.0 --end-ip-address 107.46.14.221 - name: > Create a firewall rule allowing connections to all Azure services text: > - az postgres flexible-server firewall-rule create --resource-group testGroup --name testserver --rule-name allowazureservices --start-ip-address 0.0.0.0 + az postgres flexible-server firewall-rule create --resource-group testGroup --server-name testserver --name allowazureservices --start-ip-address 0.0.0.0 """ helps['postgres flexible-server firewall-rule list'] = """ @@ -446,9 +446,9 @@ short-summary: List all firewall rules for a flexible server. example: - name: List all firewall rules for a server. - text: az postgres flexible-server firewall-rule list --resource-group testGroup --name testserver + text: az postgres flexible-server firewall-rule list --resource-group testGroup --server-name testserver - name: List all firewall rules for a server in table format. - text: az postgres flexible-server firewall-rule list --resource-group testGroup --name testserver --output table + text: az postgres flexible-server firewall-rule list --resource-group testGroup --server-name testserver --output table """ helps['postgres flexible-server firewall-rule show'] = """ @@ -456,7 +456,7 @@ short-summary: Get the details of a firewall rule. examples: - name: Get the details of a firewall rule. - text: az postgres flexible-server firewall-rule show --rule-name testRule --resource-group testGroup --name testserver + text: az postgres flexible-server firewall-rule show --name testRule --resource-group testGroup --server-name testserver """ helps['postgres flexible-server firewall-rule update'] = """ @@ -464,9 +464,9 @@ short-summary: Update a firewall rule. examples: - name: Update a firewall rule's start IP address. - text: az postgres flexible-server firewall-rule update --resource-group testGroup --name testserver --rule-name allowiprange --start-ip-address 107.46.14.1 + text: az postgres flexible-server firewall-rule update --resource-group testGroup --server-name testserver --name allowiprange --start-ip-address 107.46.14.1 - name: Update a firewall rule's start and end IP address. - text: az postgres flexible-server firewall-rule update --resource-group testGroup --name testserver --rule-name allowiprange --start-ip-address 107.46.14.2 --end-ip-address 107.46.14.218 + text: az postgres flexible-server firewall-rule update --resource-group testGroup --server-name testserver --name allowiprange --start-ip-address 107.46.14.2 --end-ip-address 107.46.14.218 """ helps['postgres flexible-server firewall-rule delete'] = """ @@ -474,7 +474,7 @@ short-summary: Delete a firewall rule. examples: - name: Delete a firewall rule. - text: az postgres flexible-server firewall-rule delete --rule-name testRule --resource-group testGroup --name testserver + text: az postgres flexible-server firewall-rule delete --name testRule --resource-group testGroup --server-name testserver """ helps['postgres flexible-server virtual-endpoint'] = """ diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/_params.py b/src/azure-cli/azure/cli/command_modules/postgresql/_params.py index 3b9bbe7175e..dae563eec27 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/_params.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/_params.py @@ -549,10 +549,17 @@ def _flexible_server_params(command_group): help='Source of the configuration.') # firewall-rule - for scope in ['create', 'delete', 'show', 'update']: + firewall_rule_name_scopes = ['create', 'delete', 'show', 'update'] + firewall_rule_server_name_scopes = firewall_rule_name_scopes + ['list'] + for scope in firewall_rule_server_name_scopes: 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=postgres_firewall_rule_name_validator, + c.argument('server_name', arg_type=server_name_resource_arg_type) + + for scope in firewall_rule_name_scopes: + 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=['--name', '-n'], 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. ') diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_firewall_rule.py b/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_firewall_rule.py index ec3039eca61..dfb32806a1d 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_firewall_rule.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_firewall_rule.py @@ -35,7 +35,7 @@ def _test_flexible_server_public_access_mgmt(self, resource_group): result = self.cmd('postgres flexible-server create -g {} -n {} --public-access {} -l {}' .format(resource_group, servers[0], 'all', location)).get_output_in_json() - self.cmd('postgres flexible-server firewall-rule show -g {} -n {} -r {}' + self.cmd('postgres flexible-server firewall-rule show -g {} -s {} -n {}' .format(resource_group, servers[0], result["firewallName"]), checks=[JMESPathCheck('startIpAddress', '0.0.0.0'), JMESPathCheck('endIpAddress', '255.255.255.255')]) @@ -44,7 +44,7 @@ def _test_flexible_server_public_access_mgmt(self, resource_group): result = self.cmd('postgres flexible-server create -g {} -n {} --public-access {} -l {}' .format(resource_group, servers[1], '0.0.0.0', location)).get_output_in_json() - self.cmd('postgres flexible-server firewall-rule show -g {} -n {} -r {}' + self.cmd('postgres flexible-server firewall-rule show -g {} -s {} -n {}' .format(resource_group, servers[1], result["firewallName"]), checks=[JMESPathCheck('startIpAddress', '0.0.0.0'), JMESPathCheck('endIpAddress', '0.0.0.0')]) @@ -53,7 +53,7 @@ def _test_flexible_server_public_access_mgmt(self, resource_group): result = self.cmd('postgres flexible-server create -g {} -n {} --public-access {} -l {}' .format(resource_group, servers[2], '10.0.0.0-12.0.0.0', location)).get_output_in_json() - self.cmd('postgres flexible-server firewall-rule show -g {} -n {} -r {}' + self.cmd('postgres flexible-server firewall-rule show -g {} -s {} -n {}' .format(resource_group, servers[2], result["firewallName"]), checks=[JMESPathCheck('startIpAddress', '10.0.0.0'), JMESPathCheck('endIpAddress', '12.0.0.0')]) @@ -62,7 +62,7 @@ def _test_flexible_server_public_access_mgmt(self, resource_group): result = self.cmd('postgres flexible-server create -g {} -n {} -l {} --yes' .format(resource_group, servers[3], location)).get_output_in_json() - firewall_rule = self.cmd('postgres flexible-server firewall-rule show -g {} -n {} -r {}' + firewall_rule = self.cmd('postgres flexible-server firewall-rule show -g {} -s {} -n {}' .format(resource_group, servers[3], result["firewallName"])).get_output_in_json() self.assertEqual(firewall_rule['startIpAddress'], firewall_rule['endIpAddress']) @@ -80,28 +80,28 @@ def _test_flexible_server_public_access_mgmt(self, resource_group): .format(resource_group, servers[4]), checks=[JMESPathCheck('network.publicNetworkAccess', "Enabled")]) - self.cmd('postgres flexible-server firewall-rule create -g {} --name {} --rule-name {} ' + self.cmd('postgres flexible-server firewall-rule create -g {} --server-name {} --name {} ' '--start-ip-address {} --end-ip-address {} ' .format(resource_group, servers[4], firewall_rule_name, start_ip_address, end_ip_address), checks=firewall_rule_checks) - self.cmd('postgres flexible-server firewall-rule show -g {} --name {} --rule-name {} ' + self.cmd('postgres flexible-server firewall-rule show -g {} --server-name {} --name {} ' .format(resource_group, servers[4], firewall_rule_name), checks=firewall_rule_checks) new_start_ip_address = '9.9.9.9' - self.cmd('postgres flexible-server firewall-rule update -g {} --name {} --rule-name {} --start-ip-address {}' + self.cmd('postgres flexible-server firewall-rule update -g {} --server-name {} --name {} --start-ip-address {}' .format(resource_group, servers[4], firewall_rule_name, new_start_ip_address), checks=[JMESPathCheck('startIpAddress', new_start_ip_address)]) new_end_ip_address = '13.13.13.13' - self.cmd('postgres flexible-server firewall-rule update -g {} --name {} --rule-name {} --end-ip-address {}' + self.cmd('postgres flexible-server firewall-rule update -g {} --server-name {} --name {} --end-ip-address {}' .format(resource_group, servers[4], firewall_rule_name, new_end_ip_address)) - self.cmd('postgres flexible-server firewall-rule list -g {} -n {}' + self.cmd('postgres flexible-server firewall-rule list -g {} -s {}' .format(resource_group, servers[4]), checks=[JMESPathCheck('length(@)', 1)]) - self.cmd('postgres flexible-server firewall-rule delete --rule-name {} -g {} --name {} --yes' + self.cmd('postgres flexible-server firewall-rule delete --name {} -g {} --server-name {} --yes' .format(firewall_rule_name, resource_group, servers[4]), checks=NoneCheck()) # Clean up @@ -118,4 +118,4 @@ def _test_flexible_server_public_access_mgmt(self, resource_group): checks=NoneCheck()) self.cmd('postgres flexible-server delete -g {} -n {} --yes'.format(resource_group, servers[4]), - checks=NoneCheck()) \ No newline at end of file + checks=NoneCheck())