return values

This commit is contained in:
Alex Stephen 2019-11-05 16:31:31 -08:00
parent c1becca3e9
commit a0bc9ad651

View file

@ -123,11 +123,6 @@ EXAMPLES = """
""" """
RETURN = """ RETURN = """
acl:
description:
- The ACL on the object
returned: download, upload
type: str
bucket: bucket:
description: description:
- The bucket where the object is contained. - The bucket where the object is contained.
@ -143,26 +138,20 @@ chunk_size:
- Get the blobs default chunk size - Get the blobs default chunk size
returned: download, upload returned: download, upload
type: str type: str
overwrite: media_link:
description: descrpition:
- "'Overwrite the file on the bucket/local machine. If overwrite is false and a - The link for the media
difference exists between GCS + local, module will fail with error' ." returned: download, upload
returned: success
type: bool
src:
description:
- Source location of file (may be local machine or cloud depending on action).
returned: success
type: str type: str
dest: self_link:
description: descrpition:
- Destination location of file (may be local machine or cloud depending on action). - The self_link for the media.
returned: success returned: download, upload
type: str type: str
bucket: storage_class:
description: descrpition:
- The name of the bucket. - The storage class for the object.
returned: success returned: download, upload
type: str type: str
""" """
@ -267,7 +256,7 @@ def download_file(module, client, name, dest):
blob = Blob(name, bucket) blob = Blob(name, bucket)
with open(dest, "wb") as file_obj: with open(dest, "wb") as file_obj:
blob.download_to_file(file_obj) blob.download_to_file(file_obj)
return {} return blob_to_dict(blob)
except google.cloud.exceptions.NotFound as e: except google.cloud.exceptions.NotFound as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
@ -278,7 +267,7 @@ def upload_file(module, client, src, dest):
blob = Blob(dest, bucket) blob = Blob(dest, bucket)
with open(src, "r") as file_obj: with open(src, "r") as file_obj:
blob.upload_from_file(file_obj) blob.upload_from_file(file_obj)
return {} return blob_to_dict(blob)
except google.cloud.exceptions.GoogleCloudError as e: except google.cloud.exceptions.GoogleCloudError as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
@ -308,6 +297,17 @@ def remote_file_path(module):
else: else:
return module.params["dest"] return module.params["dest"]
def blob_to_dict(blob):
return {
'bucket': {
'name': blob.bucket.path
},
'cache_control': blob.cache_control,
'chunk_size': blob.chunk_size,
'media_link': blob.media_link,
'self_link': blob.self_link,
'storage_class': blob.storage_class
}
if __name__ == "__main__": if __name__ == "__main__":
main() main()