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


Python environment_vars.PROJECT属性代码示例

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


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

示例1: _get_gcloud_sdk_credentials

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import PROJECT [as 别名]
def _get_gcloud_sdk_credentials():
    """Gets the credentials and project ID from the Cloud SDK."""
    from google.auth import _cloud_sdk

    # Check if application default credentials exist.
    credentials_filename = (
        _cloud_sdk.get_application_default_credentials_path())

    if not os.path.isfile(credentials_filename):
        return None, None

    credentials, project_id = _load_credentials_from_file(
        credentials_filename)

    if not project_id:
        project_id = _cloud_sdk.get_project_id()

    if not project_id:
        _LOGGER.warning(
            'No project ID could be determined from the Cloud SDK '
            'configuration. Consider running `gcloud config set project` or '
            'setting the %s environment variable', environment_vars.PROJECT)

    return credentials, project_id 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:26,代码来源:_default.py

示例2: _get_explicit_environ_credentials

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import PROJECT [as 别名]
def _get_explicit_environ_credentials():
    """Gets credentials from the GOOGLE_APPLICATION_CREDENTIALS environment
    variable."""
    explicit_file = os.environ.get(environment_vars.CREDENTIALS)

    if explicit_file is not None:
        credentials, project_id = _load_credentials_from_file(
            os.environ[environment_vars.CREDENTIALS])

        if not project_id:
            _LOGGER.warning(
                'No project ID could be determined from the credentials at %s '
                'Consider setting the %s environment variable',
                environment_vars.CREDENTIALS, environment_vars.PROJECT)

        return credentials, project_id

    else:
        return None, None 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:21,代码来源:_default.py

示例3: provide_gcp_conn_and_credentials

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import PROJECT [as 别名]
def provide_gcp_conn_and_credentials(
    key_file_path: Optional[str] = None,
    scopes: Optional[Sequence] = None,
    project_id: Optional[str] = None,
):
    """
    Context manager that provides both:

    - 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` connection

    :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
    """
    with ExitStack() as stack:
        if key_file_path:
            stack.enter_context(  # type; ignore  # pylint: disable=no-member
                provide_gcp_credentials(key_file_path)
            )
        if project_id:
            stack.enter_context(  # type; ignore  # pylint: disable=no-member
                patch_environ({PROJECT: project_id, LEGACY_PROJECT: project_id})
            )

        stack.enter_context(  # type; ignore  # pylint: disable=no-member
            provide_gcp_connection(key_file_path, scopes, project_id)
        )
        yield 
开发者ID:apache,项目名称:airflow,代码行数:35,代码来源:credentials_provider.py

示例4: test_default_explict_project_id

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import PROJECT [as 别名]
def test_default_explict_project_id(unused_get, monkeypatch):
    monkeypatch.setenv(environment_vars.PROJECT, "explicit-env")
    assert _default.default() == (mock.sentinel.credentials, "explicit-env") 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:5,代码来源:test__default.py

示例5: _get_gce_credentials

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import PROJECT [as 别名]
def _get_gce_credentials(request=None):
    """Gets credentials and project ID from the GCE Metadata Service."""
    # Ping requires a transport, but we want application default credentials
    # to require no arguments. So, we'll use the _http_client transport which
    # uses http.client. This is only acceptable because the metadata server
    # doesn't do SSL and never requires proxies.
    from google.auth import compute_engine
    from google.auth.compute_engine import _metadata

    if request is None:
        request = google.auth.transport._http_client.Request()

    if _metadata.ping(request=request):
        # Get the project ID.
        try:
            project_id = _metadata.get_project_id(request=request)
        except exceptions.TransportError:
            _LOGGER.warning(
                'No project ID could be determined from the Compute Engine '
                'metadata service. Consider setting the %s environment '
                'variable.', environment_vars.PROJECT)
            project_id = None

        return compute_engine.Credentials(), project_id
    else:
        return None, None 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:28,代码来源:_default.py

示例6: init_bigquery

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import PROJECT [as 别名]
def init_bigquery():
    from google.auth import environment_vars
    from google.cloud import bigquery

    is_proxy_token_set = "KAGGLE_DATA_PROXY_TOKEN" in os.environ
    is_user_secrets_token_set = "KAGGLE_USER_SECRETS_TOKEN" in os.environ
    if not (is_proxy_token_set or is_user_secrets_token_set):
        return bigquery

    # If this Notebook has bigquery integration on startup, preload the Kaggle Credentials
    # object for magics to work.
    if get_integrations().has_bigquery():
        from google.cloud.bigquery import magics
        magics.context.credentials = KaggleKernelCredentials()

    def monkeypatch_bq(bq_client, *args, **kwargs):
        from kaggle_gcp import get_integrations, PublicBigqueryClient, KaggleKernelCredentials
        specified_credentials = kwargs.get('credentials')
        has_bigquery = get_integrations().has_bigquery()
        # Prioritize passed in project id, but if it is missing look for env var.
        arg_project = kwargs.get('project')
        explicit_project_id = arg_project or os.environ.get(environment_vars.PROJECT)
        # This is a hack to get around the bug in google-cloud library.
        # Remove these two lines once this is resolved:
        # https://github.com/googleapis/google-cloud-python/issues/8108
        if explicit_project_id:
            Log.info(f"Explicit project set to {explicit_project_id}")
            kwargs['project'] = explicit_project_id
        if explicit_project_id is None and specified_credentials is None and not has_bigquery:
            msg = "Using Kaggle's public dataset BigQuery integration."
            Log.info(msg)
            print(msg)
            return PublicBigqueryClient(*args, **kwargs)
        else:
            if specified_credentials is None:
                Log.info("No credentials specified, using KaggleKernelCredentials.")
                kwargs['credentials'] = KaggleKernelCredentials()
                if (not has_bigquery):
                    Log.info("No bigquery integration found, creating client anyways.")
                    print('Please ensure you have selected a BigQuery '
                        'account in the Notebook Add-ons menu.')
            if explicit_project_id is None:
                Log.info("No project specified while using the unmodified client.")
                print('Please ensure you specify a project id when creating the client'
                    ' in order to use your BigQuery account.')
            kwargs['client_info'] = set_kaggle_user_agent(kwargs.get('client_info'))
            return bq_client(*args, **kwargs)

    # Monkey patches BigQuery client creation to use proxy or user-connected GCP account.
    # Deprecated in favor of Kaggle.DataProxyClient().
    # TODO: Remove this once uses have migrated to that new interface.
    bq_client = bigquery.Client
    if (not has_been_monkeypatched(bigquery.Client)):
        bigquery.Client = lambda *args, **kwargs:  monkeypatch_bq(
            bq_client, *args, **kwargs)
    return bigquery 
开发者ID:Kaggle,项目名称:docker-python,代码行数:58,代码来源:kaggle_gcp.py


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