-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASMCMS-9201 - Fix orphaned artifacts in S3. #155
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||
# | ||||||
# MIT License | ||||||
# | ||||||
# (C) Copyright 2018-2023 Hewlett Packard Enterprise Development LP | ||||||
# (C) Copyright 2018-2023, 2025 Hewlett Packard Enterprise Development LP | ||||||
# | ||||||
# Permission is hereby granted, free of charge, to any person obtaining a | ||||||
# copy of this software and associated documentation files (the "Software"), | ||||||
|
@@ -426,9 +426,37 @@ def _delete_s3_artifact(): | |||||
|
||||||
def s3_move_artifact(origin_url, destination_path): | ||||||
""" Utility function to orchestrate moving/renaming a S3 artifact to a new key value. """ | ||||||
new_object = app.s3resource.Object(origin_url.bucket, destination_path) | ||||||
new_object.copy_from(CopySource='/'.join([origin_url.bucket, origin_url.key])) | ||||||
|
||||||
# NOTE: there is 'move' or 'rename' function with S3 objects, so we have to copy then | ||||||
# delete the old object. For artifacts smaller than 5Gb, the Object.copy_from function | ||||||
# works and does this in a single transfer operation. For larger than 5Gb, it has to | ||||||
# use a multi-part copy operation. This is automatically handled by the Object.copy | ||||||
# function. The multi-part copy requires greater levels of permissions than the single | ||||||
# transfer copy. It will currenly not work if the owner of the object is something | ||||||
# other than IMS. When an object is copied into S3 via 'cray artifacts create ...' it | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# has an owner of 'STS' and can't be copied with the multi-part transfer. | ||||||
|
||||||
# Find the owner of the object | ||||||
sts_owned = False | ||||||
orig_object_owner = app.s3resource.ObjectAcl(origin_url.bucket, origin_url.key) | ||||||
if orig_object_owner.owner != None and 'ID' in orig_object_owner.owner and orig_object_owner.owner['ID']=='STS': | ||||||
app.logger.info(f"Source object owner: {orig_object_owner.owner['ID']}") | ||||||
sts_owned = True | ||||||
|
||||||
# if the object is owned by 'STS', then a multi-part copy needs to be done with 'STS' creds | ||||||
new_object = None | ||||||
if not sts_owned: | ||||||
new_object = app.s3resource.Object(origin_url.bucket, destination_path) | ||||||
else: | ||||||
new_object = app.s3_sts_resource.Object(origin_url.bucket, destination_path) | ||||||
|
||||||
# Copy - should do multi-part copy if needed | ||||||
copy_source = {'Bucket':origin_url.bucket, 'Key':origin_url.key} | ||||||
new_object.copy(copy_source) | ||||||
|
||||||
# delete the original object | ||||||
app.s3resource.Object(origin_url.bucket, origin_url.key).delete() | ||||||
|
||||||
return new_object | ||||||
|
||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're hashing all of these potential false values to False, but you're not doing the same for, presumably, the true values. Why not? You're just taking whatever is in that environment variable.