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
de5b477d
Commit
de5b477d
authored
1 year ago
by
Jacopo Gasparetto
Browse files
Options
Downloads
Patches
Plain Diff
Add objects count and total size to GET buckets
parent
ff029ea3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/src/ceph_service.py
+20
-13
20 additions, 13 deletions
backend/src/ceph_service.py
backend/src/models/buckets.py
+2
-1
2 additions, 1 deletion
backend/src/models/buckets.py
with
22 additions
and
14 deletions
backend/src/ceph_service.py
+
20
−
13
View file @
de5b477d
...
...
@@ -10,36 +10,43 @@ 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
return
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
)
def
list_buckets
()
->
BucketResponse
:
s3
=
get_s3_client
()
response
=
s3
.
list_buckets
()
client
=
s3
.
meta
.
client
response
=
client
.
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
)
bucket_acl
=
client
.
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
"
)
objects
=
s3
.
Bucket
(
bucket_name
).
objects
.
all
()
n_objects
=
0
size_byte
=
0
for
obj
in
objects
:
n_objects
+=
1
size_byte
+=
obj
.
size
rw_access
=
BucketRWAccess
(
read
=
read
,
write
=
write
)
buckets
[
i
]
=
Bucket
(
name
=
bucket_name
,
creation_date
=
creation_date
,
details
=
{},
rw_access
=
rw_access
rw_access
=
rw_access
,
objects
=
n_objects
,
size
=
size_byte
)
return
BucketResponse
(
buckets
=
buckets
,
total
=
len
(
buckets
))
This diff is collapsed.
Click to expand it.
backend/src/models/buckets.py
+
2
−
1
View file @
de5b477d
...
...
@@ -13,7 +13,8 @@ class Bucket(BaseModel):
creation_date
:
datetime
details
:
dict
rw_access
:
BucketRWAccess
objects
:
int
size
:
int
class
BucketResponse
(
BaseModel
):
buckets
:
List
[
Bucket
]
...
...
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