Skip to content

Commit

Permalink
Make all-storages response valid JSON with response model
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Oct 17, 2024
1 parent c06e193 commit f9b63d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,13 @@ class OrgStorageReplicaRefs(BaseModel):
storageReplicas: List[StorageRef]


# ============================================================================
class OrgAllStorages(BaseModel):
"""Response model for listing all available storages"""

allStorages: List[StorageRef]


# ============================================================================
class S3StorageIn(BaseModel):
"""Custom S3 Storage input model"""
Expand Down
7 changes: 4 additions & 3 deletions backend/btrixcloud/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
OrgStorageRefs,
OrgStorageRef,
OrgStorageReplicaRefs,
OrgAllStorages,
DeletedResponse,
UpdatedResponse,
UpdatedResponseId,
Expand Down Expand Up @@ -387,14 +388,14 @@ async def _run_post_storage_replica_update_tasks(
org, replica_storage, remove=True
)

def get_available_storages(self, org: Organization) -> List[StorageRef]:
def get_available_storages(self, org: Organization) -> Dict[str, 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
return {"allStorages": refs}

@asynccontextmanager
async def get_s3_client(
Expand Down Expand Up @@ -893,7 +894,7 @@ def get_storage_refs(
@router.get(
"/all-storages",
tags=["organizations", "storage"],
response_model=List[StorageRef],
response_model=OrgAllStorages,
)
def get_available_storages(org: Organization = Depends(org_owner_dep)):
return storage_ops.get_available_storages(org)
Expand Down

0 comments on commit f9b63d2

Please sign in to comment.