當前位置: 首頁>>代碼示例>>Python>>正文


Python environment_vars.CLOUD_SDK_CONFIG_DIR屬性代碼示例

本文整理匯總了Python中google.auth.environment_vars.CLOUD_SDK_CONFIG_DIR屬性的典型用法代碼示例。如果您正苦於以下問題:Python environment_vars.CLOUD_SDK_CONFIG_DIR屬性的具體用法?Python environment_vars.CLOUD_SDK_CONFIG_DIR怎麽用?Python environment_vars.CLOUD_SDK_CONFIG_DIR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在google.auth.environment_vars的用法示例。


在下文中一共展示了environment_vars.CLOUD_SDK_CONFIG_DIR屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: provide_gcp_context

# 需要導入模塊: from google.auth import environment_vars [as 別名]
# 或者: from google.auth.environment_vars import CLOUD_SDK_CONFIG_DIR [as 別名]
def provide_gcp_context(
    key_file_path: Optional[str] = None,
    scopes: Optional[Sequence] = None,
    project_id: Optional[str] = None,
):
    """
    Context manager that provides:

    - GCP credentials for application supporting `Application Default Credentials (ADC)
    strategy <https://cloud.google.com/docs/authentication/production>`__.
    - temporary value of :envvar:`AIRFLOW_CONN_GOOGLE_CLOUD_DEFAULT` variable
    - the ``gcloud`` config directory isolated from user configuration

    Moreover it resolves full path to service keys so user can pass ``myservice.json``
    as ``key_file_path``.

    :param key_file_path: Path to file with GCP credentials .json file.
    :type key_file_path: str
    :param scopes: OAuth scopes for the connection
    :type scopes: Sequence
    :param project_id: The id of GCP project for the connection.
    :type project_id: str
    """
    key_file_path = resolve_full_gcp_key_path(key_file_path)  # type: ignore
    with provide_gcp_conn_and_credentials(key_file_path, scopes, project_id), \
            tempfile.TemporaryDirectory() as gcloud_config_tmp, \
            mock.patch.dict('os.environ', {CLOUD_SDK_CONFIG_DIR: gcloud_config_tmp}):
        executor = get_executor()

        if project_id:
            executor.execute_cmd([
                "gcloud", "config", "set", "core/project", project_id
            ])
        if key_file_path:
            executor.execute_cmd([
                "gcloud", "auth", "activate-service-account", f"--key-file={key_file_path}",
            ])
        yield 
開發者ID:apache,項目名稱:airflow,代碼行數:40,代碼來源:gcp_system_helpers.py

示例2: test_get_config_path_env_var

# 需要導入模塊: from google.auth import environment_vars [as 別名]
# 或者: from google.auth.environment_vars import CLOUD_SDK_CONFIG_DIR [as 別名]
def test_get_config_path_env_var(monkeypatch):
    config_path_sentinel = "config_path"
    monkeypatch.setenv(environment_vars.CLOUD_SDK_CONFIG_DIR, config_path_sentinel)
    config_path = _cloud_sdk.get_config_path()
    assert config_path == config_path_sentinel 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:7,代碼來源:test__cloud_sdk.py

示例3: get_config_path

# 需要導入模塊: from google.auth import environment_vars [as 別名]
# 或者: from google.auth.environment_vars import CLOUD_SDK_CONFIG_DIR [as 別名]
def get_config_path():
    """Returns the absolute path the the Cloud SDK's configuration directory.

    Returns:
        str: The Cloud SDK config path.
    """
    # If the path is explicitly set, return that.
    try:
        return os.environ[environment_vars.CLOUD_SDK_CONFIG_DIR]
    except KeyError:
        pass

    # Non-windows systems store this at ~/.config/gcloud
    if os.name != "nt":
        return os.path.join(os.path.expanduser("~"), ".config", _CONFIG_DIRECTORY)
    # Windows systems store config at %APPDATA%\gcloud
    else:
        try:
            return os.path.join(
                os.environ[_WINDOWS_CONFIG_ROOT_ENV_VAR], _CONFIG_DIRECTORY
            )
        except KeyError:
            # This should never happen unless someone is really
            # messing with things, but we'll cover the case anyway.
            drive = os.environ.get("SystemDrive", "C:")
            return os.path.join(drive, "\\", _CONFIG_DIRECTORY) 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:28,代碼來源:_cloud_sdk.py

示例4: get_config_path

# 需要導入模塊: from google.auth import environment_vars [as 別名]
# 或者: from google.auth.environment_vars import CLOUD_SDK_CONFIG_DIR [as 別名]
def get_config_path():
    """Returns the absolute path the the Cloud SDK's configuration directory.

    Returns:
        str: The Cloud SDK config path.
    """
    # If the path is explicitly set, return that.
    try:
        return os.environ[environment_vars.CLOUD_SDK_CONFIG_DIR]
    except KeyError:
        pass

    # Non-windows systems store this at ~/.config/gcloud
    if os.name != 'nt':
        return os.path.join(
            os.path.expanduser('~'), '.config', _CONFIG_DIRECTORY)
    # Windows systems store config at %APPDATA%\gcloud
    else:
        try:
            return os.path.join(
                os.environ[_WINDOWS_CONFIG_ROOT_ENV_VAR],
                _CONFIG_DIRECTORY)
        except KeyError:
            # This should never happen unless someone is really
            # messing with things, but we'll cover the case anyway.
            drive = os.environ.get('SystemDrive', 'C:')
            return os.path.join(
                drive, '\\', _CONFIG_DIRECTORY) 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:30,代碼來源:_cloud_sdk.py


注:本文中的google.auth.environment_vars.CLOUD_SDK_CONFIG_DIR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。