From a5b5aeb5eaea7ed2021436824cf8da52ff4d3981 Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Sat, 23 Oct 2021 12:43:13 +0200 Subject: [PATCH 1/8] Add --allCapabilities to create-key --- CHANGELOG.md | 3 +++ b2/console_tool.py | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebb02796b..99849f10c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +* Add `--allCapabilities` to `create-key` + ## [3.0.3] - 2021-09-27 ### Fixed diff --git a/b2/console_tool.py b/b2/console_tool.py index 7d9d5168a..1a55c1dce 100644 --- a/b2/console_tool.py +++ b/b2/console_tool.py @@ -26,6 +26,7 @@ from typing import Optional, Tuple from b2sdk.v2 import ( + ALL_CAPABILITIES, B2_ACCOUNT_INFO_DEFAULT_FILE, B2_ACCOUNT_INFO_ENV_VAR, DEFAULT_SCAN_MANAGER, @@ -974,6 +975,7 @@ class CreateKey(Command): their IDs, but not the secret keys. The capabilities are passed in as a comma-separated list, like ``readFiles,writeFiles``. + Optionally, you can pass all capabilities with ``--allCapabilities``. The ``duration`` is the length of time (in seconds) the new application key will exist. When the time expires the key will disappear and will no longer be usable. If not @@ -998,7 +1000,10 @@ def _setup_parser(cls, parser): parser.add_argument('--namePrefix') parser.add_argument('--duration', type=int) parser.add_argument('keyName') - parser.add_argument('capabilities', type=parse_comma_separated_list) + + capabilities = parser.add_mutually_exclusive_group(required=True) + capabilities.add_argument('capabilities', type=parse_comma_separated_list, nargs='?') + capabilities.add_argument('--allCapabilities', action='store_true') def run(self, args): # Translate the bucket name into a bucketId @@ -1007,6 +1012,9 @@ def run(self, args): else: bucket_id_or_none = self.api.get_bucket_by_name(args.bucket).id_ + if args.allCapabilities: + args.capabilities = ALL_CAPABILITIES + application_key = self.api.create_key( capabilities=args.capabilities, key_name=args.keyName, From b24817f41f4676f5eb67452edcf01d54df18f179 Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Sat, 23 Oct 2021 13:09:26 +0200 Subject: [PATCH 2/8] Add unit tests --- test/unit/test_console_tool.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/unit/test_console_tool.py b/test/unit/test_console_tool.py index 98b5f21ec..2712bccec 100644 --- a/test/unit/test_console_tool.py +++ b/test/unit/test_console_tool.py @@ -18,6 +18,7 @@ from b2sdk import v1 +from b2sdk.v2 import ALL_CAPABILITIES from b2sdk.v2 import REALM_URLS from b2sdk.v2 import StubAccountInfo from b2sdk.v2 import B2Api @@ -611,6 +612,14 @@ def test_keys(self): '', 0, ) + self._run_command( + [ + 'create-key', '--allCapabilities', 'goodKeyName-Four' + ], + 'appKeyId3 appKey3\n', + '', + 0, + ) # Delete one key self._run_command(['delete-key', 'appKeyId2'], 'appKeyId2\n', '', 0) @@ -623,13 +632,15 @@ def test_keys(self): appKeyId0 goodKeyName-One appKeyId1 goodKeyName-Two appKeyId2 goodKeyName-Three + appKeyId3 goodKeyName-Four """ expected_list_keys_out_long = """ appKeyId0 goodKeyName-One - - - '' readFiles,listBuckets appKeyId1 goodKeyName-Two my-bucket-a - - '' readFiles,listBuckets,readBucketEncryption appKeyId2 goodKeyName-Three id=bucket_1 - - '' readFiles,listBuckets - """ + appKeyId3 goodKeyName-Four - - - '' %s + """ % (','.join(ALL_CAPABILITIES),) self._run_command(['list-keys'], expected_list_keys_out, '', 0) self._run_command(['list-keys', '--long'], expected_list_keys_out_long, '', 0) From 9254cef2c3a859169dc5e0c64d1890a1c1994c6b Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Sat, 23 Oct 2021 13:11:18 +0200 Subject: [PATCH 3/8] Format the code --- test/unit/test_console_tool.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unit/test_console_tool.py b/test/unit/test_console_tool.py index 2712bccec..cf9688536 100644 --- a/test/unit/test_console_tool.py +++ b/test/unit/test_console_tool.py @@ -613,9 +613,7 @@ def test_keys(self): 0, ) self._run_command( - [ - 'create-key', '--allCapabilities', 'goodKeyName-Four' - ], + ['create-key', '--allCapabilities', 'goodKeyName-Four'], 'appKeyId3 appKey3\n', '', 0, From fceb8844d5088419a4073a101e8fcc268a71a650 Mon Sep 17 00:00:00 2001 From: Maciej Lech <63924630+mlech-reef@users.noreply.github.com> Date: Sun, 24 Oct 2021 15:41:44 +0200 Subject: [PATCH 4/8] Update b2/console_tool.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paweł Polewicz --- b2/console_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/b2/console_tool.py b/b2/console_tool.py index 1a55c1dce..5e28576b7 100644 --- a/b2/console_tool.py +++ b/b2/console_tool.py @@ -975,7 +975,7 @@ class CreateKey(Command): their IDs, but not the secret keys. The capabilities are passed in as a comma-separated list, like ``readFiles,writeFiles``. - Optionally, you can pass all capabilities with ``--allCapabilities``. + Optionally, you can pass all capabilities known to this client with ``--allCapabilities``. The ``duration`` is the length of time (in seconds) the new application key will exist. When the time expires the key will disappear and will no longer be usable. If not From 760bd253aaa707fe0cd0d127bf7b78a7618fc8c0 Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Sun, 24 Oct 2021 19:18:35 +0200 Subject: [PATCH 5/8] Upgrade b2sdk --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6a80d9403..b4584499b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ arrow>=0.8.0,<1.0.0 -b2sdk>=1.12.0,<2.0.0 +b2sdk>=1.13.0,<2.0.0 docutils==0.16 importlib-metadata>=2.1.1,<3.0.0; python_version <= '3.5' importlib-metadata>=3.3.0; python_version > '3.5' and python_version < '3.8' From 881554b39f4900328d26b57b752b2699e8c0884c Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Sun, 24 Oct 2021 19:18:46 +0200 Subject: [PATCH 6/8] Fix unit tests --- test/unit/test_console_tool.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/unit/test_console_tool.py b/test/unit/test_console_tool.py index cf9688536..7e04925c1 100644 --- a/test/unit/test_console_tool.py +++ b/test/unit/test_console_tool.py @@ -1401,10 +1401,11 @@ def test_get_account_info(self): "bucketName": None, "capabilities": [ - "listKeys", "writeKeys", "deleteKeys", "listBuckets", "writeBuckets", - "deleteBuckets", "readBucketEncryption", "writeBucketEncryption", - "readBucketRetentions", "writeBucketRetentions", "writeFileRetentions", - "writeFileLegalHolds", "readFileRetentions", "readFileLegalHolds", + "listKeys", "writeKeys", "deleteKeys", "listBuckets", + "listAllBucketNames", "readBuckets", "writeBuckets", "deleteBuckets", + "readBucketEncryption", "writeBucketEncryption", "readBucketRetentions", + "writeBucketRetentions", "readFileRetentions", "writeFileRetentions", + "readFileLegalHolds", "writeFileLegalHolds", "bypassGovernance", "listFiles", "readFiles", "shareFiles", "writeFiles", "deleteFiles" ], "namePrefix": None From e3aff1f9337d6e2859a8ab9fec40d4e6df782123 Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Sun, 24 Oct 2021 19:19:00 +0200 Subject: [PATCH 7/8] Update the readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99b231ee5..ce1166727 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Alternatively, you can install with: b2 clear-account [-h] b2 copy-file-by-id [-h] [--fetchMetadata] [--contentType CONTENTTYPE] [--range RANGE] [--info INFO | --noInfo] [--destinationServerSideEncryption {SSE-B2,SSE-C}] [--destinationServerSideEncryptionAlgorithm {AES256}] [--sourceServerSideEncryption {SSE-C}] [--sourceServerSideEncryptionAlgorithm {AES256}] [--fileRetentionMode {compliance,governance}] [--retainUntil TIMESTAMP] [--legalHold {on,off}] sourceFileId destinationBucketName b2FileName b2 create-bucket [-h] [--bucketInfo BUCKETINFO] [--corsRules CORSRULES] [--lifecycleRules LIFECYCLERULES] [--fileLockEnabled] [--defaultServerSideEncryption {SSE-B2,none}] [--defaultServerSideEncryptionAlgorithm {AES256}] bucketName bucketType - b2 create-key [-h] [--bucket BUCKET] [--namePrefix NAMEPREFIX] [--duration DURATION] keyName capabilities + b2 create-key [-h] [--bucket BUCKET] [--namePrefix NAMEPREFIX] [--duration DURATION] [--allCapabilities] keyName [capabilities] b2 delete-bucket [-h] bucketName b2 delete-file-version [-h] [fileName] fileId b2 delete-key [-h] applicationKeyId From f4fe5c5e3f9a0290002f6c3ad392a2068fee1edf Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Mon, 25 Oct 2021 17:30:06 +0200 Subject: [PATCH 8/8] Update unit tests --- test/unit/test_console_tool.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/unit/test_console_tool.py b/test/unit/test_console_tool.py index 7e04925c1..2be3096b4 100644 --- a/test/unit/test_console_tool.py +++ b/test/unit/test_console_tool.py @@ -1399,15 +1399,7 @@ def test_get_account_info(self): { "bucketId": None, "bucketName": None, - "capabilities": - [ - "listKeys", "writeKeys", "deleteKeys", "listBuckets", - "listAllBucketNames", "readBuckets", "writeBuckets", "deleteBuckets", - "readBucketEncryption", "writeBucketEncryption", "readBucketRetentions", - "writeBucketRetentions", "readFileRetentions", "writeFileRetentions", - "readFileLegalHolds", "writeFileLegalHolds", "bypassGovernance", - "listFiles", "readFiles", "shareFiles", "writeFiles", "deleteFiles" - ], + "capabilities": ALL_CAPABILITIES, "namePrefix": None }, "apiUrl": "http://api.example.com",