5454import b2sdk
5555import requests
5656import 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 ,
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 (
0 commit comments