Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Add expiration policy to pubsub subscription resource #240

Merged
merged 1 commit into from
May 3, 2019
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
61 changes: 61 additions & 0 deletions lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down Expand Up @@ -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
'''

################################################################################
Expand Down Expand Up @@ -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'))),
)
)

Expand Down Expand Up @@ -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)


Expand All @@ -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 = {}
Expand Down Expand Up @@ -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(),
}


Expand Down Expand Up @@ -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()
23 changes: 23 additions & 0 deletions lib/ansible/modules/cloud/google/gcp_pubsub_subscription_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''

################################################################################
Expand Down