Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Ceph Webapp Poc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Jacopo Gasparetto
Ceph Webapp Poc
Commits
08ef6ee1
Commit
08ef6ee1
authored
1 year ago
by
Jacopo Gasparetto
Browse files
Options
Downloads
Patches
Plain Diff
Add list_bucket
parent
6313ba50
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/src/ceph_service.py
+16
-4
16 additions, 4 deletions
backend/src/ceph_service.py
backend/src/models/buckets.py
+22
-0
22 additions, 0 deletions
backend/src/models/buckets.py
backend/src/routes/buckets.py
+14
-2
14 additions, 2 deletions
backend/src/routes/buckets.py
with
52 additions
and
6 deletions
backend/src/ceph_service.py
+
16
−
4
View file @
08ef6ee1
from
models.buckets
import
BucketInfo
,
BucketRWAccess
,
BucketInfoResponse
from
models.buckets
import
BucketInfo
,
BucketRWAccess
,
BucketInfoResponse
from
models.buckets
import
Bu
from
models.buckets
import
Bu
cketContentResponse
import
boto3
import
boto3
import
json
import
json
import
os
import
os
...
@@ -10,7 +10,7 @@ AWS_SECRET_ACCESS_KEY = os.getenv("MINIO_SECRET_ACCESS_KEY", "minioadmin")
...
@@ -10,7 +10,7 @@ AWS_SECRET_ACCESS_KEY = os.getenv("MINIO_SECRET_ACCESS_KEY", "minioadmin")
AWS_SESSION_TOKEN
=
None
AWS_SESSION_TOKEN
=
None
def
get_s3_
client
():
def
get_s3_
resource
():
return
boto3
.
resource
(
'
s3
'
,
return
boto3
.
resource
(
'
s3
'
,
endpoint_url
=
MINIO_ENDPOINT
,
endpoint_url
=
MINIO_ENDPOINT
,
aws_access_key_id
=
AWS_ACCESS_KEY_ID
,
aws_access_key_id
=
AWS_ACCESS_KEY_ID
,
...
@@ -21,9 +21,14 @@ def get_s3_client():
...
@@ -21,9 +21,14 @@ def get_s3_client():
)
)
def
get_s3_client
():
resource
=
get_s3_resource
()
return
resource
.
meta
.
client
def
list_buckets
()
->
BucketInfoResponse
:
def
list_buckets
()
->
BucketInfoResponse
:
s3
=
get_s3_
client
()
s3
=
get_s3_
resource
()
client
=
s3
.
meta
.
client
client
=
get_s3_
client
()
response
=
client
.
list_buckets
()
response
=
client
.
list_buckets
()
buckets_info
=
response
[
"
Buckets
"
]
buckets_info
=
response
[
"
Buckets
"
]
buckets
=
[
None
]
*
len
(
buckets_info
)
buckets
=
[
None
]
*
len
(
buckets_info
)
...
@@ -51,3 +56,10 @@ def list_buckets() -> BucketInfoResponse:
...
@@ -51,3 +56,10 @@ def list_buckets() -> BucketInfoResponse:
size
=
size_byte
size
=
size_byte
)
)
return
BucketInfoResponse
(
buckets
=
buckets
,
total
=
len
(
buckets
))
return
BucketInfoResponse
(
buckets
=
buckets
,
total
=
len
(
buckets
))
def
list_bucket
(
bucket_name
:
str
)
->
BucketContentResponse
:
client
=
get_s3_client
()
buckets
=
client
.
list_objects_v2
(
Bucket
=
bucket_name
)[
"
Contents
"
]
print
(
buckets
[
0
])
return
BucketContentResponse
(
buckets
=
buckets
,
total
=
len
(
buckets
))
This diff is collapsed.
Click to expand it.
backend/src/models/buckets.py
+
22
−
0
View file @
08ef6ee1
...
@@ -21,3 +21,25 @@ class BucketInfoResponse(BaseModel):
...
@@ -21,3 +21,25 @@ class BucketInfoResponse(BaseModel):
buckets
:
List
[
BucketInfo
]
buckets
:
List
[
BucketInfo
]
total
:
int
total
:
int
class
BucketOwner
(
BaseModel
):
DisplayName
:
str
ID
:
str
class
BucketObject
(
BaseModel
):
Key
:
str
LastModified
:
datetime
ETag
:
str
Size
:
int
StorageClass
:
str
Owner
:
BucketOwner
class
BucketNotfound
:
status
:
str
detail
:
str
headers
:
dict
class
BucketContentResponse
(
BaseModel
):
buckets
:
List
[
BucketObject
]
total
:
int
This diff is collapsed.
Click to expand it.
backend/src/routes/buckets.py
+
14
−
2
View file @
08ef6ee1
from
models.buckets
import
BucketInfoResponse
from
models.buckets
import
BucketInfoResponse
,
BucketContentResponse
,
BucketNotfound
from
fastapi
import
APIRouter
from
fastapi
import
APIRouter
,
HTTPException
,
Response
from
botocore.exceptions
import
ClientError
import
ceph_service
import
ceph_service
router
=
APIRouter
()
router
=
APIRouter
()
...
@@ -8,3 +9,14 @@ router = APIRouter()
...
@@ -8,3 +9,14 @@ router = APIRouter()
@router.get
(
"
/buckets
"
)
@router.get
(
"
/buckets
"
)
def
list_buckets
()
->
BucketInfoResponse
:
def
list_buckets
()
->
BucketInfoResponse
:
return
ceph_service
.
list_buckets
()
return
ceph_service
.
list_buckets
()
@router.get
(
"
/buckets/{bucket_name}
"
)
def
list_bucket
(
bucket_name
:
str
)
->
BucketContentResponse
:
try
:
return
ceph_service
.
list_bucket
(
bucket_name
=
bucket_name
)
except
ClientError
as
err
:
status
=
err
.
response
[
"
ResponseMetadata
"
][
"
HTTPStatusCode
"
]
detail
=
err
.
response
[
"
Error
"
][
"
Code
"
]
headers
=
err
.
response
[
"
ResponseMetadata
"
][
"
HTTPHeaders
"
]
raise
HTTPException
(
status_code
=
status
,
detail
=
detail
,
headers
=
headers
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment