Package oauth2client :: Module multistore_file
[hide private]
[frames] | no frames]

Module multistore_file

source code

Multi-credential file store with lock support.

This module implements a JSON credential store where multiple
credentials can be stored in one file. That file supports locking
both in a single process and across processes.

The credential themselves are keyed off of:
* client_id
* user_agent
* scope

The format of the stored data is like so:
{
  'file_version': 1,
  'data': [
    {
      'key': {
        'clientId': '<client id>',
        'userAgent': '<user agent>',
        'scope': '<scope>'
      },
      'credential': {
        # JSON serialized Credentials.
      }
    }
  ]
}


Author: jbeda@google.com (Joe Beda)

Classes [hide private]
  Error
Base error for this module.
  NewerCredentialStoreError
The credential store is a newer version that supported.
  _MultiStore
A file backed store for multiple credentials.
Functions [hide private]
 
get_credential_storage(filename, client_id, user_agent, scope, warn_on_readonly=True)
Get a Storage instance for a credential.
source code
 
get_credential_storage_custom_string_key(filename, key_string, warn_on_readonly=True)
Get a Storage instance for a credential using a single string as a key.
source code
 
get_credential_storage_custom_key(filename, key_dict, warn_on_readonly=True)
Get a Storage instance for a credential using a dictionary as a key.
source code
 
get_all_credential_keys(filename, warn_on_readonly=True)
Gets all the registered credential keys in the given Multistore.
source code
 
_get_multistore(filename, warn_on_readonly=True)
A helper method to initialize the multistore with proper locking.
source code
Variables [hide private]
  logger = logging.getLogger(__name__)
  _multistores = {}
  _multistores_lock = threading.Lock()
Function Details [hide private]

get_credential_storage(filename, client_id, user_agent, scope, warn_on_readonly=True)

source code 
Get a Storage instance for a credential.

Args:
  filename: The JSON file storing a set of credentials
  client_id: The client_id for the credential
  user_agent: The user agent for the credential
  scope: string or iterable of strings, Scope(s) being requested
  warn_on_readonly: if True, log a warning if the store is readonly

Returns:
  An object derived from client.Storage for getting/setting the
  credential.

Decorators:
  • @util.positional(4)

get_credential_storage_custom_string_key(filename, key_string, warn_on_readonly=True)

source code 
Get a Storage instance for a credential using a single string as a key.

Allows you to provide a string as a custom key that will be used for
credential storage and retrieval.

Args:
  filename: The JSON file storing a set of credentials
  key_string: A string to use as the key for storing this credential.
  warn_on_readonly: if True, log a warning if the store is readonly

Returns:
  An object derived from client.Storage for getting/setting the
  credential.

Decorators:
  • @util.positional(2)

get_credential_storage_custom_key(filename, key_dict, warn_on_readonly=True)

source code 
Get a Storage instance for a credential using a dictionary as a key.

Allows you to provide a dictionary as a custom key that will be used for
credential storage and retrieval.

Args:
  filename: The JSON file storing a set of credentials
  key_dict: A dictionary to use as the key for storing this credential. There
    is no ordering of the keys in the dictionary. Logically equivalent
    dictionaries will produce equivalent storage keys.
  warn_on_readonly: if True, log a warning if the store is readonly

Returns:
  An object derived from client.Storage for getting/setting the
  credential.

Decorators:
  • @util.positional(2)

get_all_credential_keys(filename, warn_on_readonly=True)

source code 
Gets all the registered credential keys in the given Multistore.

Args:
  filename: The JSON file storing a set of credentials
  warn_on_readonly: if True, log a warning if the store is readonly

Returns:
  A list of the credential keys present in the file.  They are returned as
  dictionaries that can be passed into get_credential_storage_custom_key to
  get the actual credentials.

Decorators:
  • @util.positional(1)

_get_multistore(filename, warn_on_readonly=True)

source code 
A helper method to initialize the multistore with proper locking.

Args:
  filename: The JSON file storing a set of credentials
  warn_on_readonly: if True, log a warning if the store is readonly

Returns:
  A multistore object

Decorators:
  • @util.positional(1)