Ryan Brown 2018-10-18 10:55:42 -04:00 committed by GitHub
commit 18a088c64e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 2452 additions and 1095 deletions

View file

@ -59,6 +59,11 @@ options:
bucket:
description:
- The name of the bucket.
- 'This field represents a link to a Bucket resource in GCP. It can be specified in
two ways. You can add `register: name-of-resource` to a gcp_storage_bucket task
and then set this bucket field to "{{ name-of-resource }}" Alternatively, you can
set this bucket to a dictionary with the name key where the value is the name of
your Bucket.'
required: true
domain:
description:
@ -139,6 +144,11 @@ options:
bucket:
description:
- The name of the bucket.
- 'This field represents a link to a Bucket resource in GCP. It can be specified in
two ways. You can add `register: name-of-resource` to a gcp_storage_bucket task
and then set this bucket field to "{{ name-of-resource }}" Alternatively, you can
set this bucket to a dictionary with the name key where the value is the name of
your Bucket.'
required: true
domain:
description:
@ -358,7 +368,7 @@ EXAMPLES = '''
gcp_storage_bucket:
name: ansible-storage-module
project: "test_project"
auth_kind: "service_account"
auth_kind: "serviceaccount"
service_account_file: "/tmp/auth.pem"
state: present
'''
@ -396,7 +406,7 @@ RETURN = '''
entity would be domain-example.com.
returned: success
type: str
entity_id:
entityId:
description:
- The ID for the entity.
returned: success
@ -406,13 +416,13 @@ RETURN = '''
- The ID of the access-control entry.
returned: success
type: str
project_team:
projectTeam:
description:
- The project team associated with the entity.
returned: success
type: complex
contains:
project_number:
projectNumber:
description:
- The project team associated with the entity.
returned: success
@ -433,7 +443,7 @@ RETURN = '''
returned: success
type: complex
contains:
max_age_seconds:
maxAgeSeconds:
description:
- The value, in seconds, to return in the Access-Control-Max-Age header used in preflight
responses.
@ -451,13 +461,13 @@ RETURN = '''
- 'Note: "*" is permitted in the list of origins, and means "any Origin".'
returned: success
type: list
response_header:
responseHeader:
description:
- The list of HTTP headers other than the simple response headers to give permission
for the user-agent to share across domains.
returned: success
type: list
default_object_acl:
defaultObjectAcl:
description:
- Default access controls to apply to new objects when no ACL is provided.
returned: success
@ -489,7 +499,7 @@ RETURN = '''
entity would be domain-example.com.
returned: success
type: str
entity_id:
entityId:
description:
- The ID for the entity.
returned: success
@ -509,13 +519,13 @@ RETURN = '''
- The name of the object, if applied to an object.
returned: success
type: str
project_team:
projectTeam:
description:
- The project team associated with the entity.
returned: success
type: complex
contains:
project_number:
projectNumber:
description:
- The project team associated with the entity.
returned: success
@ -555,7 +565,7 @@ RETURN = '''
returned: success
type: complex
contains:
storage_class:
storageClass:
description:
- Target storage class. Required iff the type of the action is SetStorageClass.
returned: success
@ -571,32 +581,32 @@ RETURN = '''
returned: success
type: complex
contains:
age_days:
ageDays:
description:
- Age of an object (in days). This condition is satisfied when an object reaches the
specified age.
returned: success
type: int
created_before:
createdBefore:
description:
- A date in RFC 3339 format with only the date part (for instance, "2013-01-15").
This condition is satisfied when an object is created before midnight of the specified
date in UTC.
returned: success
type: str
is_live:
isLive:
description:
- Relevant only for versioned objects. If the value is true, this condition matches
live objects; if the value is false, it matches archived objects.
returned: success
type: bool
matches_storage_class:
matchesStorageClass:
description:
- Objects having any of the storage classes specified by this condition will be matched.
Values include MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, STANDARD, and DURABLE_REDUCED_AVAILABILITY.
returned: success
type: list
num_newer_versions:
numNewerVersions:
description:
- Relevant only for versioned objects. If the value is N, this condition is satisfied
when there are at least N versions (including the live version) newer than this
@ -617,12 +627,12 @@ RETURN = '''
returned: success
type: complex
contains:
log_bucket:
logBucket:
description:
- The destination bucket where the current bucket's logs should be placed.
returned: success
type: str
log_object_prefix:
logObjectPrefix:
description:
- A prefix for log object names.
returned: success
@ -648,17 +658,17 @@ RETURN = '''
- The entity, in the form project-owner-projectId.
returned: success
type: str
entity_id:
entityId:
description:
- The ID for the entity.
returned: success
type: str
project_number:
projectNumber:
description:
- The project number of the project the bucket belongs to.
returned: success
type: int
storage_class:
storageClass:
description:
- The bucket's default storage class, used whenever no storageClass is specified for
a newly-created object. This defines how objects in the bucket are stored and determines
@ -668,7 +678,7 @@ RETURN = '''
For more information, see storage classes.
returned: success
type: str
time_created:
timeCreated:
description:
- The creation time of the bucket in RFC 3339 format.
returned: success
@ -696,14 +706,14 @@ RETURN = '''
returned: success
type: complex
contains:
main_page_suffix:
mainPageSuffix:
description:
- If the requested object path is missing, the service will ensure the path has a
trailing '/', append this suffix, and attempt to retrieve the resulting object.
This allows the creation of index.html objects to represent directory pages.
returned: success
type: str
not_found_page:
notFoundPage:
description:
- If the requested object path is missing, and any mainPageSuffix object is missing,
if applicable, the service will return the named object from this bucket as the
@ -715,7 +725,7 @@ RETURN = '''
- A valid API project identifier.
returned: success
type: str
predefined_default_object_acl:
predefinedDefaultObjectAcl:
description:
- Apply a predefined set of default object access controls to this bucket.
- 'Acceptable values are: - "authenticatedRead": Object owner gets OWNER access,
@ -840,7 +850,8 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
fetch = update(module, self_link(module), kind)
update(module, self_link(module), kind)
fetch = fetch_resource(module, self_link(module), kind)
changed = True
else:
delete(module, self_link(module), kind)
@ -899,9 +910,9 @@ def resource_to_request(module):
return return_vals
def fetch_resource(module, link, kind):
def fetch_resource(module, link, kind, allow_not_found=True):
auth = GcpSession(module, 'storage')
return return_if_object(module, auth.get(link), kind)
return return_if_object(module, auth.get(link), kind, allow_not_found)
def self_link(module):
@ -912,9 +923,9 @@ def collection(module):
return "https://www.googleapis.com/storage/v1/b?project={project}".format(**module.params)
def return_if_object(module, response, kind):
def return_if_object(module, response, kind, allow_not_found=False):
# If not found, return nothing.
if response.status_code == 404:
if allow_not_found and response.status_code == 404:
return None
# If no content, return nothing.
@ -929,8 +940,6 @@ def return_if_object(module, response, kind):
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
if result['kind'] != kind:
module.fail_json(msg="Incorrect result: {kind}".format(**result))
return result