Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error message when using --with-auth for b2id urls #1070

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)