Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Network] az network dns zone export: Add support for ALIAS record #23209

Merged
merged 3 commits into from
Jul 15, 2022
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
8 changes: 7 additions & 1 deletion src/azure-cli/azure/cli/command_modules/network/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,13 @@ def export_zone(cmd, resource_group_name, zone_name, file_name=None): # pylint:

if record_type not in zone_obj[record_set_name]:
zone_obj[record_set_name][record_type] = []
if record_type == 'aaaa' or record_type == 'a':
# Checking for alias record
if (record_type == 'a' or record_type == 'aaaa' or record_type == 'cname') and record_set.target_resource.id:
target_resource_id = record_set.target_resource.id
record_obj.update({'target-resource-id': record_type.upper() + " " + target_resource_id})
record_type = 'alias'
zone_obj[record_set_name][record_type] = []
elif record_type == 'aaaa' or record_type == 'a':
record_obj.update({'ip': ''})
elif record_type == 'cname':
record_obj.update({'alias': ''})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
'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\.-]+)',
'spf': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>spf)\s+(?P<txt>.+)',
'uri': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>uri)\s+(?P<priority>\d+)\s+(?P<weight>\d+)\s+(?P<target>[\w\.]+)'
'uri': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>in)\s+)?(?P<delim>uri)\s+(?P<priority>\d+)\s+(?P<weight>\d+)\s+(?P<target>[\w\.]+)',
'alias': r'(?P<name>[@\*\w\.-]*)\s+(?:(?P<ttl>\d+\w*)\s+)?(?:(?P<class>azure)\s+)?(?P<delim>alias)\s+(?P<aliasDelim>aaaa|a|cname)\s+(?P<resourceId>[a-zA-Z0-9/._-]*)',
}

_COMPILED_REGEX = {k: re.compile(v, re.IGNORECASE) for k, v in _REGEX.items()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ def process_rr(io, data, record_type, record_keys, name, print_name):
elif not isinstance(record_keys, list):
raise ValueError('record_keys must be a string or list of strings')

in_or_azure = "IN"
if record_type == 'ALIAS':
in_or_azure = "AZURE"

name_display = name if print_name else ' ' * len(name)
print('{} {} IN {} '.format(name_display, data['ttl'], record_type), end='', file=io)
print('{} {} {} {} '.format(name_display, data['ttl'], in_or_azure, record_type), end='', file=io)

for i, key in enumerate(record_keys):
print(data[key], end='\n' if i == len(record_keys) - 1 else ' ', file=io)
Expand Down Expand Up @@ -124,3 +128,7 @@ def process_txt(io, data, name, print_name=False):

def process_srv(io, data, name, print_name=False):
return process_rr(io, data, 'SRV', ['priority', 'weight', 'port', 'target'], name, print_name)


def process_alias(io, data, name, print_name=False):
return process_rr(io, data, 'ALIAS', 'target-resource-id', name, print_name)