Python oauth2client.client.Storage() Examples

The following are 30 code examples of oauth2client.client.Storage(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oauth2client.client , or try the search function .
Example #1
Source File: appengine.py    From earthengine with MIT License 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #2
Source File: appengine.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #3
Source File: appengine.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #4
Source File: appengine.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #5
Source File: appengine.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #6
Source File: appengine.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache 
Example #7
Source File: storage.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve stored credential from the Django ORM.

        Returns:
            oauth2client.Credentials retrieved from the Django ORM, associated
             with the ``model``, ``key_value``->``key_name`` pair used to query
             for the model, and ``property_name`` identifying the
             ``CredentialsProperty`` field, all of which are defined in the
             constructor for this Storage object.

        """
        query = {self.key_name: self.key_value}
        entities = self.model_class.objects.filter(**query)
        if len(entities) > 0:
            credential = getattr(entities[0], self.property_name)
            if getattr(credential, 'set_store', None) is not None:
                credential.set_store(self)
            return credential
        else:
            return None 
Example #8
Source File: storage.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, model_class, key_name, key_value, property_name):
        """Constructor for Storage.

        Args:
            model: string, fully qualified name of db.Model model class.
            key_name: string, key name for the entity that has the credentials
            key_value: string, key value for the entity that has the
               credentials.
            property_name: string, name of the property that is an
                           CredentialsProperty.
        """
        super(DjangoORMStorage, self).__init__()
        self.model_class = model_class
        self.key_name = key_name
        self.key_value = key_value
        self.property_name = property_name 
Example #9
Source File: appengine.py    From twitter-for-bigquery with Apache License 2.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #10
Source File: multistore_file.py    From alfred-gmail with MIT License 6 votes vote down vote up
def 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.

    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.
    """
    multistore = _get_multistore(filename, warn_on_readonly=warn_on_readonly)
    key = _dict_to_tuple_key(key_dict)
    return multistore._get_storage(key) 
Example #11
Source File: multistore_file.py    From alfred-gmail with MIT License 6 votes vote down vote up
def 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.

    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.
    """
    # Create a key dictionary that can be used
    key_dict = {'key': key_string}
    return get_credential_storage_custom_key(
        filename, key_dict, warn_on_readonly=warn_on_readonly) 
Example #12
Source File: multistore_file.py    From alfred-gmail with MIT License 6 votes vote down vote up
def get_credential_storage(filename, client_id, user_agent, scope,
                           warn_on_readonly=True):
    """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.
    """
    # Recreate the legacy key with these specific parameters
    key = {'clientId': client_id, 'userAgent': user_agent,
           'scope': util.scopes_to_string(scope)}
    return get_credential_storage_custom_key(
        filename, key, warn_on_readonly=warn_on_readonly) 
Example #13
Source File: storage.py    From alfred-gmail with MIT License 6 votes vote down vote up
def locked_get(self):
        """Retrieve stored credential from the Django ORM.

        Returns:
            oauth2client.Credentials retrieved from the Django ORM, associated
             with the ``model``, ``key_value``->``key_name`` pair used to query
             for the model, and ``property_name`` identifying the
             ``CredentialsProperty`` field, all of which are defined in the
             constructor for this Storage object.

        """
        query = {self.key_name: self.key_value}
        entities = self.model_class.objects.filter(**query)
        if len(entities) > 0:
            credential = getattr(entities[0], self.property_name)
            if getattr(credential, 'set_store', None) is not None:
                credential.set_store(self)
            return credential
        else:
            return None 
Example #14
Source File: storage.py    From alfred-gmail with MIT License 6 votes vote down vote up
def __init__(self, model_class, key_name, key_value, property_name):
        """Constructor for Storage.

        Args:
            model: string, fully qualified name of db.Model model class.
            key_name: string, key name for the entity that has the credentials
            key_value: string, key value for the entity that has the
               credentials.
            property_name: string, name of the property that is an
                           CredentialsProperty.
        """
        super(DjangoORMStorage, self).__init__()
        self.model_class = model_class
        self.key_name = key_name
        self.key_value = key_value
        self.property_name = property_name 
Example #15
Source File: appengine.py    From splunk-ref-pas-code with Apache License 2.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #16
Source File: appengine.py    From sndlatr with Apache License 2.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #17
Source File: appengine.py    From billing-export-python with Apache License 2.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #18
Source File: sqlalchemy.py    From aqua-monitor with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self, session, model_class, key_name,
                 key_value, property_name):
        """Constructor for Storage.

        Args:
            session: An instance of :class:`sqlalchemy.orm.Session`.
            model_class: SQLAlchemy declarative mapping.
            key_name: string, key name for the entity that has the credentials
            key_value: key value for the entity that has the credentials
            property_name: A string indicating which property on the
                           ``model_class`` to store the credentials.
                           This property must be a
                           :class:`CredentialsType` column.
        """
        super(Storage, self).__init__()

        self.session = session
        self.model_class = model_class
        self.key_name = key_name
        self.key_value = key_value
        self.property_name = property_name 
Example #19
Source File: appengine.py    From googleapps-message-recall with Apache License 2.0 6 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache 
Example #20
Source File: appengine.py    From alfred-gmail with MIT License 5 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        super(StorageByKeyName, self).__init__()

        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache 
Example #21
Source File: flask_util.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def init_app(self, app, scopes=None, client_secrets_file=None,
                 client_id=None, client_secret=None, authorize_callback=None,
                 storage=None, **kwargs):
        """Initialize this extension for the given app.

        Arguments:
            app: A Flask application.
            scopes: Optional list of scopes to authorize.
            client_secrets_file: Path to a file containing client secrets. You
                can also specify the GOOGLE_OAUTH2_CLIENT_SECRETS_JSON config value.
            client_id: If not specifying a client secrets file, specify the
                OAuth2 client id. You can also specify the
                GOOGLE_OAUTH2_CLIENT_ID config value. You must also provide a
                client secret.
            client_secret: The OAuth2 client secret. You can also specify the
                GOOGLE_OAUTH2_CLIENT_SECRET config value.
            authorize_callback: A function that is executed after successful
                user authorization.
            storage: A oauth2client.client.Storage subclass for storing the
                credentials. By default, this is a Flask session based storage.
            kwargs: Any additional args are passed along to the Flow
                constructor.
        """
        self.app = app
        self.authorize_callback = authorize_callback
        self.flow_kwargs = kwargs

        if storage is None:
            storage = FlaskSessionStorage()
        self.storage = storage

        if scopes is None:
            scopes = app.config.get('GOOGLE_OAUTH2_SCOPES', _DEFAULT_SCOPES)
        self.scopes = scopes

        self._load_config(client_secrets_file, client_id, client_secret)

        app.register_blueprint(self._create_blueprint()) 
Example #22
Source File: flask_util.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def init_app(self, app, scopes=None, client_secrets_file=None,
                 client_id=None, client_secret=None, authorize_callback=None,
                 storage=None, **kwargs):
        """Initialize this extension for the given app.

        Arguments:
            app: A Flask application.
            scopes: Optional list of scopes to authorize.
            client_secrets_file: Path to a file containing client secrets. You
                can also specify the GOOGLE_OAUTH2_CLIENT_SECRETS_JSON config value.
            client_id: If not specifying a client secrets file, specify the
                OAuth2 client id. You can also specify the
                GOOGLE_OAUTH2_CLIENT_ID config value. You must also provide a
                client secret.
            client_secret: The OAuth2 client secret. You can also specify the
                GOOGLE_OAUTH2_CLIENT_SECRET config value.
            authorize_callback: A function that is executed after successful
                user authorization.
            storage: A oauth2client.client.Storage subclass for storing the
                credentials. By default, this is a Flask session based storage.
            kwargs: Any additional args are passed along to the Flow
                constructor.
        """
        self.app = app
        self.authorize_callback = authorize_callback
        self.flow_kwargs = kwargs

        if storage is None:
            storage = FlaskSessionStorage()
        self.storage = storage

        if scopes is None:
            scopes = app.config.get('GOOGLE_OAUTH2_SCOPES', _DEFAULT_SCOPES)
        self.scopes = scopes

        self._load_config(client_secrets_file, client_id, client_secret)

        app.register_blueprint(self._create_blueprint()) 
Example #23
Source File: appengine.py    From aqua-monitor with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        super(StorageByKeyName, self).__init__()

        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache 
Example #24
Source File: keyring_storage.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, service_name, user_name):
        """Constructor.

        Args:
            service_name: string, The name of the service under which the
                          credentials are stored.
            user_name: string, The name of the user to store credentials for.
        """
        super(Storage, self).__init__(lock=threading.Lock())
        self._service_name = service_name
        self._user_name = user_name 
Example #25
Source File: appengine.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        super(StorageByKeyName, self).__init__()

        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache 
Example #26
Source File: file.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, filename):
        super(Storage, self).__init__(lock=threading.Lock())
        self._filename = filename 
Example #27
Source File: file.py    From alfred-gmail with MIT License 5 votes vote down vote up
def __init__(self, filename):
        super(Storage, self).__init__(lock=threading.Lock())
        self._filename = filename 
Example #28
Source File: appengine.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        super(StorageByKeyName, self).__init__()

        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache 
Example #29
Source File: appengine.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        super(StorageByKeyName, self).__init__()

        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache 
Example #30
Source File: appengine.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        super(StorageByKeyName, self).__init__()

        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache