Skip to content

Commit ff08b3e

Browse files
Merge pull request #319 from reef-technologies/fix-url-for-b2id
Display error message when using `--with-auth` for b2id urls
2 parents cf9efa2 + 29c05c8 commit ff08b3e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

b2/_internal/console_tool.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,8 @@ class FileUrlBase(Command):
28752875
28762876
If it is private, you can use --with-auth to include an authorization
28772877
token in the URL that allows downloads from the given bucket for files
2878-
whose names start with the given file name.
2878+
whose names start with the given file name. NOTE: This param can only be used with
2879+
filename urls.
28792880
28802881
The URL will work for the given file, but is not specific to that file. Files
28812882
with longer names that start with the give file name can also be downloaded
@@ -2900,6 +2901,11 @@ def _run(self, args):
29002901
b2_uri = self.get_b2_uri_from_arg(args)
29012902
url = self.api.get_download_url_by_uri(b2_uri)
29022903
if args.with_auth:
2904+
if isinstance(b2_uri, B2FileIdURI):
2905+
raise CommandError(
2906+
'--with-auth param cannot be used with `b2id://` urls. Please, use `b2://bucket/filename` url format instead'
2907+
)
2908+
29032909
bucket = self.api.get_bucket_by_name(b2_uri.bucket_name)
29042910
auth_token = bucket.get_download_authorization(
29052911
file_name_prefix=b2_uri.path, valid_duration_in_seconds=args.duration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display error message when trying to use `--with-auth` param for `b2id://` urls in the `file url` command.

test/unit/console_tool/test_get_url.py

+8
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ def test_get_url__b2id_uri(b2_cli, uploaded_file, uploaded_file_url_by_id):
6262
['file', 'url', f'b2id://{uploaded_file["fileId"]}'],
6363
expected_stdout=f'{uploaded_file_url_by_id}\n',
6464
)
65+
66+
67+
def test_get_url__b2id_uri__with_auth__error(b2_cli, uploaded_file):
68+
b2_cli.run(
69+
['file', 'url', '--with-auth', f'b2id://{uploaded_file["fileId"]}'],
70+
expected_stderr='ERROR: --with-auth param cannot be used with `b2id://` urls. Please, use `b2://bucket/filename` url format instead\n',
71+
expected_status=1,
72+
)

0 commit comments

Comments
 (0)