Skip to content
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

fix resetting lifecycle rules in update-bucket #925

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
* Fix lifecycle rules being cleared after using `update-bucket` command if not explicitly set again.

## [3.10.0] - 2023-09-10

### Added
Expand Down
2 changes: 1 addition & 1 deletion b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def _setup_parser(cls, parser):
lifecycle_group.add_argument(
'--lifecycleRule',
action='append',
default=[],
default=None,
type=functools.partial(validated_loads, expected_type=LifecycleRule),
dest='lifecycleRules',
help="Lifecycle rule in JSON format. Can be supplied multiple times.",
Expand Down
34 changes: 34 additions & 0 deletions test/unit/test_console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,40 @@ def test_create_bucket_key_and_authorize_with_it(self):
0,
)

def test_update_bucket_without_lifecycle(self):
# Start with authorizing with the master key
self._authorize_account()

bucket_name = 'my-bucket-liferules'
# Create a bucket with lifecycleRule
self._run_command(
[
'create-bucket', '--lifecycleRule',
'{"daysFromHidingToDeleting": 2, "fileNamePrefix": "foo"}', bucket_name,
'allPrivate'
], 'bucket_0\n', '', 0
)

expected_stdout_dict = {
"accountId": self.account_id,
"bucketId": "bucket_0",
"bucketInfo": {
"xxx": "123"
},
"bucketName": "my-bucket-liferules",
"bucketType": "allPrivate",
"lifecycleRules": [{
"daysFromHidingToDeleting": 2,
"fileNamePrefix": "foo"
}],
}

# Update some other attribute than lifecycleRule, which should remain intact
self._run_command(
['update-bucket', bucket_name, '--bucketInfo', '{"xxx": "123"}'],
expected_json_in_stdout=expected_stdout_dict,
)

def test_clear_account(self):
# Initial condition
self._authorize_account()
Expand Down