Merge pull request #4610 from bennojoy/gcs_fix3

fix for overwrite in put operation
reviewable/pr18780/r1
Michael DeHaan 11 years ago
commit 52e35c5e6c

@ -69,7 +69,7 @@ options:
required: true required: true
default: null default: null
aliases: [] aliases: []
choices: [ 'upload', 'download', 'get_url', 'get_str' ] choices: [ 'get', 'put', 'get_url', 'get_str', 'delete', 'create' ]
gcs_secret_key: gcs_secret_key:
description: description:
- GCS secret key. If not set then the value of the GCS_SECRET_KEY environment variable is used. - GCS secret key. If not set then the value of the GCS_SECRET_KEY environment variable is used.
@ -89,10 +89,10 @@ author: benno@ansibleworks.com Note. Most of the code has been taken from the S3
EXAMPLES = ''' EXAMPLES = '''
# upload some content # upload some content
- gc_storage: bucket=mybucket object=key.txt src=/usr/local/myfile.txt mode=upload permission=public-read - gc_storage: bucket=mybucket object=key.txt src=/usr/local/myfile.txt mode=put permission=public-read
# download some content # download some content
- gc_storage: bucket=mybucket object=key.txt dest=/usr/local/myfile.txt mode=download - gc_storage: bucket=mybucket object=key.txt dest=/usr/local/myfile.txt mode=get
# Download an object as a string to use else where in your playbook # Download an object as a string to use else where in your playbook
- gc_storage: bucket=mybucket object=key.txt mode=get_str - gc_storage: bucket=mybucket object=key.txt mode=get_str
@ -263,8 +263,10 @@ def get_download_url(module, gs, bucket, obj, expiry):
def handle_get(module, gs, bucket, obj, overwrite, dest): def handle_get(module, gs, bucket, obj, overwrite, dest):
md5_remote = keysum(module, gs, bucket, obj) md5_remote = keysum(module, gs, bucket, obj)
md5_local = hashlib.md5(open(dest, 'rb').read()).hexdigest() md5_local = hashlib.md5(open(dest, 'rb').read()).hexdigest()
if md5_local == md5_remote and not overwrite: if md5_local == md5_remote:
module.exit_json(changed=False) module.exit_json(changed=False)
if md5_local != md5_remote and not overwrite:
module.exit_json(msg="WARNING: Checksums do not match. Use overwrite parameter to force download.", failed=True)
else: else:
download_gsfile(module, gs, bucket, obj, dest) download_gsfile(module, gs, bucket, obj, dest)
@ -278,12 +280,11 @@ def handle_put(module, gs, bucket, obj, overwrite, src, expiration):
md5_remote = keysum(module, gs, bucket, obj) md5_remote = keysum(module, gs, bucket, obj)
md5_local = hashlib.md5(open(src, 'rb').read()).hexdigest() md5_local = hashlib.md5(open(src, 'rb').read()).hexdigest()
if md5_local == md5_remote: if md5_local == md5_remote:
module.exit_json(msg="Local and remote object are identical.", changed=False) module.exit_json(msg="Local and remote object are identical", changed=False)
if md5_local != md5_remote and not overwrite:
module.exit_json(msg="WARNING: Checksums do not match. Use overwrite parameter to force upload.", failed=True)
else: else:
if overwrite: upload_gsfile(module, gs, bucket, obj, src, expiration)
upload_gsfile(module, gs, bucket, obj, src, expiration)
else:
module.exit_json(msg="WARNING: Checksums do not match. Use overwrite parameter to force upload.", failed=True)
if not bucket_rc: if not bucket_rc:
create_bucket(module, gs, bucket) create_bucket(module, gs, bucket)
@ -353,7 +354,7 @@ def main():
if dest: if dest:
dest = os.path.expanduser(dest) dest = os.path.expanduser(dest)
mode = module.params.get('mode') mode = module.params.get('mode')
expiry = module.params.get('expiry') expiry = module.params.get('expiration')
gs_secret_key = module.params.get('gs_secret_key') gs_secret_key = module.params.get('gs_secret_key')
gs_access_key = module.params.get('gs_access_key') gs_access_key = module.params.get('gs_access_key')
overwrite = module.params.get('overwrite') overwrite = module.params.get('overwrite')

Loading…
Cancel
Save