当前位置: 首页>>代码示例>>Python>>正文


Python Credentials.new_from_json方法代码示例

本文整理汇总了Python中oauth2client.client.Credentials.new_from_json方法的典型用法代码示例。如果您正苦于以下问题:Python Credentials.new_from_json方法的具体用法?Python Credentials.new_from_json怎么用?Python Credentials.new_from_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth2client.client.Credentials的用法示例。


在下文中一共展示了Credentials.new_from_json方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_gcloud_oauth2_creds

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def get_gcloud_oauth2_creds():
  gcfp = '~/.config/gcloud/credentials'
  credfn = os.path.expanduser(gcfp)
  if not os.path.exists(credfn):
    credfn = os.path.expanduser('~/.config/gcloud/legacy_credentials')
    if os.path.exists(credfn):
      cdirs = os.listdir(credfn)
      if cdirs:
        credfn = "%s/%s/multistore.json" % (credfn, cdirs[0])	# just take the first one for now

  if not os.path.exists(credfn):
    msg = "[edx2bigquery] Authentication error!  You have specified USE_GCLOUD_AUTH in the configuration, but do not have gcloud authentication available.\n"
    msg += "              Please authenticate using 'gcloud auth login' before running this."
    msg += "              Missing file %s" % credfn
    print msg
    raise Exception(msg)
    
  gcloud_cred = json.loads(open(credfn).read())['data'][0]['credential']
  credentials = Credentials.new_from_json(json.dumps(gcloud_cred))
  return credentials 
开发者ID:mitodl,项目名称:edx2bigquery,代码行数:22,代码来源:auth.py

示例2: _from_base_type

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def _from_base_type(self, value):
      """Converts our stored JSON string back to the desired type.

      Args:
        value: A value from the datastore to be converted to the desired type.

      Returns:
        A deserialized Credentials (or subclass) object, else None if the
            value can't be parsed.
      """
      if not value:
        return None
      try:
        # Uses the from_json method of the implied class of value
        credentials = Credentials.new_from_json(value)
      except ValueError:
        credentials = None
      return credentials 
开发者ID:mortcanty,项目名称:earthengine,代码行数:20,代码来源:appengine.py

示例3: locked_get

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
    """Retrieve Credential from datastore.

    Returns:
      oauth2client.Credentials
    """
    credentials = None
    if self._cache:
      json = self._cache.get(self._key_name)
      if json:
        credentials = Credentials.new_from_json(json)
    if credentials is None:
      entity = self._get_entity()
      if entity is not None:
        credentials = getattr(entity, self._property_name)
        if self._cache:
          self._cache.set(self._key_name, credentials.to_json())

    if credentials and hasattr(credentials, 'set_store'):
      credentials.set_store(self)
    return credentials 
开发者ID:mortcanty,项目名称:earthengine,代码行数:23,代码来源:appengine.py

示例4: locked_get

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
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 
开发者ID:mortcanty,项目名称:earthengine,代码行数:19,代码来源:keyring_storage.py

示例5: locked_get

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
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 
开发者ID:mortcanty,项目名称:earthengine,代码行数:27,代码来源:file.py

示例6: locked_get

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
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 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:27,代码来源:file.py

示例7: locked_get

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
        """Retrieve Credential from datastore.

        Returns:
            oauth2client.Credentials
        """
        credentials = None
        if self._cache:
            json = self._cache.get(self._key_name)
            if json:
                credentials = Credentials.new_from_json(json)
        if credentials is None:
            entity = self._get_entity()
            if entity is not None:
                credentials = getattr(entity, self._property_name)
                if self._cache:
                    self._cache.set(self._key_name, credentials.to_json())

        if credentials and hasattr(credentials, 'set_store'):
            credentials.set_store(self)
        return credentials 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:23,代码来源:appengine.py

示例8: locked_get

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
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 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:19,代码来源:keyring_storage.py

示例9: _decode_credential_from_json

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
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']
        key = _dict_to_tuple_key(raw_key)
        credential = None
        credential = Credentials.new_from_json(
            json.dumps(cred_entry['credential']))
        return (key, credential) 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:18,代码来源:multistore_file.py

示例10: _from_base_type

# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def _from_base_type(self, value):
            """Converts our stored JSON string back to the desired type.

            Args:
                value: A value from the datastore to be converted to the
                       desired type.

            Returns:
                A deserialized Credentials (or subclass) object, else None if
                the value can't be parsed.
            """
            if not value:
                return None
            try:
                # Uses the from_json method of the implied class of value
                credentials = Credentials.new_from_json(value)
            except ValueError:
                credentials = None
            return credentials 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:appengine.py


注:本文中的oauth2client.client.Credentials.new_from_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。