1
+ from abc import ABCMeta , abstractmethod
2
+ from logging import getLogger
3
+ from typing import List
4
+
5
+ from naas_models .pydantic .storage_p2p import *
6
+ from .models .Storage import Storage , Object
7
+
8
+
9
+ # Secondary Adaptor
10
+ from naas_python .utils .exceptions import NaasException
11
+
12
+ logger = getLogger (__name__ )
13
+
14
+ class IStorageAdaptor (metaclass = ABCMeta ):
15
+ @abstractmethod
16
+ def create_workspace_storage (self ,
17
+ workspace_id : str ,
18
+ storage_name : Storage .__fields__ ['name' ],
19
+ ) -> dict [str , str ]:
20
+ raise NotImplementedError
21
+
22
+ @abstractmethod
23
+ def delete_workspace_storage (self ,
24
+ workspace_id : str ,
25
+ storage_name : Storage .__fields__ ['name' ],
26
+ ) -> dict :
27
+ raise NotImplementedError
28
+
29
+ @abstractmethod
30
+ def list_workspace_storage (self ,
31
+ workspace_id : str ,
32
+ ) -> dict :
33
+ raise NotImplementedError
34
+
35
+ @abstractmethod
36
+ def list_workspace_storage_object (self ,
37
+ workspace_id : str ,
38
+ storage_name : Storage .__fields__ ['name' ],
39
+ storage_prefix : Object .__fields__ ['prefix' ],
40
+ ) -> dict :
41
+ raise NotImplementedError
42
+
43
+ @abstractmethod
44
+ def delete_workspace_storage_object (self ,
45
+ workspace_id : str ,
46
+ storage_name : Storage .__fields__ ['name' ],
47
+ object_name : Object .__fields__ ['name' ],
48
+ ) -> dict :
49
+ raise NotImplementedError
50
+
51
+ class IStorageProviderAdaptor (metaclass = ABCMeta ):
52
+
53
+ provider_id : str
54
+
55
+ @abstractmethod
56
+ def post_workspace_storage_object (self ,
57
+ workspace_id : str ,
58
+ storage_name : Storage .__fields__ ['name' ],
59
+ src_file : str ,
60
+ dst_file : str ,
61
+ ) -> dict :
62
+ raise NotImplementedError
63
+
64
+ @abstractmethod
65
+ def get_workspace_storage_object (self ,
66
+ workspace_id : str ,
67
+ storage_name : Storage .__fields__ ['name' ],
68
+ src_file : str ,
69
+ dst_file : str ,
70
+ ) -> bytes :
71
+ raise NotImplementedError
72
+
73
+ # Domain
74
+ class IStorageDomain (metaclass = ABCMeta ):
75
+ adaptor : IStorageAdaptor
76
+ storage_provider_adaptors : List [IStorageProviderAdaptor ]
77
+ # storage_provider_adaptors : Map[str, IStorageProviderAdaptor]
78
+ #TODO to be validated
79
+
80
+ @abstractmethod
81
+ def create_workspace_storage (self ,
82
+ workspace_id : str ,
83
+ storage_name : Storage .__fields__ ['name' ],
84
+ ) -> dict :
85
+ raise NotImplementedError
86
+
87
+ @abstractmethod
88
+ def delete_workspace_storage (self ,
89
+ workspace_id : str ,
90
+ storage_name : Storage .__fields__ ['name' ],
91
+ ) -> dict :
92
+ raise NotImplementedError
93
+
94
+ @abstractmethod
95
+ def list_workspace_storage (self ,
96
+ workspace_id : str ,
97
+ ) -> dict :
98
+ raise NotImplementedError
99
+
100
+ @abstractmethod
101
+ def list_workspace_storage_object (self ,
102
+ workspace_id : str ,
103
+ storage_name : Storage .__fields__ ['name' ],
104
+ storage_prefix : Object .__fields__ ['prefix' ],
105
+ ) -> dict :
106
+ raise NotImplementedError
107
+
108
+ @abstractmethod
109
+ def delete_workspace_storage_object (self ,
110
+ workspace_id : str ,
111
+ storage_name : Storage .__fields__ ['name' ],
112
+ object_name : Object .__fields__ ['name' ],
113
+ ) -> dict :
114
+ raise NotImplementedError
115
+
116
+ @abstractmethod
117
+ def post_workspace_storage_object (self ,
118
+ workspace_id : str ,
119
+ storage_name : Storage .__fields__ ['name' ],
120
+ src_file : str ,
121
+ dst_file : str ,
122
+ ) -> dict :
123
+ raise NotImplementedError
124
+
125
+ @abstractmethod
126
+ def get_workspace_storage_object (self ,
127
+ workspace_id : str ,
128
+ storage_name : Storage .__fields__ ['name' ],
129
+ src_file : str ,
130
+ dst_file : str ,
131
+ ) -> bytes :
132
+ raise NotImplementedError
133
+
134
+
135
+ @abstractmethod
136
+ def create_workspace_storage_credentials (self ,
137
+ workspace_id : str ,
138
+ storage_name : Storage .__fields__ ['name' ],
139
+ ) -> dict :
140
+ raise NotImplementedError
141
+
142
+ # Primary Adaptor
143
+ class IStorageInvoker (metaclass = ABCMeta ):
144
+ @abstractmethod
145
+ def create_workspace_storage (self , ** kwargs ):
146
+ raise NotImplementedError
147
+
148
+ @abstractmethod
149
+ def delete_workspace_storage (self , ** kwargs ):
150
+ raise NotImplementedError
151
+
152
+ @abstractmethod
153
+ def list_workspace_storage (self , ** kwargs ):
154
+ raise NotImplementedError
155
+
156
+ @abstractmethod
157
+ def list_workspace_storage_object (self , ** kwargs ):
158
+ raise NotImplementedError
159
+
160
+ @abstractmethod
161
+ def delete_workspace_storage_object (self , ** kwargs ):
162
+ raise NotImplementedError
163
+
164
+ @abstractmethod
165
+ def post_workspace_storage_object (self , ** kwargs ):
166
+ raise NotImplementedError
167
+
168
+ @abstractmethod
169
+ def get_workspace_storage_object (self , ** kwargs ):
170
+ raise NotImplementedError
171
+
172
+ @abstractmethod
173
+ def create_workspace_storage_credentials (self , ** kwargs ):
174
+ raise NotImplementedError
175
+
176
+ # Exceptions
177
+ class BadCredentials (NaasException ):
178
+ pass
179
+ class ClientError (NaasException ):
180
+ pass
181
+ class ConnectionError (NaasException ):
182
+ pass
183
+ class SSLError (NaasException ):
184
+ pass
185
+ class BotoCoreError (NaasException ):
186
+ pass
187
+ class StorageNotFoundError (NaasException ):
188
+ pass
189
+ class NoSuchBucket (NaasException ):
190
+ pass
191
+ class ExpiredToken (NaasException ):
192
+ pass
193
+ class FileNotFoundError (NaasException ):
194
+ pass
195
+ class BadRequest (NaasException ):
196
+ pass
197
+ class ForbiddenError (NaasException ):
198
+ pass
199
+ class APIError (NaasException ):
200
+ pass
201
+ class StorageProviderNotFound (NaasException ):
202
+ pass
203
+ class ServiceAuthenticationError (NaasException ):
204
+ pass
205
+ class ServiceStatusError (NaasException ):
206
+ pass
207
+ class ObjectAlreadyExists (NaasException ):
208
+ pass
0 commit comments