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


Python environment_vars.CREDENTIALS属性代码示例

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


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

示例1: test_provide_gcp_credential_file_decorator_key_content

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_credential_file_decorator_key_content(self, mock_file):
        string_file = StringIO()
        file_content = '{"foo": "bar"}'
        file_name = '/test/mock-file'
        self.instance.extras = {
            'extra__google_cloud_platform__keyfile_dict': file_content
        }
        mock_file_handler = mock_file.return_value.__enter__.return_value
        mock_file_handler.name = file_name
        mock_file_handler.write = string_file.write

        @hook.GoogleBaseHook.provide_gcp_credential_file
        def assert_gcp_credential_file_in_env(hook_instance):  # pylint: disable=unused-argument
            self.assertEqual(os.environ[CREDENTIALS],
                             file_name)
            self.assertEqual(file_content, string_file.getvalue())

        assert_gcp_credential_file_in_env(self.instance) 
开发者ID:apache,项目名称:airflow,代码行数:20,代码来源:test_base_google.py

示例2: test_provide_authorized_gcloud_key_path_and_keyfile_dict

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_authorized_gcloud_key_path_and_keyfile_dict(
        self, mock_check_output, mock_default
    ):
        key_path = '/test/key-path'
        self.instance.extras = {
            'extra__google_cloud_platform__key_path': key_path,
            'extra__google_cloud_platform__keyfile_dict': '{"foo": "bar"}'
        }

        with self.assertRaisesRegex(
            AirflowException,
            'The `keyfile_dict` and `key_path` fields are mutually exclusive. '
            'Please provide only one value.'
        ):
            with self.instance.provide_authorized_gcloud():
                self.assertEqual(os.environ[CREDENTIALS], key_path) 
开发者ID:apache,项目名称:airflow,代码行数:18,代码来源:test_base_google.py

示例3: test_provide_authorized_gcloud_keyfile_dict

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_authorized_gcloud_keyfile_dict(self, mock_file, mock_check_output, mock_project_id):
        string_file = StringIO()
        file_content = '{"foo": "bar"}'
        file_name = '/test/mock-file'
        self.instance.extras = {'extra__google_cloud_platform__keyfile_dict': file_content}
        mock_file_handler = mock_file.return_value.__enter__.return_value
        mock_file_handler.name = file_name
        mock_file_handler.write = string_file.write

        with self.instance.provide_authorized_gcloud():
            self.assertEqual(os.environ[CREDENTIALS], file_name)

        mock_check_output.has_calls([
            mock.call(['gcloud', 'config', 'set', 'core/project', 'PROJECT_ID']),
            mock.call(['gcloud', 'auth', 'activate-service-account', '--key-file=/test/mock-file'])
        ]) 
开发者ID:apache,项目名称:airflow,代码行数:18,代码来源:test_base_google.py

