Skip to content

Commit

Permalink
Fix route53_info max_items / type being ignored (ansible-collections#813
Browse files Browse the repository at this point in the history
)

Fix route53_info max_items / type being ignored

SUMMARY
Currently if max_items is set on the route53_info module then it is ignored meaning all items are returned.
type is also ignored due to an incorrect if statement
It looks like it was a regression introduced here:
ansible/ansible@6075536#diff-23a0c9250633162d50c3f06442b7a552a5ae0659a24dd01a328c0e165e473616
The tests have been updated to reflect a check on max_items and type
Fixes: ansible-collections#529
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
route53_info
ADDITIONAL INFORMATION
The problem with max_items being ignored is resolved by adding PaginationConfig and adding MaxItems to that instead.
The problem with type being ignored is resolved by fixing an if statement.
Boto3 docs: https://boto3.amazonaws.com/v1/documentation/api/1.18.7/reference/services/route53.html#Route53.Paginator.ListResourceRecordSets

Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
  • Loading branch information
marknet15 authored and abikouo committed Sep 18, 2023
1 parent c54d211 commit b06e75f
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions route53_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
description:
- Maximum number of items to return for various get/list requests.
required: false
type: str
type: int
next_marker:
description:
- "Some requests such as list_command: hosted_zones will return a maximum
Expand All @@ -72,7 +72,7 @@
description:
- The type of DNS record.
required: false
choices: [ 'A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'CAA', 'NS' ]
choices: [ 'A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'CAA', 'NS', 'NAPTR', 'SOA', 'DS' ]
type: str
dns_name:
description:
Expand Down Expand Up @@ -228,9 +228,13 @@ def get_hosted_zone(client, module):

def reusable_delegation_set_details(client, module):
params = dict()

if not module.params.get('delegation_set_id'):
# Set PaginationConfig with max_items
if module.params.get('max_items'):
params['MaxItems'] = module.params.get('max_items')
params['PaginationConfig'] = dict(
MaxItems=module.params.get('max_items')
)

if module.params.get('next_marker'):
params['Marker'] = module.params.get('next_marker')
Expand All @@ -246,8 +250,11 @@ def reusable_delegation_set_details(client, module):
def list_hosted_zones(client, module):
params = dict()

# Set PaginationConfig with max_items
if module.params.get('max_items'):
params['MaxItems'] = module.params.get('max_items')
params['PaginationConfig'] = dict(
MaxItems=module.params.get('max_items')
)

if module.params.get('next_marker'):
params['Marker'] = module.params.get('next_marker')
Expand All @@ -272,8 +279,11 @@ def list_hosted_zones_by_name(client, module):
if module.params.get('dns_name'):
params['DNSName'] = module.params.get('dns_name')

# Set PaginationConfig with max_items
if module.params.get('max_items'):
params['MaxItems'] = module.params.get('max_items')
params['PaginationConfig'] = dict(
MaxItems=module.params.get('max_items')
)

return client.list_hosted_zones_by_name(**params)

Expand Down Expand Up @@ -340,12 +350,15 @@ def get_resource_tags(client, module):
def list_health_checks(client, module):
params = dict()

if module.params.get('max_items'):
params['MaxItems'] = module.params.get('max_items')

if module.params.get('next_marker'):
params['Marker'] = module.params.get('next_marker')

# Set PaginationConfig with max_items
if module.params.get('max_items'):
params['PaginationConfig'] = dict(
MaxItems=module.params.get('max_items')
)

paginator = client.get_paginator('list_health_checks')
health_checks = paginator.paginate(**params).build_full_result()['HealthChecks']
return {
Expand All @@ -362,19 +375,25 @@ def record_sets_details(client, module):
else:
module.fail_json(msg="Hosted Zone Id is required")

if module.params.get('max_items'):
params['MaxItems'] = module.params.get('max_items')

if module.params.get('start_record_name'):
params['StartRecordName'] = module.params.get('start_record_name')

# Check that both params are set if type is applied
if module.params.get('type') and not module.params.get('start_record_name'):
module.fail_json(msg="start_record_name must be specified if type is set")
elif module.params.get('type'):

if module.params.get('type'):
params['StartRecordType'] = module.params.get('type')

# Set PaginationConfig with max_items
if module.params.get('max_items'):
params['PaginationConfig'] = dict(
MaxItems=module.params.get('max_items')
)

paginator = client.get_paginator('list_resource_record_sets')
record_sets = paginator.paginate(**params).build_full_result()['ResourceRecordSets']

return {
"ResourceRecordSets": record_sets,
"list": record_sets,
Expand Down Expand Up @@ -420,12 +439,12 @@ def main():
], required=True),
change_id=dict(),
hosted_zone_id=dict(),
max_items=dict(),
max_items=dict(type='int'),
next_marker=dict(),
delegation_set_id=dict(),
start_record_name=dict(),
type=dict(choices=[
'A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'CAA', 'NS'
type=dict(type='str', choices=[
'A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'CAA', 'NS', 'NAPTR', 'SOA', 'DS'
]),
dns_name=dict(),
resource_id=dict(type='list', aliases=['resource_ids'], elements='str'),
Expand Down

0 comments on commit b06e75f

Please sign in to comment.