Skip to content

Commit

Permalink
Add default retention setting to BucketSimulator
Browse files Browse the repository at this point in the history
  • Loading branch information
ppolewicz committed May 13, 2021
1 parent 47227d6 commit 7b53577
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions b2sdk/raw_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,20 @@ def bucket_dict(self, account_auth_token):
] = self.default_server_side_encryption.algorithm.value
else:
default_sse['value'] = {'mode': EncryptionMode.UNKNOWN}
logger.debug('default sse returned is: %s', default_sse)

if self.is_allowed_to_read_bucket_retention(account_auth_token):
file_lock_configuration = {
'isClientAuthorizedToRead': True,
'value': {
'defaultRetention': {
'mode': self.default_retention.mode.value,
'period': self.default_retention.period,
},
'isFileLockEnabled': self.is_file_lock_enabled,
},
} # yapf: disable
else:
file_lock_configuration = {'isClientAuthorizedToRead': False, 'value': None}
return dict(
accountId=self.account_id,
bucketName=self.bucket_name,
Expand All @@ -513,6 +526,7 @@ def bucket_dict(self, account_auth_token):
options=self.options_set,
revision=self.revision,
defaultServerSideEncryption=default_sse,
fileLockConfiguration=file_lock_configuration,
)

def cancel_large_file(self, file_id):
Expand Down Expand Up @@ -797,8 +811,9 @@ def _update_bucket(
bucket_info=None,
cors_rules=None,
lifecycle_rules=None,
if_revision_is=None,
default_server_side_encryption=None,
if_revision_is: Optional[int] = None,
default_server_side_encryption: Optional[EncryptionSetting] = None,
default_retention: Optional[BucketRetentionSetting] = None,
):
if if_revision_is is not None and self.revision != if_revision_is:
raise Conflict()
Expand All @@ -813,6 +828,8 @@ def _update_bucket(
self.lifecycle_rules = lifecycle_rules
if default_server_side_encryption is not None:
self.default_server_side_encryption = default_server_side_encryption
if default_retention:
self.default_retention = default_retention
self.revision += 1
return self.bucket_dict(self.api.current_token)

Expand Down Expand Up @@ -1498,7 +1515,8 @@ def update_bucket(
cors_rules=None,
lifecycle_rules=None,
if_revision_is=None,
default_server_side_encryption=None,
default_server_side_encryption: Optional[EncryptionSetting] = None,
default_retention: Optional[BucketRetentionSetting] = None,
):
assert bucket_type or bucket_info or cors_rules or lifecycle_rules or default_server_side_encryption
bucket = self._get_bucket_by_id(bucket_id)
Expand All @@ -1510,6 +1528,7 @@ def update_bucket(
lifecycle_rules=lifecycle_rules,
if_revision_is=if_revision_is,
default_server_side_encryption=default_server_side_encryption,
default_retention=default_retention,
)

def upload_file(
Expand Down

0 comments on commit 7b53577

Please sign in to comment.