b2sdk.account_info.abstract – Account info abstract

class b2sdk.account_info.abstract.AbstractAccountInfo[source]

Bases: object

Holder for all account-related information that needs to be kept between API calls, and between invocations of the command-line tool. This includes: account ID, application key ID, application key, auth tokens, API URL, download URL, and uploads URLs.

This class must be THREAD SAFE because it may be used by multiple threads running in the same Python process. It also needs to be safe against multiple processes running at the same time.

DEFAULT_ALLOWED = {'bucketId': None, 'bucketName': None, 'capabilities': ['listKeys', 'writeKeys', 'deleteKeys', 'listBuckets', 'writeBuckets', 'deleteBuckets', 'listFiles', 'readFiles', 'shareFiles', 'writeFiles', 'deleteFiles'], 'namePrefix': None}
REALM_URLS = {'dev': 'http://api.backblazeb2.xyz:8180', 'production': 'https://api.backblazeb2.com', 'staging': 'https://api.backblaze.net'}
classmethod all_capabilities()[source]

Return a list of all possible capabilities

Return type

list

classmethod allowed_is_valid(allowed)[source]

Makes sure that all of the required fields are present, and that bucketId is set if bucketName is.

If the bucketId is for a bucket that no longer exists, or the capabilities do not allow listBuckets, then we won’t have a bucketName.

Parameters

allowed (dict) – the structure to use for old account info that was saved without ‘allowed’

Return type

bool

abstract clear()[source]

Removes all stored information

abstract clear_bucket_upload_data(bucket_id)[source]

Removes all upload URLs for the given bucket.

Parameters

bucket_id (str) – a bucket ID

abstract clear_large_file_upload_urls(file_id)[source]

Clear a pool of URLs for a given file ID

Parameters

file_id (str) – a file ID

abstract get_account_auth_token()[source]

Returns account_auth_token or raises MissingAccountData exception

Return type

str

abstract get_account_id()[source]

Returns account ID or raises MissingAccountData exception

Return type

str

get_account_id_or_app_key_id()[source]

Returns the application key ID used to authenticate

Return type

str

Deprecated since version 0.1.6: Use get_application_key_id() instead.

abstract get_allowed()[source]

An ‘allowed’ dict, as returned by b2_authorize_account. Never None; for account info that was saved before ‘allowed’ existed, returns DEFAULT_ALLOWED.

Return type

dict

abstract get_api_url()[source]

Returns api_url or raises MissingAccountData exception

Return type

str

abstract get_application_key()[source]

Returns application_key or raises MissingAccountData exception

Return type

str

abstract get_application_key_id()[source]

Returns the application key ID used to authenticate

Return type

str

abstract get_bucket_id_or_none_from_bucket_name(bucket_name)[source]

Looks up the bucket ID for a given bucket name.

Parameters

bucket_name (str) – a bucket name

Return bucket ID or None

Return type

str, None

abstract get_download_url()[source]

Returns download_url or raises MissingAccountData exception

Return type

str

abstract get_minimum_part_size()[source]

Return the minimum number of bytes in a part of a large file

Returns

number of bytes

Return type

int

abstract get_realm()[source]

Returns realm or raises MissingAccountData exception

Return type

str

abstract put_bucket_upload_url(bucket_id, upload_url, upload_auth_token)[source]

Add an (upload_url, upload_auth_token) pair to the pool available for the bucket.

Parameters
  • bucket_id (str) – a bucket ID

  • upload_url (str) – an upload URL

  • upload_auth_token (str) – an upload authentication token

Return type

tuple

abstract put_large_file_upload_url(file_id, upload_url, upload_auth_token)[source]

Put large file upload URL into a pool

Parameters
  • file_id (str) – a file ID

  • upload_url (str) – an upload URL

  • upload_auth_token (str) – an upload authentication token

abstract refresh_entire_bucket_name_cache(name_id_iterable)[source]

Removes all previous name-to-id mappings and stores new ones.

Parameters

name_id_iterable (list) – a list of tuples of the form (name, id)

abstract remove_bucket_name(bucket_name)[source]

Removes one entry from the bucket name cache.

Parameters

bucket_name (str) – a bucket name

abstract save_bucket(bucket)[source]

Remembers the ID for a bucket name.

Parameters

bucket (b2sdk.bucket.Bucket) – a Bucket object

set_auth_data(account_id, auth_token, api_url, download_url, minimum_part_size, application_key, realm, allowed=None, application_key_id=None)[source]

Stores the results of b2_authorize_account.

All of the information returned by b2_authorize_account is saved, because all of it is needed by some command.

The allowed structure is the one returned b2_authorize_account, with the addition of a bucketName field. For keys with bucket restrictions, the name of the bucket is looked up and stored, too. The console_tool does everything by bucket name, so it’s convenient to have the restricted bucket name handy.

Parameters
  • account_id (str) – user account ID

  • auth_token (str) – user authentication token

  • api_url (str) – an API URL

  • download_url (str) – path download URL

  • minimum_part_size (int) – minimum size of the file part

  • application_key (str) – application key

  • realm (str) – a realm to authorize account in

  • allowed (dict) – the structure to use for old account info that was saved without ‘allowed’

  • application_key_id (str) – application key ID

Changed in version 0.1.5: account_id_or_app_key_id renamed to get_application_key_id

abstract take_bucket_upload_url(bucket_id)[source]

Returns a pair (upload_url, upload_auth_token) that has been removed from the pool for this bucket, or (None, None) if there are no more left.

Parameters

bucket_id (str) – a bucket ID

Return type

tuple

abstract take_large_file_upload_url(file_id)[source]

Take large file upload URL from a pool

Parameters

file_id (str) – a file ID