From 043c7fc1fd6758d4eddfde608031ef62754d0c86 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 3 May 2019 11:29:20 -0700 Subject: [PATCH] Add expiration policy to pubsub subscription resource (#240) Signed-off-by: Modular Magician --- .../cloud/google/gcp_pubsub_subscription.py | 61 +++++++++++++++++++ .../google/gcp_pubsub_subscription_facts.py | 23 +++++++ 2 files changed, 84 insertions(+) diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py index 503edbd7099af1..a08f0bacf37b8e 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py @@ -134,6 +134,26 @@ required: false type: bool version_added: 2.8 + expiration_policy: + description: + - A policy that specifies the conditions for this subscription's expiration. + - A subscription is considered active as long as any connected subscriber is successfully + consuming messages from the subscription or is issuing operations on the subscription. + If expirationPolicy is not set, a default policy with ttl of 31 days will be + used. The minimum allowed value for expirationPolicy.ttl is 1 day. + required: false + version_added: 2.8 + suboptions: + ttl: + description: + - Specifies the "time-to-live" duration for an associated resource. The resource + expires if it is not active for a period of ttl. The definition of "activity" + depends on the type of the associated resource. The minimum and maximum + allowed values for ttl depend on the type of the associated resource, as + well. If ttl is not set, the associated resource never expires. + - A duration in seconds with up to nine fractional digits, terminated by 's'. + - Example - "3.5s". + required: false extends_documentation_fragment: gcp notes: - 'API Reference: U(https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions)' @@ -246,6 +266,27 @@ they fall out of the messageRetentionDuration window. returned: success type: bool +expirationPolicy: + description: + - A policy that specifies the conditions for this subscription's expiration. + - A subscription is considered active as long as any connected subscriber is successfully + consuming messages from the subscription or is issuing operations on the subscription. + If expirationPolicy is not set, a default policy with ttl of 31 days will be used. + The minimum allowed value for expirationPolicy.ttl is 1 day. + returned: success + type: complex + contains: + ttl: + description: + - Specifies the "time-to-live" duration for an associated resource. The resource + expires if it is not active for a period of ttl. The definition of "activity" + depends on the type of the associated resource. The minimum and maximum allowed + values for ttl depend on the type of the associated resource, as well. If + ttl is not set, the associated resource never expires. + - A duration in seconds with up to nine fractional digits, terminated by 's'. + - Example - "3.5s". + returned: success + type: str ''' ################################################################################ @@ -273,6 +314,7 @@ def main(): ack_deadline_seconds=dict(type='int'), message_retention_duration=dict(default='604800s', type='str'), retain_acked_messages=dict(type='bool'), + expiration_policy=dict(type='dict', options=dict(ttl=dict(type='str'))), ) ) @@ -331,6 +373,8 @@ def updateMask(request, response): update_mask.append('messageRetentionDuration') if request.get('retainAckedMessages') != response.get('retainAckedMessages'): update_mask.append('retainAckedMessages') + if request.get('expirationPolicy') != response.get('expirationPolicy'): + update_mask.append('expirationPolicy') return ','.join(update_mask) @@ -348,6 +392,7 @@ def resource_to_request(module): u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds'), u'messageRetentionDuration': module.params.get('message_retention_duration'), u'retainAckedMessages': module.params.get('retain_acked_messages'), + u'expirationPolicy': SubscriptionExpirationpolicy(module.params.get('expiration_policy', {}), module).to_request(), } request = encode_request(request, module) return_vals = {} @@ -424,6 +469,7 @@ def response_to_hash(module, response): u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds'), u'messageRetentionDuration': response.get(u'messageRetentionDuration'), u'retainAckedMessages': response.get(u'retainAckedMessages'), + u'expirationPolicy': SubscriptionExpirationpolicy(response.get(u'expirationPolicy', {}), module).from_response(), } @@ -459,5 +505,20 @@ def from_response(self): return remove_nones_from_dict({u'pushEndpoint': self.request.get(u'pushEndpoint'), u'attributes': self.request.get(u'attributes')}) +class SubscriptionExpirationpolicy(object): + def __init__(self, request, module): + self.module = module + if request: + self.request = request + else: + self.request = {} + + def to_request(self): + return remove_nones_from_dict({u'ttl': self.request.get('ttl')}) + + def from_response(self): + return remove_nones_from_dict({u'ttl': self.request.get(u'ttl')}) + + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py index 09a9831a57c55b..45c09a1f298b1c 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py @@ -144,6 +144,29 @@ until they fall out of the messageRetentionDuration window. returned: success type: bool + expirationPolicy: + description: + - A policy that specifies the conditions for this subscription's expiration. + - A subscription is considered active as long as any connected subscriber is + successfully consuming messages from the subscription or is issuing operations + on the subscription. If expirationPolicy is not set, a default policy with + ttl of 31 days will be used. The minimum allowed value for expirationPolicy.ttl + is 1 day. + returned: success + type: complex + contains: + ttl: + description: + - Specifies the "time-to-live" duration for an associated resource. The + resource expires if it is not active for a period of ttl. The definition + of "activity" depends on the type of the associated resource. The minimum + and maximum allowed values for ttl depend on the type of the associated + resource, as well. If ttl is not set, the associated resource never expires. + - A duration in seconds with up to nine fractional digits, terminated by + 's'. + - Example - "3.5s". + returned: success + type: str ''' ################################################################################