-
Notifications
You must be signed in to change notification settings - Fork 965
/
cloud_storage.py
112 lines (91 loc) · 4.08 KB
/
cloud_storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
API operations on Cloud-based storages, such as Amazon Simple Storage Service (S3).
"""
import logging
from galaxy import exceptions
from galaxy import web
from galaxy.web.base.controller import BaseAPIController
from galaxy.managers import cloud_storage
log = logging.getLogger(__name__)
class CloudStorageController(BaseAPIController):
"""
RESTfull controller for interaction with Amazon S3.
"""
def __init__(self, app):
super(CloudStorageController, self).__init__(app)
self.cloud_storage_manager = cloud_storage.CloudStorageManager(app)
@web.expose_api
def index(self, trans, **kwargs):
"""
* GET /api/cloud_storage
Lists cloud-based containers (e.g., S3 bucket, Azure blob) user has defined.
:param trans:
:param kwargs:
:return: A list of cloud-based containers user has defined.
"""
# TODO: This can be implemented leveraging PluggedMedia objects (part of the user-based object store project)
trans.response.status = 501
return 'Not Implemented'
@web.expose_api
def download(self, trans, payload, **kwargs):
"""
* POST /api/cloud_storage/download
Downloads a given object from a given cloud-based container.
:type trans: galaxy.web.framework.webapp.GalaxyWebTransaction
:param trans: Galaxy web transaction
:type payload: dict
:param payload: A dictionary structure containing the following keys:
* history_id: the (encoded) id of history to which the object should be downloaded to.
:param kwargs:
:rtype: boolean
:return: True/False if the given object is successfully downloaded from the cloud-based storage.
"""
if not isinstance(payload, dict):
trans.response.status = 400
return {'status': 'error',
'message': 'Invalid payload data type. The payload is expected to be a dictionary, '
'but received data of type `%s`.' % str(type(payload))}
missing_arguments = []
encoded_history_id = payload.get("history_id", None)
if encoded_history_id is None:
missing_arguments.append("history_id")
provider = payload.get("provider", None)
if provider is None:
missing_arguments.append("provider")
container = payload.get("container", None)
if container is None:
missing_arguments.append("container")
obj = payload.get("object", None)
if obj is None:
missing_arguments.append("object")
credentials = payload.get("credentials", None)
if credentials is None:
missing_arguments.append("credentials")
if len(missing_arguments) > 0:
trans.response.status = 400
return {'status': 'error',
'message': "The following required arguments are missing in the payload: %s" % missing_arguments}
try:
history_id = self.decode_id(encoded_history_id)
except exceptions.MalformedId as e:
trans.response.status = 400
return {'status': 'error', 'message': 'Invalid history ID. {}'.format(e)}
status, message = self.cloud_storage_manager.download(trans=trans,
history_id=history_id,
provider=provider,
container=container,
obj=obj,
credentials=credentials)
trans.response.status = 200 if status == 'ok' else 500
return {'status': status, 'message': message}
@web.expose_api
def upload(self, trans, payload, **kwargs):
"""
* POST /api/cloud_storage/upload
Uploads a given dataset to a given cloud-based container.
:param trans:
:param payload:
:param kwargs:
:return:
"""
pass