Beispiel #1
0
  def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials

    Raises:
      CredentialsFileSymbolicLinkError if the file is a symbolic link.
    """
    credentials = None
    self._validate_file()
    try:
      f = open(self._filename, 'rb')
      content = f.read()
      f.close()
    except IOError:
      return credentials

    try:
      credentials = Credentials.new_from_json(content)
      credentials.set_store(self)
    except ValueError:
      pass

    return credentials
Beispiel #2
0
  def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    try:
      f = open(self._filename, 'r')
      content = f.read()
      f.close()
    except IOError:
      return credentials

    # First try reading as JSON, and if that fails fall back to pickle.
    try:
      credentials = Credentials.new_from_json(content)
      credentials.set_store(self)
    except ValueError:
      # TODO(jcgregorio) On a future release remove this path to finally remove
      # all pickle support.
      try:
        credentials = pickle.loads(content)
        credentials.set_store(self)
      except:
        pass

    return credentials
Beispiel #3
0
    def locked_get(self):
        """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
        credentials = None
        try:
            f = open(self._filename, 'r')
            content = f.read()
            f.close()
        except IOError:
            return credentials

        # First try reading as JSON, and if that fails fall back to pickle.
        try:
            credentials = Credentials.new_from_json(content)
            credentials.set_store(self)
        except ValueError:
            # TODO(jcgregorio) On a future release remove this path to finally remove
            # all pickle support.
            try:
                credentials = pickle.loads(content)
                credentials.set_store(self)
            except:
                pass

        return credentials
Beispiel #4
0
 def make_value_from_datastore(self, value):
   if value is None:
     return None
   if len(value) == 0:
     return None
   try:
     credentials = Credentials.new_from_json(value)
   except ValueError:
     credentials = None
   return credentials
Beispiel #5
0
 def make_value_from_datastore(self, value):
     logging.info("make: Got type " + str(type(value)))
     if value is None:
         return None
     if len(value) == 0:
         return None
     try:
         credentials = Credentials.new_from_json(value)
     except ValueError:
         credentials = None
     return credentials
 def make_value_from_datastore(self, value):
   logging.info("make: Got type " + str(type(value)))
   if value is None:
     return None
   if len(value) == 0:
     return None
   try:
     credentials = Credentials.new_from_json(value)
   except ValueError:
     credentials = None
   return credentials
  def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials
    def locked_get(self):
        """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials
Beispiel #9
0
    def locked_get(self):
        """Retrieve Credential from datastore.

    Returns:
      oauth2client.Credentials
    """
        if self._cache:
            json = self._cache.get(self._key_name)
            if json:
                return Credentials.new_from_json(json)
        entity = self._model.get_or_insert(self._key_name)
        credential = getattr(entity, self._property_name)
        if credential and hasattr(credential, 'set_store'):
            credential.set_store(self)
            if self._cache:
                self._cache.set(self._key_name, credentials.to_json())

        return credential
Beispiel #10
0
  def _decode_credential_from_json(self, cred_entry):
    """Load a credential from our JSON serialization.

    Args:
      cred_entry: A dict entry from the data member of our format

    Returns:
      (key, cred) where the key is the key tuple and the cred is the
        OAuth2Credential object.
    """
    raw_key = cred_entry['key']
    client_id = raw_key['clientId']
    user_agent = raw_key['userAgent']
    scope = raw_key['scope']
    key = (client_id, user_agent, scope)
    credential = None
    credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
    return (key, credential)
Beispiel #11
0
  def locked_get(self):
    """Retrieve Credential from datastore.

    Returns:
      oauth2client.Credentials
    """
    if self._cache:
      json = self._cache.get(self._key_name)
      if json:
        return Credentials.new_from_json(json)
    entity = self._model.get_or_insert(self._key_name)
    credential = getattr(entity, self._property_name)
    if credential and hasattr(credential, 'set_store'):
      credential.set_store(self)
      if self._cache:
        self._cache.set(self._key_name, credentials.to_json())

    return credential
Beispiel #12
0
  def _decode_credential_from_json(self, cred_entry):
    """Load a credential from our JSON serialization.

    Args:
      cred_entry: A dict entry from the data member of our format

    Returns:
      (key, cred) where the key is the key tuple and the cred is the
        OAuth2Credential object.
    """
    raw_key = cred_entry['key']
    client_id = raw_key['clientId']
    user_agent = raw_key['userAgent']
    scope = raw_key['scope']
    key = (client_id, user_agent, scope)
    credential = None
    credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
    return (key, credential)
Beispiel #13
0
    def locked_get(self):
        """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
        credentials = None
        try:
            f = open(self._filename, 'rb')
            content = f.read()
            f.close()
        except IOError:
            return credentials

        try:
            credentials = Credentials.new_from_json(content)
            credentials.set_store(self)
        except ValueError:
            pass

        return credentials
Beispiel #14
0
  def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    try:
      f = open(self._filename, 'r')
      content = f.read()
      f.close()
    except IOError:
      return credentials

    try:
      credentials = Credentials.new_from_json(content)
      credentials.set_store(self)
    except ValueError:
      pass

    return credentials