Skip to content

Commit

Permalink
Merge pull request Backblaze#1070 from reef-technologies/master
Browse files Browse the repository at this point in the history
Display error message when using --with-auth for b2id urls
  • Loading branch information
mlech-reef authored Feb 13, 2025
2 parents cf9efa2 + ff08b3e commit 97dc69a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2875,7 +2875,8 @@ class FileUrlBase(Command):
If it is private, you can use --with-auth to include an authorization
token in the URL that allows downloads from the given bucket for files
whose names start with the given file name.
whose names start with the given file name. NOTE: This param can only be used with
filename urls.
The URL will work for the given file, but is not specific to that file. Files
with longer names that start with the give file name can also be downloaded
Expand All @@ -2900,6 +2901,11 @@ def _run(self, args):
b2_uri = self.get_b2_uri_from_arg(args)
url = self.api.get_download_url_by_uri(b2_uri)
if args.with_auth:
if isinstance(b2_uri, B2FileIdURI):
raise CommandError(
'--with-auth param cannot be used with `b2id://` urls. Please, use `b2://bucket/filename` url format instead'
)

bucket = self.api.get_bucket_by_name(b2_uri.bucket_name)
auth_token = bucket.get_download_authorization(
file_name_prefix=b2_uri.path, valid_duration_in_seconds=args.duration
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+with_auth_b2id_error.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display error message when trying to use `--with-auth` param for `b2id://` urls in the `file url` command.
8 changes: 8 additions & 0 deletions test/unit/console_tool/test_get_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ def test_get_url__b2id_uri(b2_cli, uploaded_file, uploaded_file_url_by_id):
['file', 'url', f'b2id://{uploaded_file["fileId"]}'],
expected_stdout=f'{uploaded_file_url_by_id}\n',
)


def test_get_url__b2id_uri__with_auth__error(b2_cli, uploaded_file):
b2_cli.run(
['file', 'url', '--with-auth', f'b2id://{uploaded_file["fileId"]}'],
expected_stderr='ERROR: --with-auth param cannot be used with `b2id://` urls. Please, use `b2://bucket/filename` url format instead\n',
expected_status=1,
)

0 comments on commit 97dc69a

Please sign in to comment.