From 0ca594d59cac78beee75e06f072475828352e77d Mon Sep 17 00:00:00 2001 From: Maciej Urbanski Date: Mon, 22 Apr 2024 22:28:35 +0200 Subject: [PATCH] fix `create-key --all-capabilities` when account doesnt have access to notification-rules cap --- b2/_internal/console_tool.py | 9 ++++++++- changelog.d/+create_key.fixed.md | 1 + test/unit/test_console_tool.py | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelog.d/+create_key.fixed.md diff --git a/b2/_internal/console_tool.py b/b2/_internal/console_tool.py index 9376eb4ab..bc7e258c7 100644 --- a/b2/_internal/console_tool.py +++ b/b2/_internal/console_tool.py @@ -1643,7 +1643,14 @@ def _run(self, args): bucket_id_or_none = self.api.get_bucket_by_name(args.bucket).id_ if args.all_capabilities: - args.capabilities = ALL_CAPABILITIES + current_key_caps = set(self.api.account_info.get_allowed()['capabilities']) + preview_feature_caps = { + 'readBucketNotifications', + 'writeBucketNotifications', + } + args.capabilities = sorted( + set(ALL_CAPABILITIES) - preview_feature_caps | current_key_caps + ) application_key = self.api.create_key( capabilities=args.capabilities, diff --git a/changelog.d/+create_key.fixed.md b/changelog.d/+create_key.fixed.md new file mode 100644 index 000000000..a7c9bab99 --- /dev/null +++ b/changelog.d/+create_key.fixed.md @@ -0,0 +1 @@ +Fix `create-key --all-capabilities` erroring out when new b2sdk is installed. diff --git a/test/unit/test_console_tool.py b/test/unit/test_console_tool.py index 044b8e4ea..0843d6947 100644 --- a/test/unit/test_console_tool.py +++ b/test/unit/test_console_tool.py @@ -744,7 +744,7 @@ def test_keys(self): appKeyId1 goodKeyName-Two my-bucket-a - - '' readFiles,listBuckets,readBucketEncryption appKeyId3 goodKeyName-Four - - - '' {} appKeyId4 goodKeyName-Five id=bucket_1 - - '' readFiles,listBuckets - """.format(','.join(ALL_CAPABILITIES)) + """.format(','.join(sorted(ALL_CAPABILITIES))) self._run_command(['list-keys'], expected_list_keys_out, '', 0) self._run_command(['list-keys', '--long'], expected_list_keys_out_long, '', 0) @@ -1584,7 +1584,7 @@ def test_get_account_info(self): { "bucketId": None, "bucketName": None, - "capabilities": ALL_CAPABILITIES, + "capabilities": sorted(ALL_CAPABILITIES), "namePrefix": None }, "apiUrl": "http://api.example.com",