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


Python Credentials.from_service_account_file方法代码示例

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


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

示例1: _credentials_storage_service

# 需要导入模块: from google.oauth2.service_account import Credentials [as 别名]
# 或者: from google.oauth2.service_account.Credentials import from_service_account_file [as 别名]
def _credentials_storage_service():

  if RE_CREDENTIALS_JSON.match(UI_SERVICE):
    credentials = Credentials.from_service_account_info(json.loads(UI_SERVICE))
  else:
    credentials = Credentials.from_service_account_file(UI_SERVICE)

  return discovery.build('storage', 'v1', credentials=credentials) 
开发者ID:google,项目名称:starthinker,代码行数:10,代码来源:storage.py

示例2: CredentialsServiceWrapper

# 需要导入模块: from google.oauth2.service_account import Credentials [as 别名]
# 或者: from google.oauth2.service_account.Credentials import from_service_account_file [as 别名]
def CredentialsServiceWrapper(service):
  if isinstance(service, dict):
    return CredentialsService.from_service_account_info(service)
  elif RE_CREDENTIALS_JSON.match(service):
    return CredentialsService.from_service_account_info(json.loads(service))
  else:
    return CredentialsService.from_service_account_file(service) 
开发者ID:google,项目名称:starthinker,代码行数:9,代码来源:wrapper.py

示例3: _load_oauth_credentials

# 需要导入模块: from google.oauth2.service_account import Credentials [as 别名]
# 或者: from google.oauth2.service_account.Credentials import from_service_account_file [as 别名]
def _load_oauth_credentials(self):
        json_str = os.environ.get(self.gcs_credential_name)
        if not json_str:
            return None

        if os.path.isfile(json_str):
            return Credentials.from_service_account_file(json_str)

        return Credentials.from_service_account_info(json.loads(json_str)) 
开发者ID:m3dev,项目名称:gokart,代码行数:11,代码来源:gcs_config.py

示例4: get_gc_credentials

# 需要导入模块: from google.oauth2.service_account import Credentials [as 别名]
# 或者: from google.oauth2.service_account.Credentials import from_service_account_file [as 别名]
def get_gc_credentials(key_path=None, keyfile_dict=None, scopes=None):
    """
    Returns the Credentials object for Google API
    """
    key_path = key_path or get_key_path()
    keyfile_dict = keyfile_dict or get_keyfile_dict()
    scopes = scopes or get_scopes()

    if scopes is not None:
        scopes = [s.strip() for s in scopes.split(',')]
    else:
        scopes = DEFAULT_SCOPES

    if not key_path and not keyfile_dict:
        logger.info('Getting connection using `google.auth.default()` '
                    'since no key file is defined for hook.')
        credentials, _ = google.auth.default(scopes=scopes)
    elif key_path:
        # Get credentials from a JSON file.
        if key_path.endswith('.json'):
            logger.info('Getting connection using a JSON key file.')
            credentials = Credentials.from_service_account_file(
                os.path.abspath(key_path), scopes=scopes)
        else:
            raise PolyaxonStoresException('Unrecognised extension for key file.')
    else:
        # Get credentials from JSON data.
        try:
            if not isinstance(keyfile_dict, Mapping):
                keyfile_dict = json.loads(keyfile_dict)

            # Convert escaped newlines to actual newlines if any.
            keyfile_dict['private_key'] = keyfile_dict['private_key'].replace('\\n', '\n')

            credentials = Credentials.from_service_account_info(keyfile_dict, scopes=scopes)
        except ValueError:  # json.decoder.JSONDecodeError does not exist on py2
            raise PolyaxonStoresException('Invalid key JSON.')

    return credentials 
开发者ID:polyaxon,项目名称:polystores,代码行数:41,代码来源:gc_client.py

示例5: get_service_account_credentials

# 需要导入模块: from google.oauth2.service_account import Credentials [as 别名]
# 或者: from google.oauth2.service_account.Credentials import from_service_account_file [as 别名]
def get_service_account_credentials(path_to_private_key_file, subject,
                                    scopes=_SERVICE_ACCOUNT_SCOPES):
    """Creates and returns an instance of oauth2.service_account.Credentials.

    Args:
        path_to_private_key_file: A str of the path to the private key file
            location.
        subject: A str of the email address of the delegated account.
        scopes: A list of additional scopes.

    Returns:
        An instance of oauth2.credentials.Credentials
    """
    return ServiceAccountCreds.from_service_account_file(
        path_to_private_key_file, subject=subject, scopes=scopes) 
