mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-08 20:00:29 -07:00
Ansible Storage Upload/Download
This commit is contained in:
parent
daaccb8079
commit
72cc27fec1
2 changed files with 19 additions and 27 deletions
|
@ -87,25 +87,16 @@ class GcpSession(object):
|
||||||
except getattr(requests.exceptions, 'RequestException') as inst:
|
except getattr(requests.exceptions, 'RequestException') as inst:
|
||||||
self.module.fail_json(msg=inst.message)
|
self.module.fail_json(msg=inst.message)
|
||||||
|
|
||||||
def post(self, url, body=None, headers=None, **kwargs):
|
def post(self, url, body=None, headers={}, **kwargs):
|
||||||
if headers:
|
kwargs.update({'json': body, 'headers': self._merge_dictionaries(headers, self._headers())})
|
||||||
headers = self.merge_dictionaries(headers, self._headers())
|
|
||||||
else:
|
|
||||||
headers = self._headers()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.session().post(url, json=body, headers=headers)
|
return self.session().post(url, data=file_contents, headers=headers)
|
||||||
except getattr(requests.exceptions, 'RequestException') as inst:
|
except getattr(requests.exceptions, 'RequestException') as inst:
|
||||||
self.module.fail_json(msg=inst.message)
|
self.module.fail_json(msg=inst.message)
|
||||||
|
|
||||||
def post_contents(self, url, file_contents=None, headers=None, **kwargs):
|
def post_contents(self, url, file_contents=None, headers={}, **kwargs):
|
||||||
if headers:
|
|
||||||
headers = self.merge_dictionaries(headers, self._headers())
|
|
||||||
else:
|
|
||||||
headers = self._headers()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.session().post(url, data=file_contents, headers=headers)
|
return self.session().post(url, data=file_contents, headers=self._headers())
|
||||||
except getattr(requests.exceptions, 'RequestException') as inst:
|
except getattr(requests.exceptions, 'RequestException') as inst:
|
||||||
self.module.fail_json(msg=inst.message)
|
self.module.fail_json(msg=inst.message)
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,15 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
|
'status': ["preview"],
|
||||||
|
'supported_by': 'community'}
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -78,15 +79,15 @@ extends_documentation_fragment: gcp
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: create a object
|
- name: create a object
|
||||||
gcp_storage_object:
|
gcp_storage_object:
|
||||||
name: ansible-storage-module
|
name: ansible-storage-module
|
||||||
action: download
|
action: download
|
||||||
bucket: ansible-bucket
|
bucket: ansible-bucket
|
||||||
src: modules.zip
|
src: modules.zip
|
||||||
dest: "~/modules.zip"
|
dest: "~/modules.zip"
|
||||||
project: test_project
|
project: "test_project"
|
||||||
auth_kind: serviceaccount
|
auth_kind: "serviceaccount"
|
||||||
service_account_file: "/tmp/auth.pem"
|
service_account_file: "/tmp/auth.pem"
|
||||||
state: present
|
state: present
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -144,7 +145,7 @@ def main():
|
||||||
overwrite=dict(type='bool'),
|
overwrite=dict(type='bool'),
|
||||||
src=dict(type='path'),
|
src=dict(type='path'),
|
||||||
dest=dict(type='path'),
|
dest=dict(type='path'),
|
||||||
bucket=dict(type='str'),
|
bucket=dict(type='str')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -276,7 +277,7 @@ def object_headers(module):
|
||||||
return {
|
return {
|
||||||
"name": module.params['dest'],
|
"name": module.params['dest'],
|
||||||
"Content-Type": mimetypes.guess_type(module.params['src'])[0],
|
"Content-Type": mimetypes.guess_type(module.params['src'])[0],
|
||||||
"Content-Length": str(os.path.getsize(module.params['src'])),
|
"Content-Length": str(os.path.getsize(module.params['src']))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue