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