Skip to content

Commit 079c9a3

Browse files
Merge pull request Backblaze#1093 from reef-technologies/master
Migrate to b2sdk.v3
2 parents df9d40b + 2fcd521 commit 079c9a3

24 files changed

+118
-96
lines changed

b2/_internal/_cli/arg_parser_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import re
1414

1515
import arrow
16-
from b2sdk.v2 import RetentionPeriod
16+
from b2sdk.v3 import RetentionPeriod
1717

1818
_arrow_version = tuple(int(p) for p in arrow.__version__.split('.'))
1919

b2/_internal/_cli/argcompleters.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def bucket_name_completer(prefix, parsed_args, **kwargs):
19-
from b2sdk.v2 import unprintable_to_hex
19+
from b2sdk.v3 import unprintable_to_hex
2020

2121
from b2._internal._cli.b2api import _get_b2api_for_profile
2222

@@ -36,7 +36,7 @@ def file_name_completer(prefix, parsed_args, **kwargs):
3636
3737
To limit delay & cost only lists files returned from by single call to b2_list_file_names
3838
"""
39-
from b2sdk.v2 import LIST_FILE_NAMES_MAX_LIMIT, unprintable_to_hex
39+
from b2sdk.v3 import LIST_FILE_NAMES_MAX_LIMIT, unprintable_to_hex
4040

4141
from b2._internal._cli.b2api import _get_b2api_for_profile
4242

@@ -47,7 +47,6 @@ def file_name_completer(prefix, parsed_args, **kwargs):
4747
latest_only=True,
4848
recursive=False,
4949
fetch_count=LIST_FILE_NAMES_MAX_LIMIT,
50-
folder_to_list_can_be_a_file=True,
5150
)
5251
return [
5352
unprintable_to_hex(folder_name or file_version.file_name)
@@ -59,7 +58,7 @@ def b2uri_file_completer(prefix: str, parsed_args, **kwargs):
5958
"""
6059
Complete B2 URI pointing to a file-like object in a bucket.
6160
"""
62-
from b2sdk.v2 import LIST_FILE_NAMES_MAX_LIMIT, unprintable_to_hex
61+
from b2sdk.v3 import LIST_FILE_NAMES_MAX_LIMIT, unprintable_to_hex
6362

6463
from b2._internal._cli.b2api import _get_b2api_for_profile
6564
from b2._internal._utils.python_compat import removeprefix

b2/_internal/_cli/b2api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
import os
1212
from typing import Optional
1313

14-
from b2sdk.v2 import (
14+
from b2sdk.v3 import (
1515
AuthInfoCache,
1616
B2Api,
1717
B2HttpApiConfig,
1818
InMemoryAccountInfo,
1919
InMemoryCache,
2020
SqliteAccountInfo,
2121
)
22-
from b2sdk.v2.exception import MissingAccountData
22+
from b2sdk.v3.exception import MissingAccountData
2323

2424
from b2._internal._cli.const import B2_USER_AGENT_APPEND_ENV_VAR
2525

b2/_internal/_cli/obj_dumps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
######################################################################
1010
import io
1111

12-
from b2sdk.v2 import (
12+
from b2sdk.v3 import (
1313
unprintable_to_hex,
1414
)
1515

b2/_internal/_cli/obj_loads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sys
1818
from typing import TypeVar
1919

20-
from b2sdk.v2 import get_b2sdk_doc_urls
20+
from b2sdk.v3 import get_b2sdk_doc_urls
2121

2222
try:
2323
import pydantic

b2/_internal/_utils/uri.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
from pathlib import Path
1717
from typing import Sequence
1818

19-
from b2sdk.v2 import (
19+
from b2sdk.v3 import (
2020
B2Api,
2121
DownloadVersion,
2222
FileVersion,
2323
Filter,
2424
)
25-
from b2sdk.v2.exception import B2Error
25+
from b2sdk.v3.exception import B2Error
2626

2727
from b2._internal._utils.python_compat import removeprefix
2828

b2/_internal/console_tool.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import b2sdk
5555
import requests
5656
import rst2ansi
57-
from b2sdk.v2 import (
57+
from b2sdk.v3 import (
5858
ALL_CAPABILITIES,
5959
B2_ACCOUNT_INFO_DEFAULT_FILE,
6060
B2_ACCOUNT_INFO_ENV_VAR,
@@ -103,12 +103,12 @@
103103
get_included_sources,
104104
make_progress_listener,
105105
notification_rule_response_to_request,
106-
parse_sync_folder,
106+
parse_folder,
107107
points_to_fifo,
108108
substitute_control_chars,
109109
unprintable_to_hex,
110110
)
111-
from b2sdk.v2.exception import (
111+
from b2sdk.v3.exception import (
112112
B2Error,
113113
BadFileInfo,
114114
EmptyDirectory,
@@ -1364,7 +1364,7 @@ def authorize(self, application_key_id, application_key, realm: str | None):
13641364
if verbose_realm:
13651365
self._print_stderr(f'Using {url}')
13661366
try:
1367-
self.api.authorize_account(realm, application_key_id, application_key)
1367+
self.api.authorize_account(application_key_id, application_key, realm=realm)
13681368

13691369
allowed = self.api.account_info.get_allowed()
13701370
if 'listBuckets' not in allowed['capabilities']:
@@ -1376,15 +1376,26 @@ def authorize(self, application_key_id, application_key, realm: str | None):
13761376
)
13771377
self.api.account_info.clear()
13781378
return 1
1379-
if allowed['bucketId'] is not None and allowed['bucketName'] is None:
1380-
logger.error('ConsoleTool has bucket-restricted key and the bucket does not exist')
1381-
self._print_stderr(
1382-
"ERROR: application key is restricted to bucket id '{}', which no longer exists".format(
1383-
allowed['bucketId']
1379+
buckets = allowed['buckets']
1380+
if buckets:
1381+
existing_bucket_present = False
1382+
1383+
for item in buckets:
1384+
if item['name'] is not None:
1385+
existing_bucket_present = True
1386+
break
1387+
1388+
if not existing_bucket_present:
1389+
logger.error(
1390+
'ConsoleTool has bucket-restricted key and the bucket does not exist'
13841391
)
1385-
)
1386-
self.api.account_info.clear()
1387-
return 1
1392+
self._print_stderr(
1393+
"ERROR: application key is restricted to bucket id '{}', which no longer exists".format(
1394+
allowed['bucketId']
1395+
)
1396+
)
1397+
self.api.account_info.clear()
1398+
return 1
13881399
return 0
13891400
except B2Error as e:
13901401
logger.exception('ConsoleTool account authorization error')
@@ -1736,11 +1747,13 @@ def _run(self, args):
17361747
set(ALL_CAPABILITIES) - preview_feature_caps | current_key_caps
17371748
)
17381749

1750+
buckets_ids = [bucket_id_or_none] if bucket_id_or_none else None
1751+
17391752
application_key = self.api.create_key(
17401753
capabilities=args.capabilities,
17411754
key_name=args.keyName,
17421755
valid_duration_seconds=args.duration,
1743-
bucket_id=bucket_id_or_none,
1756+
bucket_ids=buckets_ids,
17441757
name_prefix=args.name_prefix,
17451758
)
17461759

@@ -2344,10 +2357,13 @@ def print_key(self, key: ApplicationKey, is_long_format: bool):
23442357
format_str = '{keyId} {keyName:20s}'
23452358
timestamp_or_none = apply_or_none(int, key.expiration_timestamp_millis)
23462359
(date_str, time_str) = self.timestamp_display(timestamp_or_none)
2360+
2361+
bucket_id = key.bucket_ids[0] if key.bucket_ids else None
2362+
23472363
key_str = format_str.format(
23482364
keyId=key.id_,
23492365
keyName=key.key_name,
2350-
bucketName=self.bucket_display_name(key.bucket_id),
2366+
bucketName=self.bucket_display_name(bucket_id),
23512367
namePrefix=(key.name_prefix or ''),
23522368
capabilities=','.join(key.capabilities),
23532369
dateStr=date_str,
@@ -2478,7 +2494,6 @@ def _get_ls_generator(self, args, b2_uri: B2URI | None = None):
24782494
recursive=args.recursive,
24792495
with_wildcard=args.with_wildcard,
24802496
filters=args.filters,
2481-
folder_to_list_can_be_a_file=True,
24822497
)
24832498
except Exception as err:
24842499
raise CommandError(unprintable_to_hex(str(err))) from err
@@ -3170,8 +3185,8 @@ def _run(self, args):
31703185
self.api.services.upload_manager.set_thread_pool_size(upload_threads)
31713186
self.api.services.download_manager.set_thread_pool_size(download_threads)
31723187

3173-
source = parse_sync_folder(args.source, self.console_tool.api)
3174-
destination = parse_sync_folder(args.destination, self.console_tool.api)
3188+
source = parse_folder(args.source, self.console_tool.api)
3189+
destination = parse_folder(args.destination, self.console_tool.api)
31753190
allow_empty_source = args.allow_empty_source or VERSION_0_COMPATIBILITY
31763191

31773192
synchronizer = self.get_synchronizer_from_args(

b2/_internal/json_encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import json
1212
from enum import Enum
1313

14-
from b2sdk.v2 import Bucket, DownloadVersion, FileIdAndName, FileVersion
14+
from b2sdk.v3 import Bucket, DownloadVersion, FileIdAndName, FileVersion
1515

1616

1717
class B2CliJsonEncoder(json.JSONEncoder):

changelog.d/+b2sdk_v3.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Migrate to b2sdk.v3.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Redesign console tools tests using b2sdk.v1 to use b2sdk.v3.

0 commit comments

Comments
 (0)