當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。