-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
storages.py
784 lines (621 loc) · 26 KB
/
storages.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
"""
Storage API
"""
from typing import (
Optional,
Iterator,
Iterable,
List,
Dict,
AsyncIterator,
TYPE_CHECKING,
Any,
)
from urllib.parse import urlsplit
from contextlib import asynccontextmanager
from itertools import chain
import asyncio
import heapq
import zlib
import json
import os
from datetime import datetime
from zipfile import ZipInfo
from fastapi import Depends, HTTPException
from stream_zip import stream_zip, NO_COMPRESSION_64
from remotezip import RemoteZip
import aiobotocore.session
import boto3
from mypy_boto3_s3.client import S3Client
from mypy_boto3_s3.type_defs import CompletedPartTypeDef
from types_aiobotocore_s3 import S3Client as AIOS3Client
from .models import (
CrawlFile,
CrawlFileOut,
Organization,
StorageRef,
S3Storage,
S3StorageIn,
OrgStorageRefs,
)
from .utils import is_bool, slug_from_name
if TYPE_CHECKING:
from .orgs import OrgOps
from .crawlmanager import CrawlManager
else:
OrgOps = CrawlManager = object
CHUNK_SIZE = 1024 * 256
# ============================================================================
# pylint: disable=broad-except,raise-missing-from
class StorageOps:
"""All storage handling, download/upload operations"""
default_storages: Dict[str, S3Storage] = {}
default_primary: Optional[StorageRef] = None
default_replicas: List[StorageRef] = []
org_ops: OrgOps
crawl_manager: CrawlManager
def __init__(self, org_ops, crawl_manager) -> None:
self.org_ops = org_ops
self.crawl_manager = crawl_manager
self.is_local_minio = is_bool(os.environ.get("IS_LOCAL_MINIO"))
with open(os.environ["STORAGES_JSON"], encoding="utf-8") as fh:
storage_list = json.loads(fh.read())
for storage in storage_list:
name = storage.get("name")
name = slug_from_name(name)
type_ = storage.get("type", "s3")
if type_ == "s3":
self.default_storages[name] = self._create_s3_storage(storage)
else:
# expand when additional storage options are supported
raise TypeError("Only s3 storage supported for now")
if storage.get("is_default_primary"):
if self.default_primary:
raise TypeError("Only one default primary storage can be specified")
self.default_primary = StorageRef(name=name)
if storage.get("is_default_replica"):
self.default_replicas.append(StorageRef(name=name))
if not self.default_primary:
num_storages = len(self.default_storages)
if num_storages == 1:
self.default_primary = StorageRef(
name=list(self.default_storages.keys())[0]
)
elif num_storages == 0:
raise TypeError("No storages specified in 'storages' key")
else:
raise TypeError(
"Multiple storages found -- set 'is_default_primary: True'"
"to indicate which storage should be considered default primary"
)
self.org_ops.set_default_primary_storage(self.default_primary)
def _create_s3_storage(self, storage: dict[str, str]) -> S3Storage:
"""create S3Storage object"""
endpoint_url = storage["endpoint_url"]
bucket_name = storage.get("bucket_name")
endpoint_no_bucket_url = endpoint_url
if bucket_name:
endpoint_url += bucket_name + "/"
if self.is_local_minio:
access_endpoint_url = "/data/"
use_access_for_presign = False
else:
access_endpoint_url = storage.get("access_endpoint_url") or endpoint_url
use_access_for_presign = True
return S3Storage(
access_key=storage["access_key"],
secret_key=storage["secret_key"],
region=storage.get("region", ""),
endpoint_url=endpoint_url,
endpoint_no_bucket_url=endpoint_no_bucket_url,
access_endpoint_url=access_endpoint_url,
use_access_for_presign=use_access_for_presign,
)
async def add_custom_storage(
self, storagein: S3StorageIn, org: Organization
) -> dict:
"""Add new custom storage"""
name = "!" + slug_from_name(storagein.name)
if name in org.customStorages:
raise HTTPException(status_code=400, detail="storage_already_exists")
bucket_name = storagein.bucket
endpoint_url = storagein.endpoint_url
endpoint_no_bucket_url = endpoint_url
if bucket_name:
endpoint_url += bucket_name + "/"
storage = S3Storage(
access_key=storagein.access_key,
secret_key=storagein.secret_key,
region=storagein.region,
endpoint_url=endpoint_url,
endpoint_no_bucket_url=endpoint_no_bucket_url,
access_endpoint_url=storagein.access_endpoint_url or storagein.endpoint_url,
use_access_for_presign=True,
)
try:
await self.verify_storage_upload(storage, ".btrix-upload-verify")
except:
raise HTTPException(
status_code=400,
detail="Could not verify custom storage. Check credentials are valid?",
)
org.customStorages[name] = storage
string_data = {
"TYPE": "s3",
"STORE_ENDPOINT_URL": storage.endpoint_url,
"STORE_ENDPOINT_NO_BUCKET_URL": storage.endpoint_no_bucket_url,
"STORE_ACCESS_KEY": storage.access_key,
"STORE_SECRET_KEY": storage.secret_key,
}
await self.crawl_manager.add_org_storage(
StorageRef(name=name, custom=True), string_data, str(org.id)
)
await self.org_ops.update_custom_storages(org)
return {"added": True, "name": name}
async def remove_custom_storage(
self, name: str, org: Organization
) -> dict[str, bool]:
"""remove custom storage"""
if org.storage.custom and org.storage.name == name:
raise HTTPException(status_code=400, detail="storage_in_use")
for replica in org.storageReplicas:
if replica.custom and replica.name == name:
raise HTTPException(status_code=400, detail="storage_in_use")
await self.crawl_manager.remove_org_storage(
StorageRef(name=name, custom=True), str(org.id)
)
try:
del org.customStorages[name]
except:
raise HTTPException(status_code=400, detail="no_such_storage")
await self.org_ops.update_custom_storages(org)
return {"deleted": True}
async def update_storage_refs(
self,
storage_refs: OrgStorageRefs,
org: Organization,
) -> dict[str, bool]:
"""update storage for org"""
try:
self.get_org_storage_by_ref(org, storage_refs.storage)
for replica in storage_refs.storageReplicas:
self.get_org_storage_by_ref(org, replica)
except:
raise HTTPException(status_code=400, detail="invalid_storage_ref")
org.storage = storage_refs.storage
org.storageReplicas = storage_refs.storageReplicas
await self.org_ops.update_storage_refs(org)
return {"updated": True}
def get_available_storages(self, org: Organization) -> List[StorageRef]:
"""return a list of available default + custom storages"""
refs: List[StorageRef] = []
for name in self.default_storages:
refs.append(StorageRef(name=name, custom=False))
for name in org.customStorages:
refs.append(StorageRef(name=name, custom=True))
return refs
@asynccontextmanager
async def get_s3_client(
self, storage: S3Storage, use_access=False
) -> AsyncIterator[tuple[AIOS3Client, str, str]]:
"""context manager for s3 client"""
endpoint_url = (
storage.endpoint_url if not use_access else storage.access_endpoint_url
)
if not endpoint_url.endswith("/"):
endpoint_url += "/"
parts = urlsplit(endpoint_url)
bucket, key = parts.path[1:].split("/", 1)
endpoint_url = parts.scheme + "://" + parts.netloc
session = aiobotocore.session.get_session()
async with session.create_client(
"s3",
region_name=storage.region,
endpoint_url=endpoint_url,
aws_access_key_id=storage.access_key,
aws_secret_access_key=storage.secret_key,
) as client:
yield client, bucket, key
@asynccontextmanager
async def get_sync_client(
self, org: Organization
) -> AsyncIterator[tuple[S3Client, str, str]]:
"""context manager for s3 client"""
storage = self.get_org_primary_storage(org)
endpoint_url = storage.endpoint_url
if not endpoint_url.endswith("/"):
endpoint_url += "/"
parts = urlsplit(endpoint_url)
bucket, key = parts.path[1:].split("/", 1)
endpoint_url = parts.scheme + "://" + parts.netloc
try:
client = boto3.client(
"s3",
region_name=storage.region,
endpoint_url=endpoint_url,
aws_access_key_id=storage.access_key,
aws_secret_access_key=storage.secret_key,
)
yield client, bucket, key
finally:
client.close()
async def verify_storage_upload(self, storage: S3Storage, filename: str) -> None:
"""Test credentials and storage endpoint by uploading an empty test file"""
async with self.get_s3_client(storage) as (client, bucket, key):
key += filename
data = b""
resp = await client.put_object(Bucket=bucket, Key=key, Body=data)
assert resp["ResponseMetadata"]["HTTPStatusCode"] == 200
def get_org_relative_path(
self, org: Organization, ref: StorageRef, file_path: str
) -> str:
"""get relative path for file"""
storage = self.get_org_storage_by_ref(org, ref)
if file_path.startswith(storage.endpoint_url):
return file_path[len(storage.endpoint_url) :]
return file_path
def get_org_primary_storage(self, org: Organization) -> S3Storage:
"""get org primary storage, from either defaults or org custom storage"""
return self.get_org_storage_by_ref(org, org.storage)
def get_org_replicas_storage_refs(self, org: Organization) -> List[StorageRef]:
"""get org replicas storages, defaulting to default replicas if none found"""
if org.storageReplicas:
return org.storageReplicas
return self.default_replicas
def get_org_storage_by_ref(self, org: Organization, ref: StorageRef) -> S3Storage:
"""Get a storage object from StorageRef"""
if not ref.custom:
s3storage = self.default_storages.get(ref.name)
elif not org.storage:
raise KeyError(
f"Referencing custom org storage: {ref.name}, but no custom storage found!"
)
else:
s3storage = org.customStorages.get(ref.name)
if not s3storage:
raise KeyError(
f"No {'custom' if ref.custom else 'default'} storage with name: {ref.name}"
)
return s3storage
async def do_upload_single(
self,
org: Organization,
filename: str,
data,
) -> None:
"""do upload to specified key"""
s3storage = self.get_org_primary_storage(org)
async with self.get_s3_client(s3storage) as (client, bucket, key):
key += filename
await client.put_object(Bucket=bucket, Key=key, Body=data)
# pylint: disable=too-many-arguments,too-many-locals
async def do_upload_multipart(
self,
org: Organization,
filename: str,
file_: AsyncIterator,
min_size: int,
) -> bool:
"""do upload to specified key using multipart chunking"""
s3storage = self.get_org_primary_storage(org)
async def get_next_chunk(file_, min_size) -> bytes:
total = 0
bufs = []
async for chunk in file_:
bufs.append(chunk)
total += len(chunk)
if total >= min_size:
break
if len(bufs) == 1:
return bufs[0]
return b"".join(bufs)
async with self.get_s3_client(s3storage) as (client, bucket, key):
key += filename
mup_resp = await client.create_multipart_upload(
ACL="bucket-owner-full-control", Bucket=bucket, Key=key
)
upload_id = mup_resp["UploadId"]
parts = []
part_number = 1
try:
while True:
chunk = await get_next_chunk(file_, min_size)
resp = await client.upload_part(
Bucket=bucket,
Body=chunk,
UploadId=upload_id,
PartNumber=part_number,
Key=key,
)
print(
f"part added: {part_number} {len(chunk)} {upload_id}",
flush=True,
)
part: CompletedPartTypeDef = {
"PartNumber": part_number,
"ETag": resp["ETag"],
}
parts.append(part)
part_number += 1
if len(chunk) < min_size:
break
await client.complete_multipart_upload(
Bucket=bucket,
Key=key,
UploadId=upload_id,
MultipartUpload={"Parts": parts},
)
print(f"Multipart upload succeeded: {upload_id}")
return True
# pylint: disable=broad-exception-caught
except Exception as exc:
await client.abort_multipart_upload(
Bucket=bucket, Key=key, UploadId=upload_id
)
print(exc)
print(f"Multipart upload failed: {upload_id}")
return False
async def get_presigned_url(
self, org: Organization, crawlfile: CrawlFile, duration=3600
) -> str:
"""generate pre-signed url for crawl file"""
s3storage = self.get_org_storage_by_ref(org, crawlfile.storage)
async with self.get_s3_client(s3storage, s3storage.use_access_for_presign) as (
client,
bucket,
key,
):
key += crawlfile.filename
presigned_url = await client.generate_presigned_url(
"get_object", Params={"Bucket": bucket, "Key": key}, ExpiresIn=duration
)
if (
not s3storage.use_access_for_presign
and s3storage.access_endpoint_url
and s3storage.access_endpoint_url != s3storage.endpoint_url
):
presigned_url = presigned_url.replace(
s3storage.endpoint_url, s3storage.access_endpoint_url
)
return presigned_url
async def delete_crawl_file_object(
self, org: Organization, crawlfile: CrawlFile
) -> bool:
"""delete crawl file from storage."""
return await self._delete_file(org, crawlfile.filename, crawlfile.storage)
async def _delete_file(
self, org: Organization, filename: str, storage: StorageRef
) -> bool:
"""delete specified file from storage"""
status_code = None
s3storage = self.get_org_storage_by_ref(org, storage)
async with self.get_s3_client(s3storage, s3storage.use_access_for_presign) as (
client,
bucket,
key,
):
key += filename
response = await client.delete_object(Bucket=bucket, Key=key)
status_code = response["ResponseMetadata"]["HTTPStatusCode"]
return status_code == 204
async def sync_stream_wacz_pages(
self, wacz_files: List[CrawlFileOut]
) -> Iterator[Dict[Any, Any]]:
"""Return stream of pages specified WACZ"""
loop = asyncio.get_event_loop()
resp = await loop.run_in_executor(None, self._sync_get_pages, wacz_files)
return resp
async def sync_stream_wacz_logs(
self,
wacz_files: List[CrawlFileOut],
log_levels: List[str],
contexts: List[str],
) -> Iterator[bytes]:
"""Return filtered stream of logs from specified WACZs sorted by timestamp"""
loop = asyncio.get_event_loop()
resp = await loop.run_in_executor(
None,
self._sync_get_logs,
wacz_files,
log_levels,
contexts,
)
return resp
def _sync_get_logs(
self,
wacz_files: List[CrawlFileOut],
log_levels: List[str],
contexts: List[str],
) -> Iterator[bytes]:
"""Generate filtered stream of logs from specified WACZs sorted by timestamp"""
# pylint: disable=too-many-function-args
def stream_log_lines(
log_zipinfo: ZipInfo, wacz_url: str, wacz_filename: str
) -> Iterator[dict]:
"""Pass lines as json objects"""
filename = log_zipinfo.filename
print(f"Fetching log {filename} from {wacz_filename}", flush=True)
line_iter: Iterator[bytes] = self._sync_get_filestream(wacz_url, filename)
for line in line_iter:
yield _parse_json(line.decode("utf-8", errors="ignore"))
def stream_json_lines(
iterator: Iterable[dict], log_levels: List[str], contexts: List[str]
) -> Iterator[bytes]:
"""Yield parsed JSON dicts as JSON-lines bytes after filtering as necessary"""
for line_dict in iterator:
if log_levels and line_dict["logLevel"] not in log_levels:
continue
if contexts and line_dict["context"] not in contexts:
continue
json_str = json.dumps(line_dict, ensure_ascii=False) + "\n"
yield json_str.encode("utf-8")
def organize_based_on_instance_number(
wacz_files: List[CrawlFileOut],
) -> List[List[CrawlFileOut]]:
"""Place wacz_files into their own list based on instance number"""
wacz_files.sort(key=lambda file: file.name)
waczs_groups: Dict[str, List[CrawlFileOut]] = {}
for file in wacz_files:
instance_number = file.name[
file.name.rfind("-") + 1 : file.name.rfind(".")
]
if instance_number in waczs_groups:
waczs_groups[instance_number].append(file)
else:
waczs_groups[instance_number] = [file]
return list(waczs_groups.values())
log_generators: List[Iterator[dict]] = []
waczs_groups = organize_based_on_instance_number(wacz_files)
for instance_list in waczs_groups:
wacz_log_streams: List[Iterator[dict]] = []
for wacz_file in instance_list:
wacz_url = wacz_file.path
if wacz_url.startswith("/data"):
wacz_url = f"http://browsertrix-cloud-frontend.default{wacz_url}"
with RemoteZip(wacz_url) as remote_zip:
log_files: List[ZipInfo] = [
f
for f in remote_zip.infolist()
if f.filename.startswith("logs/") and not f.is_dir()
]
log_files.sort(key=lambda log_zipinfo: log_zipinfo.filename)
for log_zipinfo in log_files:
wacz_log_streams.append(
stream_log_lines(log_zipinfo, wacz_url, wacz_file.name)
)
log_generators.append(chain(*wacz_log_streams))
heap_iter = heapq.merge(*log_generators, key=lambda entry: entry["timestamp"])
return stream_json_lines(heap_iter, log_levels, contexts)
def _sync_get_pages(
self,
wacz_files: List[CrawlFileOut],
) -> Iterator[Dict[Any, Any]]:
"""Generate stream of page dicts from specified WACZs"""
# pylint: disable=too-many-function-args
def stream_page_lines(
pagefile_zipinfo: ZipInfo, wacz_url: str, wacz_filename: str
) -> Iterator[Dict[Any, Any]]:
"""Pass lines as json objects"""
filename = pagefile_zipinfo.filename
print(
f"Fetching JSON lines from {filename} in {wacz_filename}",
flush=True,
)
line_iter: Iterator[bytes] = self._sync_get_filestream(wacz_url, filename)
for line in line_iter:
yield _parse_json(line.decode("utf-8", errors="ignore"))
page_generators: List[Iterator[Dict[Any, Any]]] = []
for wacz_file in wacz_files:
wacz_url = wacz_file.path
if wacz_url.startswith("/data"):
wacz_url = f"http://browsertrix-cloud-frontend.default{wacz_url}"
with RemoteZip(wacz_url) as remote_zip:
page_files: List[ZipInfo] = [
f
for f in remote_zip.infolist()
if f.filename.startswith("pages/")
and f.filename.endswith(".jsonl")
and not f.is_dir()
]
for pagefile_zipinfo in page_files:
page_generators.append(
stream_page_lines(pagefile_zipinfo, wacz_url, wacz_file.name)
)
return chain.from_iterable(page_generators)
def _sync_get_filestream(self, wacz_url: str, filename: str) -> Iterator[bytes]:
"""Return iterator of lines in remote file as bytes"""
with RemoteZip(wacz_url) as remote_zip:
with remote_zip.open(filename) as file_stream:
yield from file_stream
def _sync_dl(
self, all_files: List[CrawlFileOut], client: S3Client, bucket: str, key: str
) -> Iterator[bytes]:
"""generate streaming zip as sync"""
for file_ in all_files:
file_.path = file_.name
datapackage = {
"profile": "multi-wacz-package",
"resources": [file_.dict() for file_ in all_files],
}
datapackage_bytes = json.dumps(datapackage).encode("utf-8")
def get_file(name) -> Iterator[bytes]:
response = client.get_object(Bucket=bucket, Key=key + name)
return response["Body"].iter_chunks(chunk_size=CHUNK_SIZE)
def member_files():
modified_at = datetime(year=1980, month=1, day=1)
perms = 0o664
for file_ in all_files:
yield (
file_.name,
modified_at,
perms,
NO_COMPRESSION_64(file_.size, file_.crc32),
get_file(file_.name),
)
yield (
"datapackage.json",
modified_at,
perms,
NO_COMPRESSION_64(
len(datapackage_bytes), zlib.crc32(datapackage_bytes)
),
(datapackage_bytes,),
)
return stream_zip(member_files(), chunk_size=CHUNK_SIZE)
async def download_streaming_wacz(
self, org: Organization, files: List[CrawlFileOut]
) -> Iterator[bytes]:
"""return an iter for downloading a stream nested wacz file
from list of files"""
async with self.get_sync_client(org) as (client, bucket, key):
loop = asyncio.get_event_loop()
resp = await loop.run_in_executor(
None, self._sync_dl, files, client, bucket, key
)
return resp
# ============================================================================
def _parse_json(line) -> dict:
"""Parse JSON str into dict."""
parsed_json: Optional[dict] = None
try:
parsed_json = json.loads(line)
except json.JSONDecodeError as err:
print(f"Error decoding json-l line: {line}. Error: {err}", flush=True)
return parsed_json or {}
# ============================================================================
def init_storages_api(org_ops, crawl_manager):
"""API for updating storage for an org"""
storage_ops = StorageOps(org_ops, crawl_manager)
if not org_ops.router:
return storage_ops
router = org_ops.router
org_owner_dep = org_ops.org_owner_dep
@router.get("/storage", tags=["organizations"], response_model=OrgStorageRefs)
def get_storage_refs(
org: Organization = Depends(org_owner_dep),
):
"""get storage refs for an org"""
return OrgStorageRefs(storage=org.storage, storageReplicas=org.storageReplicas)
@router.get("/allStorages", tags=["organizations"])
def get_available_storages(org: Organization = Depends(org_owner_dep)):
return storage_ops.get_available_storages(org)
# pylint: disable=unreachable, fixme
# todo: enable when ready to support custom storage
return storage_ops
@router.post("/customStorage", tags=["organizations"])
async def add_custom_storage(
storage: S3StorageIn, org: Organization = Depends(org_owner_dep)
):
return await storage_ops.add_custom_storage(storage, org)
@router.delete("/customStorage/{name}", tags=["organizations"])
async def remove_custom_storage(
name: str, org: Organization = Depends(org_owner_dep)
):
return await storage_ops.remove_custom_storage(name, org)
@router.post("/storage", tags=["organizations"])
async def update_storage_refs(
storage: OrgStorageRefs,
org: Organization = Depends(org_owner_dep),
):
return await storage_ops.update_storage_refs(storage, org)
return storage_ops