当前位置: 首页>>代码示例>>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;未经允许,请勿转载。