-
Notifications
You must be signed in to change notification settings - Fork 17
ks/md5 #553
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
Open
katiewiessfelt
wants to merge
6
commits into
master
Choose a base branch
from
ks/md5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ks/md5 #553
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca79076
change references of md5 to sha256
728c443
create script to update aws objects to sha256 hashed keys
af75777
cannot update to sha256 due to comparison to external data
5e952fa
add useforsecurity attribute
d342cc0
created script to update aws objects
b912655
add sha256 process class
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import argparse | ||
| import hashlib | ||
| import logging | ||
|
|
||
| from castle.cms.files import aws | ||
| from castle.cms.services.google.youtube import get_youtube_service | ||
| import plone.api as api | ||
| from zope.component.hooks import setSite | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
| RESOURCES_KEY_PREFIX = 'archiveresources/' | ||
|
|
||
| parser = argparse.ArgumentParser( | ||
| description='...') | ||
| parser.add_argument('--site-id', dest='site_id', default='Castle') | ||
| args, _ = parser.parse_known_args() | ||
|
|
||
|
|
||
| def update_s3_resources(): | ||
| bucket_name = api.portal.get_registry_record( | ||
| 'castle.aws_s3_bucket_name') | ||
| s3_conn, bucket = aws.get_bucket(s3_bucket=bucket_name) | ||
| objects_summary_list = bucket.objects.all() | ||
| for object_summary in objects_summary_list: | ||
| md5_key = object_summary.key | ||
| obj = s3_conn.get_object(key=md5_key) | ||
| fidata = obj.get('Body') | ||
| copy_source = { | ||
| 'Bucket': bucket.name, | ||
| 'Key': md5_key | ||
| } | ||
| sha256 = hashlib.sha256(fidata).hexdigest() | ||
| sha256_content_path = '{0}{1}/{2}/{3}/{4}'.format( | ||
| RESOURCES_KEY_PREFIX, sha256[0], sha256[1], sha256[2], sha256 | ||
| ) | ||
| try: | ||
| # check if the key already exists | ||
| bucket.Object(sha256_content_path).load() | ||
| logger.info(f'key {md5_key} already exists, skipping') | ||
| except botocore.exceptions.ClientError: | ||
| # this is what we want, the sha256 hashed version shouldn't exist yet | ||
| new_obj = bucket.Object(sha256_content_path) | ||
| resp_copy = new_obj.copy(copy_source) | ||
| if resp_copy.status == 200: | ||
| resp_delete = bucket.Object(md5_key).delete() | ||
| if resp_delete.status != 200: | ||
| logger.error(f'Unable to delete md5 hashed key {md5_key}. This key should not be used for security purposes') | ||
| raise Exception(f'Unable to delete key {md5_key}.') | ||
|
|
||
| if __name__ == '__main__': | ||
| site = app[args.site_id] # noqa | ||
| setSite(site) | ||
| update_s3_resources(site) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.