mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-04 05:04:22 -07:00
Bug fixes for GCP modules (#52618)
This commit is contained in:
parent
0b16286254
commit
9291f48964
6 changed files with 134 additions and 23 deletions
|
@ -71,6 +71,7 @@ options:
|
||||||
- SOA
|
- SOA
|
||||||
- SPF
|
- SPF
|
||||||
- SRV
|
- SRV
|
||||||
|
- TLSA
|
||||||
- TXT
|
- TXT
|
||||||
ttl:
|
ttl:
|
||||||
description:
|
description:
|
||||||
|
@ -83,7 +84,6 @@ options:
|
||||||
managed_zone:
|
managed_zone:
|
||||||
description:
|
description:
|
||||||
- Identifies the managed zone addressed by this request.
|
- Identifies the managed zone addressed by this request.
|
||||||
- Can be the managed zone name or id.
|
|
||||||
- 'This field represents a link to a ManagedZone resource in GCP. It can be specified
|
- 'This field represents a link to a ManagedZone resource in GCP. It can be specified
|
||||||
in two ways. First, you can place in the name of the resource here as a string
|
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_dns_managed_zone
|
Alternatively, you can add `register: name-of-resource` to a gcp_dns_managed_zone
|
||||||
|
@ -143,7 +143,6 @@ target:
|
||||||
managed_zone:
|
managed_zone:
|
||||||
description:
|
description:
|
||||||
- Identifies the managed zone addressed by this request.
|
- Identifies the managed zone addressed by this request.
|
||||||
- Can be the managed zone name or id.
|
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
'''
|
'''
|
||||||
|
@ -170,7 +169,7 @@ def main():
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
type=dict(required=True, type='str', choices=['A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR', 'SOA', 'SPF', 'SRV', 'TXT']),
|
type=dict(required=True, type='str', choices=['A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR', 'SOA', 'SPF', 'SRV', 'TLSA', 'TXT']),
|
||||||
ttl=dict(type='int'),
|
ttl=dict(type='int'),
|
||||||
target=dict(type='list', elements='str'),
|
target=dict(type='list', elements='str'),
|
||||||
managed_zone=dict(required=True),
|
managed_zone=dict(required=True),
|
||||||
|
@ -358,13 +357,12 @@ class SOAForwardable(object):
|
||||||
|
|
||||||
|
|
||||||
def prefetch_soa_resource(module):
|
def prefetch_soa_resource(module):
|
||||||
name = module.params['name'].split('.')[1:]
|
|
||||||
|
|
||||||
resource = SOAForwardable(
|
resource = SOAForwardable(
|
||||||
{
|
{
|
||||||
'type': 'SOA',
|
'type': 'SOA',
|
||||||
'managed_zone': module.params['managed_zone'],
|
'managed_zone': module.params['managed_zone'],
|
||||||
'name': '.'.join(name),
|
'name': replace_resource_dict(module.params['managed_zone'], 'dnsName'),
|
||||||
'project': module.params['project'],
|
'project': module.params['project'],
|
||||||
'scopes': module.params['scopes'],
|
'scopes': module.params['scopes'],
|
||||||
'service_account_file': module.params['service_account_file'],
|
'service_account_file': module.params['service_account_file'],
|
||||||
|
|
|
@ -43,7 +43,6 @@ options:
|
||||||
managed_zone:
|
managed_zone:
|
||||||
description:
|
description:
|
||||||
- Identifies the managed zone addressed by this request.
|
- Identifies the managed zone addressed by this request.
|
||||||
- Can be the managed zone name or id.
|
|
||||||
- 'This field represents a link to a ManagedZone resource in GCP. It can be specified
|
- 'This field represents a link to a ManagedZone resource in GCP. It can be specified
|
||||||
in two ways. First, you can place in the name of the resource here as a string
|
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_dns_managed_zone
|
Alternatively, you can add `register: name-of-resource` to a gcp_dns_managed_zone
|
||||||
|
@ -90,7 +89,6 @@ items:
|
||||||
managed_zone:
|
managed_zone:
|
||||||
description:
|
description:
|
||||||
- Identifies the managed zone addressed by this request.
|
- Identifies the managed zone addressed by this request.
|
||||||
- Can be the managed zone name or id.
|
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -51,7 +51,7 @@ options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of the subscription.
|
- Name of the subscription.
|
||||||
required: false
|
required: true
|
||||||
topic:
|
topic:
|
||||||
description:
|
description:
|
||||||
- A reference to a Topic resource.
|
- A reference to a Topic resource.
|
||||||
|
@ -59,7 +59,12 @@ options:
|
||||||
in two ways. First, you can place in the name of the resource here as a string
|
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
|
Alternatively, you can add `register: name-of-resource` to a gcp_pubsub_topic
|
||||||
task and then set this topic field to "{{ name-of-resource }}"'
|
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
|
required: false
|
||||||
|
version_added: 2.8
|
||||||
push_config:
|
push_config:
|
||||||
description:
|
description:
|
||||||
- If push delivery is used with this subscription, this field is used to configure
|
- If push delivery is used with this subscription, this field is used to configure
|
||||||
|
@ -71,6 +76,25 @@ options:
|
||||||
description:
|
description:
|
||||||
- A URL locating the endpoint to which messages should be pushed.
|
- A URL locating the endpoint to which messages should be pushed.
|
||||||
- For example, a Webhook endpoint might use "U(https://example.com/push".)
|
- 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
|
required: false
|
||||||
ack_deadline_seconds:
|
ack_deadline_seconds:
|
||||||
description:
|
description:
|
||||||
|
@ -90,6 +114,9 @@ options:
|
||||||
redeliver the message.
|
redeliver the message.
|
||||||
required: false
|
required: false
|
||||||
extends_documentation_fragment: gcp
|
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 = '''
|
EXAMPLES = '''
|
||||||
|
@ -124,6 +151,11 @@ topic:
|
||||||
- A reference to a Topic resource.
|
- A reference to a Topic resource.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
|
labels:
|
||||||
|
description:
|
||||||
|
- A set of key/value label pairs to assign to this Subscription.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
pushConfig:
|
pushConfig:
|
||||||
description:
|
description:
|
||||||
- If push delivery is used with this subscription, this field is used to configure
|
- If push delivery is used with this subscription, this field is used to configure
|
||||||
|
@ -138,6 +170,25 @@ pushConfig:
|
||||||
- For example, a Webhook endpoint might use "U(https://example.com/push".)
|
- For example, a Webhook endpoint might use "U(https://example.com/push".)
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
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:
|
ackDeadlineSeconds:
|
||||||
description:
|
description:
|
||||||
- This value is the maximum time after a subscriber receives a message before the
|
- This value is the maximum time after a subscriber receives a message before the
|
||||||
|
@ -176,9 +227,10 @@ def main():
|
||||||
module = GcpModule(
|
module = GcpModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
name=dict(type='str'),
|
name=dict(required=True, type='str'),
|
||||||
topic=dict(),
|
topic=dict(required=True),
|
||||||
push_config=dict(type='dict', options=dict(push_endpoint=dict(type='str'))),
|
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'),
|
ack_deadline_seconds=dict(type='int'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -194,7 +246,7 @@ def main():
|
||||||
if fetch:
|
if fetch:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if is_different(module, fetch):
|
if is_different(module, fetch):
|
||||||
update(module, self_link(module))
|
update(module, self_link(module), fetch)
|
||||||
fetch = fetch_resource(module, self_link(module))
|
fetch = fetch_resource(module, self_link(module))
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
|
@ -218,8 +270,23 @@ def create(module, link):
|
||||||
return return_if_object(module, auth.put(link, resource_to_request(module)))
|
return return_if_object(module, auth.put(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
def update(module, link):
|
def update(module, link, fetch):
|
||||||
module.fail_json(msg="Subscription cannot be edited")
|
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')
|
||||||
|
return ','.join(update_mask)
|
||||||
|
|
||||||
|
|
||||||
def delete(module, link):
|
def delete(module, link):
|
||||||
|
@ -231,6 +298,7 @@ def resource_to_request(module):
|
||||||
request = {
|
request = {
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'topic': replace_resource_dict(module.params.get(u'topic', {}), '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'pushConfig': SubscriptionPushconfig(module.params.get('push_config', {}), module).to_request(),
|
||||||
u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds'),
|
u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds'),
|
||||||
}
|
}
|
||||||
|
@ -302,8 +370,9 @@ def is_different(module, response):
|
||||||
# This is for doing comparisons with Ansible's current parameters.
|
# This is for doing comparisons with Ansible's current parameters.
|
||||||
def response_to_hash(module, response):
|
def response_to_hash(module, response):
|
||||||
return {
|
return {
|
||||||
u'name': response.get(u'name'),
|
u'name': module.params.get('name'),
|
||||||
u'topic': response.get(u'topic'),
|
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'pushConfig': SubscriptionPushconfig(response.get(u'pushConfig', {}), module).from_response(),
|
||||||
u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds'),
|
u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds'),
|
||||||
}
|
}
|
||||||
|
@ -335,10 +404,10 @@ class SubscriptionPushconfig(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
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):
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -67,6 +67,11 @@ items:
|
||||||
- A reference to a Topic resource.
|
- A reference to a Topic resource.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
|
labels:
|
||||||
|
description:
|
||||||
|
- A set of key/value label pairs to assign to this Subscription.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
pushConfig:
|
pushConfig:
|
||||||
description:
|
description:
|
||||||
- If push delivery is used with this subscription, this field is used to configure
|
- If push delivery is used with this subscription, this field is used to configure
|
||||||
|
@ -81,6 +86,26 @@ items:
|
||||||
- For example, a Webhook endpoint might use "U(https://example.com/push".)
|
- For example, a Webhook endpoint might use "U(https://example.com/push".)
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
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:
|
ackDeadlineSeconds:
|
||||||
description:
|
description:
|
||||||
- This value is the maximum time after a subscriber receives a message before
|
- This value is the maximum time after a subscriber receives a message before
|
||||||
|
|
|
@ -50,8 +50,16 @@ options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of the topic.
|
- Name of the topic.
|
||||||
|
required: true
|
||||||
|
labels:
|
||||||
|
description:
|
||||||
|
- A set of key/value label pairs to assign to this Topic.
|
||||||
required: false
|
required: false
|
||||||
|
version_added: 2.8
|
||||||
extends_documentation_fragment: gcp
|
extends_documentation_fragment: gcp
|
||||||
|
notes:
|
||||||
|
- 'API Reference: U(https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics)'
|
||||||
|
- 'Managing Topics: U(https://cloud.google.com/pubsub/docs/admin#managing_topics)'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -70,6 +78,11 @@ name:
|
||||||
- Name of the topic.
|
- Name of the topic.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
|
labels:
|
||||||
|
description:
|
||||||
|
- A set of key/value label pairs to assign to this Topic.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
'''
|
'''
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -87,7 +100,11 @@ import json
|
||||||
def main():
|
def main():
|
||||||
"""Main function"""
|
"""Main function"""
|
||||||
|
|
||||||
module = GcpModule(argument_spec=dict(state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(type='str')))
|
module = GcpModule(
|
||||||
|
argument_spec=dict(
|
||||||
|
state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(required=True, type='str'), labels=dict(type='dict')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
|
||||||
|
@ -125,8 +142,7 @@ def create(module, link):
|
||||||
|
|
||||||
|
|
||||||
def update(module, link):
|
def update(module, link):
|
||||||
auth = GcpSession(module, 'pubsub')
|
module.fail_json(msg="Topic cannot be edited")
|
||||||
return return_if_object(module, auth.put(link, resource_to_request(module)))
|
|
||||||
|
|
||||||
|
|
||||||
def delete(module, link):
|
def delete(module, link):
|
||||||
|
@ -135,7 +151,7 @@ def delete(module, link):
|
||||||
|
|
||||||
|
|
||||||
def resource_to_request(module):
|
def resource_to_request(module):
|
||||||
request = {u'name': module.params.get('name')}
|
request = {u'name': module.params.get('name'), u'labels': module.params.get('labels')}
|
||||||
request = encode_request(request, module)
|
request = encode_request(request, module)
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -203,7 +219,7 @@ def is_different(module, response):
|
||||||
# Remove unnecessary properties from the response.
|
# Remove unnecessary properties from the response.
|
||||||
# This is for doing comparisons with Ansible's current parameters.
|
# This is for doing comparisons with Ansible's current parameters.
|
||||||
def response_to_hash(module, response):
|
def response_to_hash(module, response):
|
||||||
return {u'name': response.get(u'name')}
|
return {u'name': response.get(u'name'), u'labels': response.get(u'labels')}
|
||||||
|
|
||||||
|
|
||||||
def decode_request(response, module):
|
def decode_request(response, module):
|
||||||
|
|
|
@ -62,6 +62,11 @@ items:
|
||||||
- Name of the topic.
|
- Name of the topic.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
|
labels:
|
||||||
|
description:
|
||||||
|
- A set of key/value label pairs to assign to this Topic.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
'''
|
'''
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue