diff --git a/backend/src/__init__.py b/backend/src/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/backend/src/ceph_service.py b/backend/src/ceph_service.py new file mode 100644 index 0000000000000000000000000000000000000000..a39481b10dc7258420e049958c4e846ea9c642eb --- /dev/null +++ b/backend/src/ceph_service.py @@ -0,0 +1,29 @@ +import boto3 +import json +import os + +MINIO_ENDPOINT = os.getenv("MINIO_ENDPOINT", "http://minio:9000") +AWS_ACCESS_KEY_ID = os.getenv("MINIO_ACCESS_KEY_ID", "minioadmin") +AWS_SECRET_ACCESS_KEY = os.getenv("MINIO_SECRET_ACCESS_KEY", "minioadmin") +AWS_SESSION_TOKEN = None + + +def get_s3_client(): + resource = boto3.resource('s3', + endpoint_url=MINIO_ENDPOINT, + aws_access_key_id=AWS_ACCESS_KEY_ID, + aws_secret_access_key=AWS_SECRET_ACCESS_KEY, + aws_session_token=AWS_SESSION_TOKEN, + config=boto3.session.Config(signature_version='s3v4'), + verify=False + ) + client = resource.meta.client + return client + + +def list_buckets() -> json: + s3 = get_s3_client() + buckets = s3.list_buckets() + buckets = {key: buckets[key] for key in ["Buckets", "Owner"]} + return json.dumps(buckets, default=str) + diff --git a/backend/src/main.py b/backend/src/main.py index d5c0b27bf59d1d6f6e06a43ac75dd101537e7f7d..0544fc9a35eb8e6ef879bf6caf0381eb3a0a4edc 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -1,14 +1,7 @@ from typing import Union from fastapi import FastAPI +from routes import buckets app = FastAPI() - -@app.get("/") -def read_root(): - return {"Hello": "World"} - - -@app.get("/items/{item_id}") -def read_item(item_id: int, q: Union[str, None] = None): - return {"item_id": item_id, "q": q} \ No newline at end of file +app.include_router(buckets.router) diff --git a/backend/src/routes/__init__.py b/backend/src/routes/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/backend/src/routes/buckets.py b/backend/src/routes/buckets.py new file mode 100644 index 0000000000000000000000000000000000000000..193a973335777fdd07f06d8654c961177cdcef8a --- /dev/null +++ b/backend/src/routes/buckets.py @@ -0,0 +1,9 @@ +from fastapi import APIRouter +import ceph_service + +router = APIRouter() + + +@router.get("/buckets") +def list_buckets(): + return ceph_service.list_buckets()