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
ff029ea3
Commit
ff029ea3
authored
1 year ago
by
Jacopo Gasparetto
Browse files
Options
Downloads
Patches
Plain Diff
Add BucketResponse model and change return values
parent
6884c2b9
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
+21
-5
21 additions, 5 deletions
backend/src/ceph_service.py
backend/src/models/buckets.py
+20
-0
20 additions, 0 deletions
backend/src/models/buckets.py
backend/src/routes/buckets.py
+2
-1
2 additions, 1 deletion
backend/src/routes/buckets.py
with
43 additions
and
6 deletions
backend/src/ceph_service.py
+
21
−
5
View file @
ff029ea3
from
models.buckets
import
Bucket
,
BucketRWAccess
,
BucketResponse
import
boto3
import
json
import
os
...
...
@@ -21,9 +22,24 @@ def get_s3_client():
return
client
def
list_buckets
()
->
json
:
def
list_buckets
()
->
BucketResponse
:
s3
=
get_s3_client
()
buckets
=
s3
.
list_buckets
()
buckets
=
{
key
:
buckets
[
key
]
for
key
in
[
"
Buckets
"
,
"
Owner
"
]}
return
json
.
dumps
(
buckets
,
default
=
str
)
response
=
s3
.
list_buckets
()
buckets_info
=
response
[
"
Buckets
"
]
buckets
=
[
None
]
*
len
(
buckets_info
)
for
i
,
bucket_info
in
enumerate
(
buckets_info
):
bucket_name
=
bucket_info
[
"
Name
"
]
creation_date
=
bucket_info
[
"
CreationDate
"
]
bucket_acl
=
s3
.
get_bucket_acl
(
Bucket
=
bucket_name
)
grant
=
bucket_acl
[
"
Grants
"
][
0
]
# TODO: Here we can have multiple grants
permission
=
grant
[
"
Permission
"
]
read
=
permission
in
(
"
READ
"
,
"
FULL_CONTROL
"
)
write
=
permission
in
(
"
WRITE
"
,
"
FULL_CONTROL
"
)
rw_access
=
BucketRWAccess
(
read
=
read
,
write
=
write
)
buckets
[
i
]
=
Bucket
(
name
=
bucket_name
,
creation_date
=
creation_date
,
details
=
{},
rw_access
=
rw_access
)
return
BucketResponse
(
buckets
=
buckets
,
total
=
len
(
buckets
))
This diff is collapsed.
Click to expand it.
backend/src/models/buckets.py
0 → 100644
+
20
−
0
View file @
ff029ea3
from
pydantic
import
BaseModel
from
datetime
import
datetime
from
typing
import
List
class
BucketRWAccess
(
BaseModel
):
read
:
bool
write
:
bool
class
Bucket
(
BaseModel
):
name
:
str
creation_date
:
datetime
details
:
dict
rw_access
:
BucketRWAccess
class
BucketResponse
(
BaseModel
):
buckets
:
List
[
Bucket
]
total
:
int
This diff is collapsed.
Click to expand it.
backend/src/routes/buckets.py
+
2
−
1
View file @
ff029ea3
from
models.buckets
import
BucketResponse
from
fastapi
import
APIRouter
import
ceph_service
...
...
@@ -5,5 +6,5 @@ router = APIRouter()
@router.get
(
"
/buckets
"
)
def
list_buckets
():
def
list_buckets
()
->
BucketResponse
:
return
ceph_service
.
list_buckets
()
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