examples showing an improper auth value (#87)

<!-- This change is generated by MagicModules. -->
/cc @rambleraptor
This commit is contained in:
The Magician 2018-09-07 14:15:36 -07:00 committed by Alex Stephen
commit 0a18332815
98 changed files with 2171 additions and 1727 deletions

View file

@ -51,15 +51,21 @@ options:
name:
description:
- Name of the subscription.
required: false
required: true
topic:
description:
- A reference to a Topic resource.
- 'This field represents a link to a Topic resource in GCP. It can be specified
in two ways. First, you can place in the name of the resource here as a string
Alternatively, you can add `register: name-of-resource` to a gcp_pubsub_topic
task and then set this topic field to "{{ name-of-resource }}"'
in two ways. First, you can place a dictionary with key ''name'' and value of
your resource''s name Alternatively, you can add `register: name-of-resource`
to a gcp_pubsub_topic task and then set this topic field to "{{ name-of-resource
}}"'
required: true
labels:
description:
- A set of key/value label pairs to assign to this Subscription.
required: false
version_added: 2.8
push_config:
description:
- If push delivery is used with this subscription, this field is used to configure
@ -71,6 +77,25 @@ options:
description:
- A URL locating the endpoint to which messages should be pushed.
- For example, a Webhook endpoint might use "U(https://example.com/push".)
required: true
attributes:
description:
- Endpoint configuration attributes.
- Every endpoint has a set of API supported attributes that can be used to
control different aspects of the message delivery.
- The currently supported attribute is x-goog-version, which you can use to
change the format of the pushed message. This attribute indicates the version
of the data expected by the endpoint. This controls the shape of the pushed
message (i.e., its fields and metadata). The endpoint version is based on
the version of the Pub/Sub API.
- If not present during the subscriptions.create call, it will default to
the version of the API used to make such call. If not present during a subscriptions.modifyPushConfig
call, its value will not be changed. subscriptions.get calls will always
return a valid version, even if the subscription was created without this
attribute.
- 'The possible values for this attribute are: - v1beta1: uses the push format
defined in the v1beta1 Pub/Sub API.'
- "- v1 or v1beta2: uses the push format defined in the v1 Pub/Sub API."
required: false
ack_deadline_seconds:
description:
@ -89,23 +114,48 @@ options:
- If the subscriber never acknowledges the message, the Pub/Sub system will eventually
redeliver the message.
required: false
message_retention_duration:
description:
- How long to retain unacknowledged messages in the subscription's backlog, from
the moment a message is published. If retainAckedMessages is true, then this
also configures the retention of acknowledged messages, and thus configures
how far back in time a subscriptions.seek can be done. Defaults to 7 days. Cannot
be more than 7 days (`"604800s"`) or less than 10 minutes (`"600s"`).
- 'A duration in seconds with up to nine fractional digits, terminated by ''s''.
Example: `"600.5s"`.'
required: false
default: 604800s
version_added: 2.8
retain_acked_messages:
description:
- Indicates whether to retain acknowledged messages. If `true`, then messages
are not expunged from the subscription's backlog, even if they are acknowledged,
until they fall out of the messageRetentionDuration window.
required: false
type: bool
version_added: 2.8
extends_documentation_fragment: gcp
notes:
- 'API Reference: U(https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions)'
- 'Managing Subscriptions: U(https://cloud.google.com/pubsub/docs/admin#managing_subscriptions)'
'''
EXAMPLES = '''
- name: create a topic
gcp_pubsub_topic:
name: "topic-subscription"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
name: topic-subscription
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: topic
- name: create a subscription
gcp_pubsub_subscription:
name: "test_object"
topic: "{{ topic }}"
push_config:
push_endpoint: https://myapp.graphite.cloudnativeapp.com/webhook/sub1
ack_deadline_seconds: 300
project: "test_project"
auth_kind: "serviceaccount"
@ -123,7 +173,12 @@ topic:
description:
- A reference to a Topic resource.
returned: success
type: str
type: dict
labels:
description:
- A set of key/value label pairs to assign to this Subscription.
returned: success
type: dict
pushConfig:
description:
- If push delivery is used with this subscription, this field is used to configure
@ -138,6 +193,25 @@ pushConfig:
- For example, a Webhook endpoint might use "U(https://example.com/push".)
returned: success
type: str
attributes:
description:
- Endpoint configuration attributes.
- Every endpoint has a set of API supported attributes that can be used to control
different aspects of the message delivery.
- The currently supported attribute is x-goog-version, which you can use to
change the format of the pushed message. This attribute indicates the version
of the data expected by the endpoint. This controls the shape of the pushed
message (i.e., its fields and metadata). The endpoint version is based on
the version of the Pub/Sub API.
- If not present during the subscriptions.create call, it will default to the
version of the API used to make such call. If not present during a subscriptions.modifyPushConfig
call, its value will not be changed. subscriptions.get calls will always return
a valid version, even if the subscription was created without this attribute.
- 'The possible values for this attribute are: - v1beta1: uses the push format
defined in the v1beta1 Pub/Sub API.'
- "- v1 or v1beta2: uses the push format defined in the v1 Pub/Sub API."
returned: success
type: dict
ackDeadlineSeconds:
description:
- This value is the maximum time after a subscriber receives a message before the
@ -156,6 +230,24 @@ ackDeadlineSeconds:
redeliver the message.
returned: success
type: int
messageRetentionDuration:
description:
- How long to retain unacknowledged messages in the subscription's backlog, from
the moment a message is published. If retainAckedMessages is true, then this also
configures the retention of acknowledged messages, and thus configures how far
back in time a subscriptions.seek can be done. Defaults to 7 days. Cannot be more
than 7 days (`"604800s"`) or less than 10 minutes (`"600s"`).
- 'A duration in seconds with up to nine fractional digits, terminated by ''s''.
Example: `"600.5s"`.'
returned: success
type: str
retainAckedMessages:
description:
- Indicates whether to retain acknowledged messages. If `true`, then messages are
not expunged from the subscription's backlog, even if they are acknowledged, until
they fall out of the messageRetentionDuration window.
returned: success
type: bool
'''
################################################################################
@ -176,10 +268,13 @@ def main():
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'),
topic=dict(),
push_config=dict(type='dict', options=dict(push_endpoint=dict(type='str'))),
name=dict(required=True, type='str'),
topic=dict(required=True, type='dict'),
labels=dict(type='dict'),
push_config=dict(type='dict', options=dict(push_endpoint=dict(required=True, type='str'), attributes=dict(type='dict'))),
ack_deadline_seconds=dict(type='int'),
message_retention_duration=dict(default='604800s', type='str'),
retain_acked_messages=dict(type='bool'),
)
)
@ -194,7 +289,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
update(module, self_link(module))
update(module, self_link(module), fetch)
fetch = fetch_resource(module, self_link(module))
changed = True
else:
@ -218,8 +313,27 @@ def create(module, link):
return return_if_object(module, auth.put(link, resource_to_request(module)))
def update(module, link):
module.fail_json(msg="Subscription cannot be edited")
def update(module, link, fetch):
auth = GcpSession(module, 'pubsub')
params = {'updateMask': updateMask(resource_to_request(module), response_to_hash(module, fetch))}
request = resource_to_request(module)
del request['name']
return return_if_object(module, auth.patch(link, request, params=params))
def updateMask(request, response):
update_mask = []
if request.get('labels') != response.get('labels'):
update_mask.append('labels')
if request.get('pushConfig') != response.get('pushConfig'):
update_mask.append('pushConfig')
if request.get('ackDeadlineSeconds') != response.get('ackDeadlineSeconds'):
update_mask.append('ackDeadlineSeconds')
if request.get('messageRetentionDuration') != response.get('messageRetentionDuration'):
update_mask.append('messageRetentionDuration')
if request.get('retainAckedMessages') != response.get('retainAckedMessages'):
update_mask.append('retainAckedMessages')
return ','.join(update_mask)
def delete(module, link):
@ -231,8 +345,11 @@ def resource_to_request(module):
request = {
u'name': module.params.get('name'),
u'topic': replace_resource_dict(module.params.get(u'topic', {}), 'name'),
u'labels': module.params.get('labels'),
u'pushConfig': SubscriptionPushconfig(module.params.get('push_config', {}), module).to_request(),
u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds'),
u'messageRetentionDuration': module.params.get('message_retention_duration'),
u'retainAckedMessages': module.params.get('retain_acked_messages'),
}
request = encode_request(request, module)
return_vals = {}
@ -302,10 +419,13 @@ def is_different(module, response):
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'name': response.get(u'name'),
u'topic': response.get(u'topic'),
u'name': module.params.get('name'),
u'topic': replace_resource_dict(module.params.get(u'topic', {}), 'name'),
u'labels': response.get(u'labels'),
u'pushConfig': SubscriptionPushconfig(response.get(u'pushConfig', {}), module).from_response(),
u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds'),
u'messageRetentionDuration': response.get(u'messageRetentionDuration'),
u'retainAckedMessages': response.get(u'retainAckedMessages'),
}
@ -335,10 +455,10 @@ class SubscriptionPushconfig(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({u'pushEndpoint': self.request.get('push_endpoint')})
return remove_nones_from_dict({u'pushEndpoint': self.request.get('push_endpoint'), u'attributes': self.request.get('attributes')})
def from_response(self):
return remove_nones_from_dict({u'pushEndpoint': self.request.get(u'pushEndpoint')})
return remove_nones_from_dict({u'pushEndpoint': self.request.get(u'pushEndpoint'), u'attributes': self.request.get(u'attributes')})
if __name__ == '__main__':