本文整理汇总了Python中google.auth.environment_vars.LEGACY_PROJECT属性的典型用法代码示例。如果您正苦于以下问题:Python environment_vars.LEGACY_PROJECT属性的具体用法?Python environment_vars.LEGACY_PROJECT怎么用?Python environment_vars.LEGACY_PROJECT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类google.auth.environment_vars
的用法示例。
在下文中一共展示了environment_vars.LEGACY_PROJECT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: provide_gcp_conn_and_credentials
# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import LEGACY_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
示例2: test_default_explict_legacy_project_id
# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import LEGACY_PROJECT [as 别名]
def test_default_explict_legacy_project_id(unused_get, monkeypatch):
monkeypatch.setenv(environment_vars.LEGACY_PROJECT, "explicit-env")
assert _default.default() == (mock.sentinel.credentials, "explicit-env")