Skip to content

Commit 08c6f71

Browse files
Merge pull request Backblaze#1115 from reef-technologies/fix-unhide-b2id-uri-support
Fix b2id:// uri support in file unhide command
2 parents c858fef + 063a9e9 commit 08c6f71

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

b2/_internal/console_tool.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,8 +2274,16 @@ def _setup_parser(cls, parser):
22742274

22752275
def _run(self, args):
22762276
b2_uri = self.get_b2_uri_from_arg(args)
2277-
bucket = self.api.get_bucket_by_name(b2_uri.bucket_name)
2278-
file_id_and_name = bucket.unhide_file(b2_uri.path, args.bypass_governance)
2277+
2278+
if isinstance(b2_uri, B2FileIdURI):
2279+
file_version = self.api.get_file_info_by_uri(b2_uri)
2280+
bucket = self.api.get_bucket_by_id(file_version.bucket_id)
2281+
file_name = file_version.file_name
2282+
else:
2283+
bucket = self.api.get_bucket_by_name(b2_uri.bucket_name)
2284+
file_name = b2_uri.path
2285+
2286+
file_id_and_name = bucket.unhide_file(file_name, args.bypass_governance)
22792287
self._print_json(file_id_and_name)
22802288
return 0
22812289

changelog.d/1114.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix `b2id://` uri support in `file unhide` command.

test/unit/test_console_tool.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,39 @@ def test_get_bucket_with_hidden(self):
21612161
expected_json_in_stdout=expected_json,
21622162
)
21632163

2164+
@pytest.mark.apiver(from_ver=4)
2165+
def test_unhide_b2id(self):
2166+
self._authorize_account()
2167+
self._create_my_bucket()
2168+
2169+
bucket = self.b2_api.get_bucket_by_name('my-bucket')
2170+
stdout, stderr = self._get_stdouterr()
2171+
console_tool = self.console_tool_class(stdout, stderr)
2172+
2173+
file_version = bucket.upload(UploadSourceBytes(b'test'), 'test.txt')
2174+
bucket.hide_file('test.txt')
2175+
2176+
console_tool.run_command(['b2', 'file', 'unhide', f'b2id://{file_version.id_}'])
2177+
2178+
expected_json = {
2179+
'accountId': self.account_id,
2180+
'bucketId': 'bucket_0',
2181+
'bucketInfo': {},
2182+
'bucketName': 'my-bucket',
2183+
'bucketType': 'allPublic',
2184+
'corsRules': [],
2185+
'defaultServerSideEncryption': {'mode': 'none'},
2186+
'fileCount': 1,
2187+
'lifecycleRules': [],
2188+
'options': [],
2189+
'revision': 1,
2190+
'totalSize': 4,
2191+
}
2192+
self._run_command(
2193+
['bucket', 'get', '--show-size', 'my-bucket'],
2194+
expected_json_in_stdout=expected_json,
2195+
)
2196+
21642197
def test_get_bucket_complex(self):
21652198
self._authorize_account()
21662199
self._create_my_bucket()

0 commit comments

Comments
 (0)