Skip to content

Commit

Permalink
Merge pull request ansible-collections#739 from tremble/sns_topic/htt…
Browse files Browse the repository at this point in the history
…pretry_strings

sns_topic - Define shape for delivery_policy.

SUMMARY
delivery_policy was previously defined just as "dict", this meant that if someone passed in JSON or quoted the numbers, AWS would spit errors at them.
By defining the shape of delivery_policy Ansible will automatically convert "10" to 10, as well as providing cleaner error messages for missing components of the policy.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
sns_topic
ADDITIONAL INFORMATION
obsoletes ansible-collections#716

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
  • Loading branch information
ansible-zuul[bot] authored Oct 1, 2021
2 parents c16440c + 19e60c2 commit 11ac443
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/739-sns_topic-delivery_policy-shape.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- sns_topic - define suboptions for delivery_policy option (https://github.com/ansible-collections/community.aws/issues/713).
105 changes: 101 additions & 4 deletions plugins/modules/sns_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,73 @@
description:
- Delivery policy to apply to the SNS topic.
type: dict
suboptions:
http:
description:
- Delivery policy for HTTP(S) messages.
- See U(https://docs.aws.amazon.com/sns/latest/dg/sns-message-delivery-retries.html)
for more information.
type: dict
required: false
suboptions:
disableSubscriptionOverrides:
description:
- Applies this policy to all subscriptions, even if they have their own policies.
type: bool
required: false
defaultThrottlePolicy:
description:
- Throttle the rate of messages sent to subsriptions.
type: dict
suboptions:
maxReceivesPerSecond:
description:
- The maximum number of deliveries per second per subscription.
type: int
required: true
required: false
defaultHealthyRetryPolicy:
description:
- Retry policy for HTTP(S) messages.
type: dict
required: true
suboptions:
minDelayTarget:
description:
- The minimum delay for a retry.
type: int
required: true
maxDelayTarget:
description:
- The maximum delay for a retry.
type: int
required: true
numRetries:
description:
- The total number of retries.
type: int
required: true
numMaxDelayRetries:
description:
- The number of retries with the maximum delay between them.
type: int
required: true
numMinDelayRetries:
description:
- The number of retries with just the minimum delay between them.
type: int
required: true
numNoDelayRetries:
description:
- The number of retries to be performmed immediately.
type: int
required: true
backoffFunction:
description:
- The function for backoff between retries.
type: str
required: true
choices: ['arithmetic', 'exponential', 'geometric', 'linear']
subscriptions:
description:
- List of subscriptions to apply to the topic. Note that AWS requires
Expand Down Expand Up @@ -225,8 +292,12 @@
except ImportError:
pass # handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_policies, AWSRetry, camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.core import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_policies
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict


class SnsTopicManager(object):
Expand All @@ -251,7 +322,7 @@ def __init__(self,
self.state = state
self.display_name = display_name
self.policy = policy
self.delivery_policy = delivery_policy
self.delivery_policy = scrub_none_parameters(delivery_policy) if delivery_policy else None
self.subscriptions = subscriptions
self.subscriptions_existing = []
self.subscriptions_deleted = []
Expand Down Expand Up @@ -495,13 +566,39 @@ def get_info(self):


def main():

# We're kinda stuck with CamelCase here, it would be nice to switch to
# snake_case, but we'd need to purge out the alias entries
http_retry_args = dict(
minDelayTarget=dict(type='int', required=True),
maxDelayTarget=dict(type='int', required=True),
numRetries=dict(type='int', required=True),
numMaxDelayRetries=dict(type='int', required=True),
numMinDelayRetries=dict(type='int', required=True),
numNoDelayRetries=dict(type='int', required=True),
backoffFunction=dict(type='str', required=True, choices=['arithmetic', 'exponential', 'geometric', 'linear']),
)
http_delivery_args = dict(
defaultHealthyRetryPolicy=dict(type='dict', required=True, options=http_retry_args),
disableSubscriptionOverrides=dict(type='bool', required=False),
defaultThrottlePolicy=dict(
type='dict', required=False,
options=dict(
maxReceivesPerSecond=dict(type='int', required=True),
),
),
)
delivery_args = dict(
http=dict(type='dict', required=False, options=http_delivery_args),
)

argument_spec = dict(
name=dict(required=True),
topic_type=dict(type='str', default='standard', choices=['standard', 'fifo']),
state=dict(default='present', choices=['present', 'absent']),
display_name=dict(),
policy=dict(type='dict'),
delivery_policy=dict(type='dict'),
delivery_policy=dict(type='dict', options=delivery_args),
subscriptions=dict(default=[], type='list', elements='dict'),
purge_subscriptions=dict(type='bool', default=True),
)
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/targets/sns_topic/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
delivery_policy:
http:
defaultHealthyRetryPolicy:
minDelayTarget: 20
minDelayTarget: "20"
maxDelayTarget: 20
numRetries: 3
numMaxDelayRetries: 0
Expand All @@ -153,7 +153,7 @@
delivery_policy:
http:
defaultHealthyRetryPolicy:
minDelayTarget: 20
minDelayTarget: "20"
maxDelayTarget: 20
numRetries: 3
numMaxDelayRetries: 0
Expand All @@ -179,7 +179,7 @@
delivery_policy:
http:
defaultHealthyRetryPolicy:
minDelayTarget: 40
minDelayTarget: "40"
maxDelayTarget: 40
numRetries: 6
numMaxDelayRetries: 0
Expand Down

0 comments on commit 11ac443

Please sign in to comment.