-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject_storage.py
368 lines (318 loc) · 10.9 KB
/
object_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
from typing import Optional, Union
from fastapi import APIRouter, HTTPException, Request, UploadFile
from fastapi.responses import Response
from ..models.object_storage import (
CollectionListResponse,
CollectionName,
DatasetCreateResponse,
DatasetListResponse,
DatasetName,
SemanticMappingListResponse,
SemanticMappingModel,
)
router = APIRouter(
prefix="/data",
responses={
501: {"description": "Not implemented."},
},
)
@router.get(
"",
operation_id="listCollections",
summary="List all collections",
tags=["DataSource", "DataSink"],
response_model=CollectionListResponse,
responses={
204: {"description": "No collections found."},
},
)
async def list_collections(
limit: int = 100, offset: int = 0
) -> Union[CollectionListResponse, Response]:
"""List all collections."""
raise HTTPException(status_code=501, detail="Not implemented.")
@router.get(
"/{collection_name}",
operation_id="listDatasets",
summary="List all datasets in a collection",
tags=["DataSource"],
response_model=DatasetListResponse,
responses={
204: {"description": "No datasets found."},
404: {"description": "Container not found."},
},
)
async def list_datasets(
collection_name: CollectionName, limit: int = 100, offset: int = 0
) -> Union[DatasetListResponse, Response]:
"""List all datasets."""
raise HTTPException(status_code=501, detail="Not implemented.")
CREATE_COLLECTION_DESCRIPTION = """
To add custom metadata, add keys to the header of the form:
- X-Object-Meta-name: value
Where 'name' is the name of the metadata key and 'value' is the
corresponding value.
Note: This operation is in compliance with the OpenStack Swift object
storage API:
https://docs.openstack.org/api-ref/object-store/index.html#create-container
"""
@router.put(
"/{collection_name}",
name="Create or update Collection",
operation_id="createOrUpdateCollection",
summary="Create or update a collection",
tags=["DataSink"],
status_code=201,
response_class=Response,
responses={
201: {"description": "Collection has been created."},
202: {"description": "Collection has been updated."},
400: {"description": "Bad request."},
507: {"description": "Insufficient storage."},
},
description="Create or update a collection.\n" + CREATE_COLLECTION_DESCRIPTION,
)
@router.put(
"/",
name="Create Collection",
operation_id="createCollection",
summary="Create a collection",
tags=["DataSink"],
status_code=201,
response_class=Response,
responses={
201: {"description": "Collection has been created."},
400: {"description": "Bad request."},
507: {"description": "Insufficient storage."},
},
description="Create a collection.\n" + CREATE_COLLECTION_DESCRIPTION,
)
async def create_collection(
request: Request, collection_name: CollectionName = None
) -> Response:
"""Create a new or replace an existing collection."""
raise HTTPException(status_code=501, detail="Not implemented.")
@router.head(
"/{collection_name}",
name="Get Collection Metadata",
operation_id="getCollectionMetadata",
summary="Get a collection's metadata",
tags=["DataSource"],
response_class=Response,
status_code=204,
responses={
204: {"description": "Normal response."},
404: {"description": "Not found."},
},
)
async def get_collection_metadata(collection_name: CollectionName) -> Response:
"""Get the metadata for a collection."""
raise HTTPException(status_code=501, detail="Not implemented.")
@router.delete(
"/{collection_name}",
name="Delete Collection",
operation_id="deleteCollection",
summary="Delete an empty collection",
tags=["DataSink"],
response_class=Response,
status_code=204,
responses={
204: {"description": "Collection has been deleted."},
404: {"description": "Collection not found."},
409: {"description": "Collection is not empty."},
422: {"description": "Validation error."},
},
)
async def delete_collection(collection_name: CollectionName) -> Response:
"""Delete an empty collection."""
raise HTTPException(status_code=501, detail="Not implemented.")
CREATE_DATASET_DESCRIPTION = """
To add custom metadata, add keys to the header of the form:
- X-Object-Meta-name: value
Where 'name' is the name of the metadata key and 'value' is the
corresponding value.
Note: This operation is in compliance with the OpenStack Swift object
storage API:
https://docs.openstack.org/api-ref/object-store/index.html#create-or-replace-object
"""
@router.put(
"/{collection_name}/{dataset_name}",
name="Create or Replace Dataset",
operation_id="createOrReplaceDataset",
summary="Create or replace a dataset",
tags=["DataSink"],
response_model=DatasetCreateResponse,
status_code=201,
responses={
507: {"description": "Insufficient storage."},
},
description="Create or replace a dataset.\n" + CREATE_DATASET_DESCRIPTION,
)
@router.put(
"/{collection_name}/",
name="Create a dataset",
operation_id="createDataset",
summary="Create a dataset",
tags=["DataSink"],
response_model=DatasetCreateResponse,
status_code=201,
responses={
507: {"description": "Insufficient storage."},
},
description="Create a dataset.\n" + CREATE_DATASET_DESCRIPTION,
)
async def create_dataset(
request: Request,
file: UploadFile,
collection_name: CollectionName,
dataset_name: Optional[DatasetName] = None,
) -> Union[DatasetCreateResponse, Response]:
"""Create a new or replace an existing dataset."""
raise HTTPException(status_code=501, detail="Not implemented.")
@router.post(
"/{collection_name}/",
name="Create Dataset Metadata",
operation_id="createDatasetMetadata",
summary="Create a dataset's metadata",
tags=["DataSink"],
status_code=202,
response_class=Response,
responses={
202: {"description": "Dataset metadata has been created."},
},
)
@router.post(
"/{collection_name}/{dataset_name}",
name="Create or Replace Dataset Metadata",
operation_id="createOrReplaceDatasetMetadata",
summary="Create or replace a dataset's metadata",
tags=["DataSink"],
status_code=202,
response_class=Response,
responses={
202: {"description": "Dataset metadata has been created/updated."},
},
)
async def create_or_replace_dataset_metadata(
collection_name: CollectionName,
dataset_name: Optional[DatasetName] = None,
) -> Response:
"""Create or replace dataset metadata.
Note: This operation is in compliance with the OpenStack Swift object
storage API:
https://docs.openstack.org/api-ref/object-store/index.html#create-or-update-object-metadata
"""
raise HTTPException(status_code=501, detail="Not implemented.")
@router.head(
"/{collection_name}/{dataset_name}",
name="Get Dataset Metadata",
operation_id="getDatasetMetadata",
summary="Get a dataset's metadata",
tags=["DataSource"],
status_code=200,
response_class=Response,
responses={
404: {"description": "Not found."},
},
)
async def get_dataset_metadata(
collection_name: CollectionName, dataset_name: DatasetName
) -> Response:
"""Get dataset metadata.
Returns the dataset metadata in the response header in the form of:
- X-Object-Meta-name: value
Where 'name' is the name of the metadata key and 'value' is the
corresponding value.
Example response header for a plain-text file:
- Content-Type: text/plain;charset=UTF-8
- Content-Length: 1234
- X-Object-Meta-my-key: some-value
Note: This operation is in compliance with the OpenStack Swift object
storage API:
https://docs.openstack.org/api-ref/object-store/index.html#show-object-metadata
"""
# return Response(content=None, headers={"X-Object-Meta-my-key": "some-value"})
raise HTTPException(status_code=501, detail="Not implemented.")
@router.get(
"/{collection_name}/{dataset_name}",
name="Get Dataset",
operation_id="getDataset",
summary="Get a dataset",
tags=["DataSource"],
response_class=Response,
responses={
404: {"description": "Not found."},
},
)
async def get_dataset(
collection_name: CollectionName, dataset_name: DatasetName
) -> Response:
"""Get a dataset.
Returns the object as part of the request body and metadata as part of the
response headers.
In addition to the standard response header keys (Content-Type and
Content-Length), the header may also contain metadata key-value pairs in the
form of:
- X-Object-Meta-name: value
Where 'name' is the name of the metadata key and 'value' is the
corresponding value.
Example response header for a plain-text file:
- Content-Type: text/plain;charset=UTF-8
- Content-Length: 1234
- X-Object-Meta-my-key: some-value
Note: This operation is in compliance with the OpenStack Swift object
storage API:
https://docs.openstack.org/api-ref/object-store/index.html#get-object-content-and-metadata
"""
# return Response(content=data, headers={"X-Object-Meta-my-key": "some-value"})
raise HTTPException(status_code=501, detail="Not implemented.")
@router.delete(
"/{collection_name}/{dataset_name}",
name="Delete Dataset",
operation_id="deleteDataset",
summary="Delete a dataset",
tags=["DataSink"],
status_code=204,
responses={
404: {"description": "Not found."},
},
)
async def delete_dataset(
collection_name: CollectionName, dataset_name: DatasetName
) -> Response:
"""Delete a dataset with the given dataset id.
Note: This operation is in compliance with the OpenStack Swift object
storage API:
https://docs.openstack.org/api-ref/object-store/index.html#delete-object
"""
raise HTTPException(status_code=501, detail="Not implemented.")
@router.get(
"/semanticMappings",
operation_id="listSemanticMappings",
summary="List all semantic mappings",
tags=["DataSource", "DataSink"],
response_model=SemanticMappingListResponse,
responses={
204: {"description": "No mappings found."},
},
)
async def list_semantic_mappings(
limit: int = 100, offset: int = 0
) -> Union[SemanticMappingListResponse, Response]:
"""List all semantic mappings."""
raise HTTPException(status_code=501, detail="Not implemented.")
@router.get(
"/semanticMappings/{semantic_mapping_id}",
operation_id="getSemanticMapping",
summary="Get a specific semantic mapping",
tags=["DataSource", "DataSink"],
response_model=SemanticMappingModel,
responses={
404: {"description": "Not found."},
},
)
async def get_semantic_mapping(
semantic_mapping_id,
) -> Union[SemanticMappingModel, Response]:
"""Get a semantic mapping."""
raise HTTPException(status_code=501, detail="Not implemented.")