Skip to content

Commit

Permalink
Revert some changes to glacier_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
netsettler committed Oct 23, 2023
1 parent e6815f7 commit 7cb98bb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dcicutils/glacier_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def __init__(self, env_name: str):
self.env_key = self.key_manager.get_keydict_for_env(env_name)
self.health_page = get_health_page(key=self.env_key, ff_env=env_name)

@property
def kms_key_id(self) -> str:
return self.health_page.get("s3_encrypt_key_id", "")

@classmethod
def is_glacier_storage_class(cls, storage_class: S3StorageClass):
return storage_class in S3_GLACIER_CLASSES
Expand Down Expand Up @@ -295,6 +299,9 @@ def _do_multipart_upload(self, bucket: str, key: str, total_size: int, part_size
}
if tags:
cmu['Tagging'] = tags
if self.kms_key_id:
cmu['ServerSideEncryption'] = 'aws:kms'
cmu['SSEKMSKeyId'] = self.kms_key_id
mpu = self.s3.create_multipart_upload(**cmu)
mpu_upload_id = mpu['UploadId']
except Exception as e:
Expand Down Expand Up @@ -381,16 +388,21 @@ def copy_object_back_to_original_location(self, bucket: str, key: str, storage_c
else:
# Force copy the object into standard in a single operation
copy_source = {'Bucket': bucket, 'Key': key}
copy_target = {
copy_args = {
'Bucket': bucket, 'Key': key,
'StorageClass': storage_class,
}
if version_id:
copy_source['VersionId'] = version_id
copy_target['CopySourceVersionId'] = version_id
copy_args['CopySourceVersionId'] = version_id
if tags:
copy_target['Tagging'] = tags
response = self.s3.copy_object(CopySource=copy_source, **copy_target)
copy_args['Tagging'] = tags
if self.kms_key_id:
copy_args['ServerSideEncryption'] = 'aws:kms'
copy_args['SSEKMSKeyId'] = self.kms_key_id
response = self.s3.copy_object(
**copy_args, CopySource=copy_source
)
PRINT(f'Response from boto3 copy:\n{response}')
PRINT(f'Object {bucket}/{key} copied back to its original location in S3')
return response
Expand Down

0 comments on commit 7cb98bb

Please sign in to comment.