Skip to content

Commit

Permalink
endpoint to get all files
Browse files Browse the repository at this point in the history
Signed-off-by: Pratiksha Sankhe <[email protected]>
  • Loading branch information
psankhe28 committed Sep 11, 2024
1 parent 4f7c103 commit 11827ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cloud_storage_handler/api/elixircloud/csh/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from http import HTTPStatus

from flask import jsonify
from minio.error import S3Error

from cloud_storage_handler.clients.minio import get_minio_client

logger = logging.getLogger(__name__)

Expand All @@ -13,3 +16,15 @@ def home():
return jsonify(
{"message": "Welcome to the Cloud Storage Handler server!"}
), HTTPStatus.OK


def list_files():
"""Endpoint to list all files in the MinIO bucket."""
try:
minio_client = get_minio_client()
objects = minio_client.list_objects("files")
files = [obj.object_name for obj in objects]
return jsonify({"files": files}), 200

except S3Error as err:
return jsonify({"error": str(err)}), 500
18 changes: 18 additions & 0 deletions cloud_storage_handler/api/specs/specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ paths:
description: The request is malformed.
'500':
description: An unexpected error occurred.
/list_files:
get:
description: |
Returns a list of all files in the minio storage
operationId: list_files
responses:
'200':
description: The list of files has been retrieved successfully.
content:
application/json:
schema:
type: array
items:
type: string
'400':
description: The request is malformed.
'500':
description: An unexpected error occurred.
...

0 comments on commit 11827ee

Please sign in to comment.