Skip to content

Commit

Permalink
fix create-key --all-capabilities when account doesnt have access t…
Browse files Browse the repository at this point in the history
…o notification-rules cap
  • Loading branch information
mjurbanski-reef committed Apr 23, 2024
1 parent 6a78575 commit 0ca594d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+create_key.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `create-key --all-capabilities` erroring out when new b2sdk is installed.
4 changes: 2 additions & 2 deletions test/unit/test_console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 0ca594d

Please sign in to comment.