Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
s3storage
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
Service Desk
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
Show more breadcrumbs
cubicweb
cubes
s3storage
Commits
8044b4314a50
Commit
8044b4314a50
authored
2 years ago
by
Efflam Lemaillet
Browse files
Options
Downloads
Patches
Plain Diff
feat: add version id to entity
Refs:
#13
parent
8c41ae0c2e50
No related branches found
No related tags found
No related merge requests found
Pipeline
#152156
passed with warnings
2 years ago
Stage: lint
Stage: tests
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cubicweb_s3storage/storages.py
+24
-8
24 additions, 8 deletions
cubicweb_s3storage/storages.py
with
24 additions
and
8 deletions
cubicweb_s3storage/storages.py
+
24
−
8
View file @
8044b431
...
...
@@ -87,10 +87,6 @@
else
:
oldkey
=
self
.
get_s3_key
(
entity
,
attr
)
key
=
self
.
new_s3_key
(
entity
,
attr
)
# save S3 key
entity
.
cw_edited
.
edited_attribute
(
attr
,
Binary
(
key
.
encode
(
'
utf-8
'
)))
# copy Binary value, workaround for boto3 bug
# https://github.com/boto/s3transfer/issues/80
# .read() is required since Binary can't wrap itself
...
...
@@ -103,8 +99,8 @@
upload_key
=
key
extra_args
=
self
.
get_upload_extra_args
(
entity
,
attr
,
key
)
s3
_object
=
self
.
bucket
.
put_object
(
B
ody
=
buffer
,
Key
=
upload_key
,
**
extra_args
)
put
_object
_result
=
self
.
s3cnx
.
put_object
(
Body
=
buffer
,
B
ucket
=
self
.
bucket
,
Key
=
upload_key
,
**
extra_args
)
buffer
.
close
()
...
...
@@ -110,4 +106,7 @@
buffer
.
close
()
version_id
=
put_object_result
.
get
(
'
VersionId
'
,
None
)
# save S3 key
self
.
save_s3_key
(
entity
,
attr
,
upload_key
,
version_id
)
# when key is suffixed, move to final key in post commit event
# remove temporary key on rollback
...
...
@@ -160,6 +159,23 @@
source
.
doexec
(
cnx
,
sql
,
attrs
)
entity
.
cw_edited
=
None
def
save_s3_key
(
self
,
entity
,
attr
,
key
,
version_id
=
None
):
"""
Save the s3 key into the entity bytes attribute
"""
id_string
=
key
if
entity
.
_cw
.
repo
.
config
[
'
s3-activate-object-versioning
'
]
and
\
version_id
is
not
None
:
id_string
=
self
.
format_version_id_suffix
(
key
,
version_id
)
entity
.
cw_edited
.
edited_attribute
(
attr
,
Binary
(
id_string
.
encode
(
'
utf-8
'
)))
def
format_version_id_suffix
(
self
,
key
,
version_id
):
"""
Format the string that will store key and version id
"""
return
f
"
{
key
}
#
{
version_id
}
"
def
get_s3_key
(
self
,
entity
,
attr
):
"""
Return the S3 key of the S3 object storing the content of attribute
...
...
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