示例4: _get_explicit_environ_credentials

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [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

示例5: _service_key

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def _service_key():
        return os.environ.get(CREDENTIALS) 
开发者ID:apache,项目名称:airflow,代码行数:4,代码来源:gcp_system_helpers.py

示例6: test_provide_gcp_credentials_key_content

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_credentials_key_content(self, mock_file):
        file_dict = {"foo": "bar"}
        string_file = StringIO()
        file_content = json.dumps(file_dict)
        file_name = "/test/mock-file"
        mock_file_handler = mock_file.return_value.__enter__.return_value
        mock_file_handler.name = file_name
        mock_file_handler.write = string_file.write

        with provide_gcp_credentials(key_file_dict=file_dict):
            self.assertEqual(os.environ[CREDENTIALS], file_name)
            self.assertEqual(file_content, string_file.getvalue())
        self.assertEqual(os.environ[CREDENTIALS], ENV_VALUE) 
开发者ID:apache,项目名称:airflow,代码行数:15,代码来源:test_credentials_provider.py

示例7: test_provide_gcp_credentials_keep_environment

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_credentials_keep_environment(self):
        key_path = "/test/key-path"
        with provide_gcp_credentials(key_file_path=key_path):
            self.assertEqual(os.environ[CREDENTIALS], key_path)
        self.assertEqual(os.environ[CREDENTIALS], ENV_VALUE) 
开发者ID:apache,项目名称:airflow,代码行数:7,代码来源:test_credentials_provider.py

示例8: test_provide_gcp_conn_and_credentials

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_conn_and_credentials(self, mock_builder):
        mock_builder.return_value = TEMP_VARIABLE
        path = "path/to/file.json"
        scopes = ["scopes"]
        project_id = "project_id"
        with provide_gcp_conn_and_credentials(path, scopes, project_id):
            mock_builder.assert_called_once_with(
                key_file_path=path, scopes=scopes, project_id=project_id
            )
            self.assertEqual(
                os.environ[AIRFLOW_CONN_GOOGLE_CLOUD_DEFAULT], TEMP_VARIABLE
            )
            self.assertEqual(os.environ[CREDENTIALS], path)
        self.assertEqual(os.environ[AIRFLOW_CONN_GOOGLE_CLOUD_DEFAULT], ENV_VALUE)
        self.assertEqual(os.environ[CREDENTIALS], ENV_VALUE) 
开发者ID:apache,项目名称:airflow,代码行数:17,代码来源:test_credentials_provider.py

示例9: test_get_credentials_and_project_id_with_default_auth

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_get_credentials_and_project_id_with_default_auth(self, mock_auth_default):
        result = get_credentials_and_project_id()
        mock_auth_default.assert_called_once_with(scopes=None)
        self.assertEqual(("CREDENTIALS", "PROJECT_ID"), result) 
开发者ID:apache,项目名称:airflow,代码行数:6,代码来源:test_credentials_provider.py

示例10: test_provide_gcp_credential_file_decorator_key_path

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_credential_file_decorator_key_path(self):
        key_path = '/test/key-path'
        self.instance.extras = {'extra__google_cloud_platform__key_path': key_path}

        @hook.GoogleBaseHook.provide_gcp_credential_file
        def assert_gcp_credential_file_in_env(_):
            self.assertEqual(os.environ[CREDENTIALS], key_path)

        assert_gcp_credential_file_in_env(self.instance) 
开发者ID:apache,项目名称:airflow,代码行数:11,代码来源:test_base_google.py

示例11: test_provide_gcp_credential_keep_environment

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_credential_keep_environment(self):
        key_path = '/test/key-path'
        self.instance.extras = {'extra__google_cloud_platform__key_path': key_path}

        @hook.GoogleBaseHook.provide_gcp_credential_file
        def assert_gcp_credential_file_in_env(_):
            self.assertEqual(os.environ[CREDENTIALS], key_path)

        assert_gcp_credential_file_in_env(self.instance)
        self.assertEqual(os.environ[CREDENTIALS], ENV_VALUE) 
开发者ID:apache,项目名称:airflow,代码行数:12,代码来源:test_base_google.py

示例12: test_provide_gcp_credential_keep_environment_when_exception

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_credential_keep_environment_when_exception(self):
        key_path = '/test/key-path'
        self.instance.extras = {'extra__google_cloud_platform__key_path': key_path}

        @hook.GoogleBaseHook.provide_gcp_credential_file
        def assert_gcp_credential_file_in_env(_):
            raise Exception()

        with self.assertRaises(Exception):
            assert_gcp_credential_file_in_env(self.instance)

        self.assertEqual(os.environ[CREDENTIALS], ENV_VALUE) 
开发者ID:apache,项目名称:airflow,代码行数:14,代码来源:test_base_google.py

示例13: test_provide_gcp_credential_keep_clear_environment

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_provide_gcp_credential_keep_clear_environment(self):
        key_path = '/test/key-path'
        self.instance.extras = {'extra__google_cloud_platform__key_path': key_path}

        @hook.GoogleBaseHook.provide_gcp_credential_file
        def assert_gcp_credential_file_in_env(_):
            self.assertEqual(os.environ[CREDENTIALS], key_path)

        assert_gcp_credential_file_in_env(self.instance)
        self.assertNotIn(CREDENTIALS, os.environ) 
开发者ID:apache,项目名称:airflow,代码行数:12,代码来源:test_base_google.py

示例14: test_get_credentials_and_project_id_with_default_auth

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_get_credentials_and_project_id_with_default_auth(self, mock_get_creds_and_proj_id):
        self.instance.extras = {}
        result = self.instance._get_credentials_and_project_id()
        mock_get_creds_and_proj_id.assert_called_once_with(
            key_path=None,
            keyfile_dict=None,
            scopes=self.instance.scopes,
            delegate_to=None)
        self.assertEqual(('CREDENTIALS', 'PROJECT_ID'), result) 
开发者ID:apache,项目名称:airflow,代码行数:11,代码来源:test_base_google.py

示例15: test_get_credentials_and_project_id_with_default_auth_and_overridden_project_id

# 需要导入模块: from google.auth import environment_vars [as 别名]
# 或者: from google.auth.environment_vars import CREDENTIALS [as 别名]
def test_get_credentials_and_project_id_with_default_auth_and_overridden_project_id(
        self,
        mock_get_creds_and_proj_id
    ):
        self.instance.extras = {
            'extra__google_cloud_platform__project': "SECOND_PROJECT_ID"
        }
        result = self.instance._get_credentials_and_project_id()
        mock_get_creds_and_proj_id.assert_called_once_with(
            key_path=None,
            keyfile_dict=None,
            scopes=self.instance.scopes,
            delegate_to=None
        )
        self.assertEqual(("CREDENTIALS", 'SECOND_PROJECT_ID'), result) 
开发者ID:apache,项目名称:airflow,代码行数:17,代码来源:test_base_google.py


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