开发者ID:googleads,项目名称:google-ads-python,代码行数:17,代码来源:oauth2.py

示例6: clone

# 需要导入模块: from google.oauth2.service_account import Credentials [as 别名]
# 或者: from google.oauth2.service_account.Credentials import from_service_account_file [as 别名]
def clone(self):
        accounts = glob(self.path + '/*.json')
        if len(accounts) < 2:
            raise ValueError('The path provided (%s) has 1 or no accounts.' % self.path)

        check = build('drive','v3',credentials=Credentials.from_service_account_file(accounts[0]))

        try:
            root_dir = check.files().get(fileId=self.source,supportsAllDrives=True).execute()['name']
        except HttpError:
            raise ValueError('Source folder %s cannot be read or is invalid.' % self.source)

        dest_dict = {i:'' for i in self.dest}
        for key in list(dest_dict.keys()):
            try:
                dest_dir = check.files().get(fileId=key,supportsAllDrives=True).execute()['name']
                dest_dict[key] = dest_dir
            except HttpError:
                if not self.skip_bad_dests:
                    raise ValueError('Destination folder %s cannot be read or is invalid.' % key)
                else:
                    dest_dict.pop(key)

        print('Creating %d Drive Services' % len(accounts))
        drive = []
        for account in accounts:
            credentials = Credentials.from_service_account_file(account, scopes=[
                'https://www.googleapis.com/auth/drive'
            ])
            drive.append(build('drive', 'v3', credentials=credentials))
        if self.thread_count is not None and self.thread_count <= len(drive):
            self.threads = threading.BoundedSemaphore(self.thread_count)
            print('BoundedSemaphore with %d threads' % self.thread_count)
        elif self.thread_count is None:
            self.threads = threading.BoundedSemaphore(len(drive))
            print('BoundedSemaphore with %d threads' % len(drive))
        else:
            raise ValueError('More threads than there is service accounts.')

        for i, dest_dir in dest_dict.items():
            print('Copying from %s to %s.' % (root_dir,dest_dir))
            self._rcopy(drive,1,self.source,i,root_dir,'',self.width) 
开发者ID:Spazzlo,项目名称:folderclone,代码行数:44,代码来源:multifolderclone.py

示例7: get_gc_credentials

# 需要导入模块: from google.oauth2.service_account import Credentials [as 别名]
# 或者: from google.oauth2.service_account.Credentials import from_service_account_file [as 别名]
def get_gc_credentials(
    key_path=None, keyfile_dict=None, scopes=None, context_path: Optional[str] = None
):
    """
    Returns the Credentials object for Google API
    """
    key_path = key_path or get_key_path(context_path=context_path)
    keyfile_dict = keyfile_dict or get_keyfile_dict(context_path=context_path)
    scopes = scopes or get_scopes(context_path=context_path)

    if scopes is not None:
        scopes = [s.strip() for s in scopes.split(",")]
    else:
        scopes = DEFAULT_SCOPES

    if not key_path and not keyfile_dict:
        # Look for default GC path
        if os.path.exists(CONTEXT_MOUNT_GC):
            key_path = CONTEXT_MOUNT_GC

    if not key_path and not keyfile_dict:
        logger.info(
            "Getting connection using `google.auth.default()` "
            "since no key file is defined for hook."
        )
        credentials, _ = google.auth.default(scopes=scopes)
    elif key_path:
        # Get credentials from a JSON file.
        if key_path.endswith(".json"):
            logger.info("Getting connection using a JSON key file.")
            credentials = Credentials.from_service_account_file(
                os.path.abspath(key_path), scopes=scopes
            )
        else:
            raise PolyaxonStoresException("Unrecognised extension for key file.")
    else:
        # Get credentials from JSON data.
        try:
            if not isinstance(keyfile_dict, Mapping):
                keyfile_dict = json.loads(keyfile_dict)

            # Convert escaped newlines to actual newlines if any.
            keyfile_dict["private_key"] = keyfile_dict["private_key"].replace(
                "\\n", "\n"
            )

            credentials = Credentials.from_service_account_info(
                keyfile_dict, scopes=scopes
            )
        except ValueError:  # json.decoder.JSONDecodeError does not exist on py2
            raise PolyaxonStoresException("Invalid key JSON.")

    return credentials 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:55,代码来源:base.py


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