diff --git a/b2/_internal/console_tool.py b/b2/_internal/console_tool.py index 26471b8f..d2430e46 100644 --- a/b2/_internal/console_tool.py +++ b/b2/_internal/console_tool.py @@ -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 @@ -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 diff --git a/changelog.d/+with_auth_b2id_error.fixed.md b/changelog.d/+with_auth_b2id_error.fixed.md new file mode 100644 index 00000000..6f2c297a --- /dev/null +++ b/changelog.d/+with_auth_b2id_error.fixed.md @@ -0,0 +1 @@ +Display error message when trying to use `--with-auth` param for `b2id://` urls in the `file url` command. diff --git a/test/unit/console_tool/test_get_url.py b/test/unit/console_tool/test_get_url.py index 94dd42bc..747f948f 100644 --- a/test/unit/console_tool/test_get_url.py +++ b/test/unit/console_tool/test_get_url.py @@ -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, + )