Skip to content

Commit

Permalink
{Network} az network dns record-set naptr: Naptr feature tests and …
Browse files Browse the repository at this point in the history
…fixes (Azure#30055)

* feature-naptr

* NAPTR azcli small fixes

* Naptr recordings

* Fix len of tests

* Naptr test fix for ttl comparison

* Fix empty regexp test

* Empty regexp fix

* Fix the backslash expectations in regexp

* Naptr empty regexp handling

* Comment NS in tests

* Style fixes

* Naptr check fixes

* More naptr regexp handling

* naptr regexp handling

* Change it to original values

* NAPTR test updates and Zone import fixes

* Naptr import/export logic fixes

* Update with import zone recordings

---------

Co-authored-by: Sandeep Kadagathur Vadiraj <skadagat@microsoft.com>
  • Loading branch information
2 people authored and yanzhudd committed Nov 25, 2024
1 parent 34d9c1e commit 7d96a58
Show file tree
Hide file tree
Showing 43 changed files with 6,085 additions and 4,303 deletions.
78 changes: 78 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,84 @@
crafted: true
"""

helps['network dns record-set naptr'] = """
type: group
short-summary: Manage DNS NAPTR records.
"""

helps['network dns record-set naptr add-record'] = """
type: command
short-summary: Add a NAPTR record.
examples:
- name: Add a NAPTR record.
text: |
az network dns record-set naptr add-record -g MyResourceGroup -z www.mysite.com \\
-n MyRecordSet --flags "U" --order 10 --preference 20 --services "E2U+sip" --regexp "!^.*$!sip:customer-service@example.com!" --replacement .
"""

helps['network dns record-set naptr create'] = """
type: command
short-summary: Create an empty NAPTR record set.
examples:
- name: Create an empty NAPTR record set.
text: az network dns record-set naptr create -g MyResourceGroup -z www.mysite.com -n MyRecordSet
- name: Create an empty NAPTR record set. (autogenerated)
text: |
az network dns record-set naptr create --name MyRecordSet --resource-group MyResourceGroup --ttl 30 --zone-name www.mysite.com
crafted: true
"""

helps['network dns record-set naptr delete'] = """
type: command
short-summary: Delete a NAPTR record set and all associated records.
examples:
- name: Delete a NAPTR record set and all associated records.
text: az network dns record-set naptr delete -g MyResourceGroup -z www.mysite.com -n MyRecordSet
"""

helps['network dns record-set naptr list'] = """
type: command
short-summary: List all NAPTR record sets in a zone.
examples:
- name: List all NAPTR record sets in a zone.
text: az network dns record-set naptr list -g MyResourceGroup -z www.mysite.com
"""

helps['network dns record-set naptr remove-record'] = """
type: command
short-summary: Remove a NAPTR record from its record set.
long-summary: >
By default, if the last record in a set is removed, the record set is deleted.
To retain the empty record set, include --keep-empty-record-set.
examples:
- name: Remove an NAPTR record from its record set.
text: |
az network dns record-set naptr remove-record -g MyResourceGroup -z www.mysite.com \\
-n MyRecordSet --flags "U" --order 10 --preference 20 --services "E2U+sip" --regexp "!^.*$!sip:customer-service@example.com!" --replacement .
"""

helps['network dns record-set naptr show'] = """
type: command
short-summary: Get the details of a NAPTR record set.
examples:
- name: Get the details of a NAPTR record set.
text: az network dns record-set naptr show -g MyResourceGroup -n MyRecordSet -z www.mysite.com
"""

helps['network dns record-set naptr update'] = """
type: command
short-summary: Update a NAPTR record set.
examples:
- name: Update a NAPTR record set.
text: |
az network dns record-set naptr update -g MyResourceGroup -n MyRecordSet \\
-z www.mysite.com --metadata owner=WebTeam
- name: Update a NAPTR record set. (autogenerated)
text: |
az network dns record-set naptr update --name MyRecordSet --resource-group MyResourceGroup --set tags.CostCenter=MyBusinessGroup --zone-name www.mysite.com
crafted: true
"""

helps['network dns record-set ns'] = """
type: group
short-summary: Manage DNS NS records.
Expand Down
12 changes: 10 additions & 2 deletions src/azure-cli/azure/cli/command_modules/network/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ def load_arguments(self, _):
for item in ['record_type', 'record_set_type']:
c.argument(item, ignore_type, validator=validate_dns_record_type)

for item in ['', 'a', 'aaaa', 'caa', 'cname', 'ds', 'mx', 'ns', 'ptr', 'srv', 'tlsa', 'txt']:
for item in ['', 'a', 'aaaa', 'caa', 'cname', 'ds', 'mx', 'naptr', 'ns', 'ptr', 'srv', 'tlsa', 'txt']:
with self.argument_context('network dns record-set {} create'.format(item)) as c:
c.argument('ttl', type=int, help='Record set TTL (time-to-live)')
c.argument('if_none_match', help='Create the record set only if it does not already exist.', action='store_true')

for item in ['a', 'aaaa', 'caa', 'cname', 'ds', 'mx', 'ns', 'ptr', 'srv', 'tlsa', 'txt']:
for item in ['a', 'aaaa', 'caa', 'cname', 'ds', 'mx', 'naptr', 'ns', 'ptr', 'srv', 'tlsa', 'txt']:
with self.argument_context('network dns record-set {} add-record'.format(item)) as c:
c.argument('ttl', type=int, help='Record set TTL (time-to-live)')
c.argument('record_set_name',
Expand Down Expand Up @@ -367,6 +367,14 @@ def load_arguments(self, _):
c.argument('exchange', options_list=['--exchange', '-e'], help='Exchange metric.')
c.argument('preference', options_list=['--preference', '-p'], help='Preference metric.')

with self.argument_context('network dns record-set naptr') as c:
c.argument('order', help='The order in which the NAPTR records MUST be processed in order to accurately represent the ordered list of rules. The ordering is from lowest to highest. Valid values: 0-65535.', type=int)
c.argument('preference', help='The preference specifies the order in which NAPTR records with equal "order" values should be processed, low numbers being processed before high numbers. Valid values: 0-65535.', type=int)
c.argument('flags', help='The flags specific to DDDS applications. Values currently defined in RFC 3404 are uppercase and lowercase letters "A", "P", "S", and "U", and the empty string, "". Enclose Flags in quotation marks.')
c.argument('services', help='The services specific to DDDS applications. Enclose Services in quotation marks.')
c.argument('regexp', help='The regular expression that the DDDS application uses to convert an input value into an output value. For example: an IP phone system might use a regular expression to convert a phone number that is entered by a user into a SIP URI. Enclose the regular expression in quotation marks. Specify either a value for "regexp" or a value for "replacement".')
c.argument('replacement', help='The replacement is a fully qualified domain name (FQDN) of the next domain name that you want the DDDS application to submit a DNS query for. The DDDS application replaces the input value with the value specified for replacement. Specify either a value for "regexp" or a value for "replacement". If you specify a value for "regexp", specify a dot (.) for "replacement".')

with self.argument_context('network dns record-set ns') as c:
c.argument('dname', options_list=['--nsdname', '-d'], help='Name server domain name.')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def validate_ssl_cert(namespace):

def validate_dns_record_type(namespace):
tokens = namespace.command.split(' ')
types = ['a', 'aaaa', 'caa', 'cname', 'ds', 'mx', 'ns', 'ptr', 'soa', 'srv', 'tlsa', 'txt']
types = ['a', 'aaaa', 'caa', 'cname', 'ds', 'mx', 'naptr', 'ns', 'ptr', 'soa', 'srv', 'tlsa', 'txt']
for token in tokens:
if token in types:
if hasattr(namespace, 'record_type'):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* PTR records must have a non-empty name
* currently only supports the following:
'$ORIGIN', '$TTL', 'SOA', 'NS', 'A', 'AAAA', 'CNAME', 'MX', 'PTR',
'TXT', 'SRV', 'SPF', 'URI', 'CAA'
'TXT', 'SRV', 'SPF', 'URI', 'CAA', 'NAPTR'
"""

import copy
Expand Down Expand Up @@ -67,6 +67,7 @@
'caa': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>caa)\s+(?P<flags>\d+)\s+(?P<tag>\w+)\s+(?P<val>.+)',
'cname': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>cname)\s+(?P<alias>[@\w\.-]+)',
'mx': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>mx)\s+(?P<preference>\d+)\s+(?P<host>[@\w\.-]+)',
'naptr': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>naptr)\s+(?P<order>\d+)\s+(?P<preference>\d+)\s+"(?P<flags>[^"]*)"\s+"(?P<services>[^"]*)"\s+"(?P<regexp>[^"]*)"\s+(?P<replacement>[\w.-]+)\.?',
'txt': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>txt)\s+(?P<txt>.+)',
'ptr': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>ptr)\s+(?P<host>[\w\.-]+)',
'srv': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>srv)\s+(?P<priority>\d+)\s+(?P<weight>\d+)\s+(?P<port>\d+)\s+(?P<target>[@\w\.-]+)',
Expand Down
50 changes: 28 additions & 22 deletions src/azure-cli/azure/cli/command_modules/network/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def load_command_table(self, _):
g.custom_command('export', 'export_zone')
g.custom_command('create', 'create_dns_zone', table_transformer=transform_dns_zone_table_output)

supported_records = ['a', 'aaaa', 'ds', 'mx', 'ns', 'ptr', 'srv', 'tlsa', 'txt', 'caa']
experimental_records = ['ds', 'tlsa']
supported_records = ['a', 'aaaa', 'ds', 'mx', 'naptr', 'ns', 'ptr', 'srv', 'tlsa', 'txt', 'caa']
experimental_records = ['ds', 'naptr', 'tlsa']
for record in supported_records:
is_experimental = record in experimental_records
with self.command_group('network dns record-set {}'.format(record), is_experimental=is_experimental) as g:
Expand All @@ -215,14 +215,16 @@ def load_command_table(self, _):

from .operations.dns import RecordSetAShow as DNSRecordSetAShow, RecordSetAAAAShow as DNSRecordSetAAAAShow, \
RecordSetDSShow as DNSRecordSetDSShow, RecordSetMXShow as DNSRecordSetMXShow, \
RecordSetNSShow as DNSRecordSetNSShow, RecordSetPTRShow as DNSRecordSetPTRShow, \
RecordSetSRVShow as DNSRecordSetSRVShow, RecordSetTLSAShow as DNSRecordSetTLSAShow, \
RecordSetTXTShow as DNSRecordSetTXTShow, RecordSetCAAShow as DNSRecordSetCAAShow, \
RecordSetCNAMEShow as DNSRecordSetCNAMEShow, RecordSetSOAShow as DNSRecordSetSOAShow
RecordSetNAPTRShow as DNSRecordSetNAPTRShow, RecordSetNSShow as DNSRecordSetNSShow, \
RecordSetPTRShow as DNSRecordSetPTRShow, RecordSetSRVShow as DNSRecordSetSRVShow, \
RecordSetTLSAShow as DNSRecordSetTLSAShow, RecordSetTXTShow as DNSRecordSetTXTShow, \
RecordSetCAAShow as DNSRecordSetCAAShow, RecordSetCNAMEShow as DNSRecordSetCNAMEShow, \
RecordSetSOAShow as DNSRecordSetSOAShow
self.command_table["network dns record-set a show"] = DNSRecordSetAShow(loader=self)
self.command_table["network dns record-set aaaa show"] = DNSRecordSetAAAAShow(loader=self)
self.command_table["network dns record-set ds show"] = DNSRecordSetDSShow(loader=self)
self.command_table["network dns record-set mx show"] = DNSRecordSetMXShow(loader=self)
self.command_table["network dns record-set naptr show"] = DNSRecordSetNAPTRShow(loader=self)
self.command_table["network dns record-set ns show"] = DNSRecordSetNSShow(loader=self)
self.command_table["network dns record-set ptr show"] = DNSRecordSetPTRShow(loader=self)
self.command_table["network dns record-set srv show"] = DNSRecordSetSRVShow(loader=self)
Expand All @@ -234,14 +236,15 @@ def load_command_table(self, _):

from .operations.dns import RecordSetAList as DNSRecordSetAList, RecordSetAAAAList as DNSRecordSetAAAAList, \
RecordSetDSList as DNSRecordSetDSList, RecordSetMXList as DNSRecordSetMXList, \
RecordSetNSList as DNSRecordSetNSList, RecordSetPTRList as DNSRecordSetPTRList, \
RecordSetSRVList as DNSRecordSetSRVList, RecordSetTLSAList as DNSRecordSetTLSAList, \
RecordSetTXTList as DNSRecordSetTXTList, RecordSetCAAList as DNSRecordSetCAAList, \
RecordSetCNAMEList as DNSRecordSetCNAMEList
RecordSetNAPTRList as DNSRecordSetNAPTRList, RecordSetNSList as DNSRecordSetNSList, \
RecordSetPTRList as DNSRecordSetPTRList, RecordSetSRVList as DNSRecordSetSRVList, \
RecordSetTLSAList as DNSRecordSetTLSAList, RecordSetTXTList as DNSRecordSetTXTList, \
RecordSetCAAList as DNSRecordSetCAAList, RecordSetCNAMEList as DNSRecordSetCNAMEList
self.command_table["network dns record-set a list"] = DNSRecordSetAList(loader=self)
self.command_table["network dns record-set aaaa list"] = DNSRecordSetAAAAList(loader=self)
self.command_table["network dns record-set ds list"] = DNSRecordSetDSList(loader=self)
self.command_table["network dns record-set mx list"] = DNSRecordSetMXList(loader=self)
self.command_table["network dns record-set naptr list"] = DNSRecordSetNAPTRList(loader=self)
self.command_table["network dns record-set ns list"] = DNSRecordSetNSList(loader=self)
self.command_table["network dns record-set ptr list"] = DNSRecordSetPTRList(loader=self)
self.command_table["network dns record-set srv list"] = DNSRecordSetSRVList(loader=self)
Expand All @@ -252,14 +255,15 @@ def load_command_table(self, _):

from .operations.dns import RecordSetACreate as DNSRecordSetACreate, RecordSetAAAACreate as DNSRecordSetAAAACreate, \
RecordSetDSCreate as DNSRecordSetDSCreate, RecordSetMXCreate as DNSRecordSetMXCreate, \
RecordSetNSCreate as DNSRecordSetNSCreate, RecordSetPTRCreate as DNSRecordSetPTRCreate, \
RecordSetSRVCreate as DNSRecordSetSRVCreate, RecordSetTLSACreate as DNSRecordSetTLSACreate, \
RecordSetTXTCreate as DNSRecordSetTXTCreate, RecordSetCAACreate as DNSRecordSetCAACreate, \
RecordSetCNAMECreate as DNSRecordSetCNAMECreate
RecordSetNAPTRCreate as DNSRecordSetNAPTRCreate, RecordSetNSCreate as DNSRecordSetNSCreate, \
RecordSetPTRCreate as DNSRecordSetPTRCreate, RecordSetSRVCreate as DNSRecordSetSRVCreate, \
RecordSetTLSACreate as DNSRecordSetTLSACreate, RecordSetTXTCreate as DNSRecordSetTXTCreate, \
RecordSetCAACreate as DNSRecordSetCAACreate, RecordSetCNAMECreate as DNSRecordSetCNAMECreate
self.command_table["network dns record-set a create"] = DNSRecordSetACreate(loader=self)
self.command_table["network dns record-set aaaa create"] = DNSRecordSetAAAACreate(loader=self)
self.command_table["network dns record-set ds create"] = DNSRecordSetDSCreate(loader=self)
self.command_table["network dns record-set mx create"] = DNSRecordSetMXCreate(loader=self)
self.command_table["network dns record-set naptr create"] = DNSRecordSetNAPTRCreate(loader=self)
self.command_table["network dns record-set ns create"] = DNSRecordSetNSCreate(loader=self)
self.command_table["network dns record-set ptr create"] = DNSRecordSetPTRCreate(loader=self)
self.command_table["network dns record-set srv create"] = DNSRecordSetSRVCreate(loader=self)
Expand All @@ -270,14 +274,15 @@ def load_command_table(self, _):

from .operations.dns import RecordSetAUpdate as DNSRecordSetAUpdate, RecordSetAAAAUpdate as DNSRecordSetAAAAUpdate, \
RecordSetDSUpdate as DNSRecordSetDSUpdate, RecordSetMXUpdate as DNSRecordSetMXUpdate, \
RecordSetNSUpdate as DNSRecordSetNSUpdate, RecordSetPTRUpdate as DNSRecordSetPTRUpdate, \
RecordSetSRVUpdate as DNSRecordSetSRVUpdate, RecordSetTLSAUpdate as DNSRecordSetTLSAUpdate, \
RecordSetTXTUpdate as DNSRecordSetTXTUpdate, RecordSetCAAUpdate as DNSRecordSetCAAUpdate, \
RecordSetCNAMEUpdate as DNSRecordSetCNAMEUpdate
RecordSetNAPTRUpdate as DNSRecordSetNAPTRUpdate, RecordSetNSUpdate as DNSRecordSetNSUpdate, \
RecordSetPTRUpdate as DNSRecordSetPTRUpdate, RecordSetSRVUpdate as DNSRecordSetSRVUpdate, \
RecordSetTLSAUpdate as DNSRecordSetTLSAUpdate, RecordSetTXTUpdate as DNSRecordSetTXTUpdate, \
RecordSetCAAUpdate as DNSRecordSetCAAUpdate, RecordSetCNAMEUpdate as DNSRecordSetCNAMEUpdate
self.command_table["network dns record-set a update"] = DNSRecordSetAUpdate(loader=self)
self.command_table["network dns record-set aaaa update"] = DNSRecordSetAAAAUpdate(loader=self)
self.command_table["network dns record-set ds update"] = DNSRecordSetDSUpdate(loader=self)
self.command_table["network dns record-set mx update"] = DNSRecordSetMXUpdate(loader=self)
self.command_table["network dns record-set naptr update"] = DNSRecordSetNAPTRUpdate(loader=self)
self.command_table["network dns record-set ns update"] = DNSRecordSetNSUpdate(loader=self)
self.command_table["network dns record-set ptr update"] = DNSRecordSetPTRUpdate(loader=self)
self.command_table["network dns record-set srv update"] = DNSRecordSetSRVUpdate(loader=self)
Expand All @@ -288,14 +293,15 @@ def load_command_table(self, _):

from .operations.dns import RecordSetADelete as DNSRecordSetADelete, RecordSetAAAADelete as DNSRecordSetAAAADelete, \
RecordSetDSDelete as DNSRecordSetDSDelete, RecordSetMXDelete as DNSRecordSetMXDelete, \
RecordSetNSDelete as DNSRecordSetNSDelete, RecordSetPTRDelete as DNSRecordSetPTRDelete, \
RecordSetSRVDelete as DNSRecordSetSRVDelete, RecordSetTLSADelete as DNSRecordSetTLSADelete, \
RecordSetTXTDelete as DNSRecordSetTXTDelete, RecordSetCAADelete as DNSRecordSetCAADelete, \
RecordSetCNAMEDelete as DNSRecordSetCNAMEDelete
RecordSetNAPTRDelete as DNSRecordSetNAPTRDelete, RecordSetNSDelete as DNSRecordSetNSDelete, \
RecordSetPTRDelete as DNSRecordSetPTRDelete, RecordSetSRVDelete as DNSRecordSetSRVDelete, \
RecordSetTLSADelete as DNSRecordSetTLSADelete, RecordSetTXTDelete as DNSRecordSetTXTDelete, \
RecordSetCAADelete as DNSRecordSetCAADelete, RecordSetCNAMEDelete as DNSRecordSetCNAMEDelete
self.command_table["network dns record-set a delete"] = DNSRecordSetADelete(loader=self)
self.command_table["network dns record-set aaaa delete"] = DNSRecordSetAAAADelete(loader=self)
self.command_table["network dns record-set ds delete"] = DNSRecordSetDSDelete(loader=self)
self.command_table["network dns record-set mx delete"] = DNSRecordSetMXDelete(loader=self)
self.command_table["network dns record-set naptr delete"] = DNSRecordSetNAPTRDelete(loader=self)
self.command_table["network dns record-set ns delete"] = DNSRecordSetNSDelete(loader=self)
self.command_table["network dns record-set ptr delete"] = DNSRecordSetPTRDelete(loader=self)
self.command_table["network dns record-set srv delete"] = DNSRecordSetSRVDelete(loader=self)
Expand Down
Loading

0 comments on commit 7d96a58

Please sign in to comment.