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


Python service_account.Credentials方法代码示例

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


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

示例1: test_parses_all_keys

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_parses_all_keys(self, project_id, credentials, custom_encoder):
        settings = {
            "APP_NAME": "rele",
            "SUB_PREFIX": "rele",
            "GC_PROJECT_ID": project_id,
            "GC_CREDENTIALS": credentials,
            "MIDDLEWARE": ["rele.contrib.DjangoDBMiddleware"],
            "ENCODER": custom_encoder,
        }

        config = Config(settings)

        assert config.app_name == "rele"
        assert config.sub_prefix == "rele"
        assert config.gc_project_id == project_id
        assert isinstance(config.credentials, service_account.Credentials)
        assert config.middleware == ["rele.contrib.DjangoDBMiddleware"] 
开发者ID:mercadona,项目名称:rele,代码行数:19,代码来源:test_config.py

示例2: test_from_service_account_info_args

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_from_service_account_info_args(self):
        info = SERVICE_ACCOUNT_INFO.copy()
        scopes = ["email", "profile"]
        subject = "subject"
        additional_claims = {"meta": "data"}

        credentials = service_account.Credentials.from_service_account_info(
            info, scopes=scopes, subject=subject, additional_claims=additional_claims
        )

        assert credentials.service_account_email == info["client_email"]
        assert credentials.project_id == info["project_id"]
        assert credentials._signer.key_id == info["private_key_id"]
        assert credentials._token_uri == info["token_uri"]
        assert credentials._scopes == scopes
        assert credentials._subject == subject
        assert credentials._additional_claims == additional_claims 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:19,代码来源:test_service_account.py

示例3: test_from_service_account_file_args

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_from_service_account_file_args(self):
        info = SERVICE_ACCOUNT_INFO.copy()
        scopes = ["email", "profile"]
        subject = "subject"
        additional_claims = {"meta": "data"}

        credentials = service_account.Credentials.from_service_account_file(
            SERVICE_ACCOUNT_JSON_FILE,
            subject=subject,
            scopes=scopes,
            additional_claims=additional_claims,
        )

        assert credentials.service_account_email == info["client_email"]
        assert credentials.project_id == info["project_id"]
        assert credentials._signer.key_id == info["private_key_id"]
        assert credentials._token_uri == info["token_uri"]
        assert credentials._scopes == scopes
        assert credentials._subject == subject
        assert credentials._additional_claims == additional_claims 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:22,代码来源:test_service_account.py

示例4: test_before_request_refreshes

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_before_request_refreshes(self, jwt_grant):
        credentials = self.make_credentials()
        token = "token"
        jwt_grant.return_value = (
            token,
            _helpers.utcnow() + datetime.timedelta(seconds=500),
            None,
        )
        request = mock.create_autospec(transport.Request, instance=True)

        # Credentials should start as invalid
        assert not credentials.valid

        # before_request should cause a refresh
        credentials.before_request(request, "GET", "http://example.com?a=1#3", {})

        # The refresh endpoint should've been called.
        assert jwt_grant.called

        # Credentials should now be valid.
        assert credentials.valid 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:23,代码来源:test_service_account.py

示例5: from_service_account_file

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def from_service_account_file(cls, filename, *args, **kwargs):
        """Creates an instance of this client using the provided credentials
        file.

        Args:
            filename (str): The path to the service account private key json
                file.
            args: Additional arguments to pass to the constructor.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            QuantumEngineServiceClient: The constructed client.
        """
        credentials = service_account.Credentials.from_service_account_file(
            filename)
        kwargs['credentials'] = credentials
        return cls(*args, **kwargs) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:19,代码来源:quantum_engine_service_client.py

示例6: _verify_credential

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def _verify_credential(self, credential):
        assert credential.client_id == 'mock.apps.googleusercontent.com'
        assert credential.client_secret == 'mock-secret'
        assert credential.refresh_token == 'mock-refresh-token'

        g_credential = credential.get_credential()
        assert isinstance(g_credential, gcredentials.Credentials)
        assert g_credential.token is None
        check_scopes(g_credential)

        mock_response = {
            'access_token': 'mock_access_token',
            'expires_in': 3600
        }
        credentials._request = testutils.MockRequest(200, json.dumps(mock_response))
        access_token = credential.get_access_token()
        assert access_token.access_token == 'mock_access_token'
        assert isinstance(access_token.expiry, datetime.datetime) 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:20,代码来源:test_credentials.py

示例7: delegated_credential

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def delegated_credential(credentials, subject, scopes):
    try:
        admin_creds = credentials.with_subject(subject).with_scopes(scopes)
    except AttributeError:  # Looks like a compute creds object

        # Refresh the boostrap credentials. This ensures that the information
        # about this account, notably the email, is populated.
        request = requests.Request()
        credentials.refresh(request)

        # Create an IAM signer using the bootstrap credentials.
        signer = iam.Signer(request, credentials,
                            credentials.service_account_email)

        # Create OAuth 2.0 Service Account credentials using the IAM-based
        # signer and the bootstrap_credential's service account email.
        admin_creds = service_account.Credentials(
            signer, credentials.service_account_email, TOKEN_URI,
            scopes=scopes, subject=subject)
    except Exception:
        raise

    return admin_creds 
开发者ID:GoogleCloudPlatform,项目名称:professional-services,代码行数:25,代码来源:main.py

示例8: get_credentials

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def get_credentials(service_account_json):
    scopes = ["https://www.googleapis.com/auth/cloud-platform"]
    credentials = (service_account.Credentials
                   .from_service_account_file(service_account_json, scopes=scopes))
    logger.info("credentials created from %s.", service_account_json)
    return credentials 
开发者ID:yxtay,项目名称:recommender-tensorflow,代码行数:8,代码来源:gcp_utils.py

示例9: get_bigquery_client

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def get_bigquery_client(service_account_json):
    scopes = ["https://www.googleapis.com/auth/cloud-platform"]
    credentials = (service_account.Credentials
                   .from_service_account_file(service_account_json, scopes=scopes))
    logger.info("credentials created from %s.", service_account_json)

    # get client
    client = bigquery.Client(project=credentials.project_id, credentials=credentials)
    return client 
开发者ID:yxtay,项目名称:recommender-tensorflow,代码行数:11,代码来源:gcp_utils.py

示例10: test_inits_service_account_creds_when_credential_path_given

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_inits_service_account_creds_when_credential_path_given(self, project_id):
        settings = {
            "GC_PROJECT_ID": project_id,
            "GC_CREDENTIALS_PATH": "tests/dummy-pub-sub-credentials.json",
        }

        config = Config(settings)

        assert config.gc_project_id == project_id
        assert isinstance(config.credentials, google.oauth2.service_account.Credentials)
        assert config.credentials.project_id == "rele-test" 
开发者ID:mercadona,项目名称:rele,代码行数:13,代码来源:test_config.py

示例11: test_uses_path_instead_of_gc_credentials_when_both_are_provided

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_uses_path_instead_of_gc_credentials_when_both_are_provided(
        self, credentials
    ):
        settings = {
            "GC_CREDENTIALS_PATH": "tests/dummy-pub-sub-credentials.json",
            "GC_CREDENTIALS": credentials,
        }

        config = Config(settings)

        assert isinstance(config.credentials, google.oauth2.service_account.Credentials)
        assert config.credentials != credentials
        assert config.credentials.project_id == "rele-test" 
开发者ID:mercadona,项目名称:rele,代码行数:15,代码来源:test_config.py

示例12: test_load_credentials_from_file_authorized_user

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_load_credentials_from_file_authorized_user():
    credentials, project_id = _default.load_credentials_from_file(AUTHORIZED_USER_FILE)
    assert isinstance(credentials, google.oauth2.credentials.Credentials)
    assert project_id is None 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:6,代码来源:test__default.py

示例13: test_load_credentials_from_file_authorized_user_cloud_sdk

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_load_credentials_from_file_authorized_user_cloud_sdk():
    with pytest.warns(UserWarning, match="Cloud SDK"):
        credentials, project_id = _default.load_credentials_from_file(
            AUTHORIZED_USER_CLOUD_SDK_FILE
        )
    assert isinstance(credentials, google.oauth2.credentials.Credentials)
    assert project_id is None

    # No warning if the json file has quota project id.
    credentials, project_id = _default.load_credentials_from_file(
        AUTHORIZED_USER_CLOUD_SDK_WITH_QUOTA_PROJECT_ID_FILE
    )
    assert isinstance(credentials, google.oauth2.credentials.Credentials)
    assert project_id is None 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:16,代码来源:test__default.py

示例14: test_load_credentials_from_file_authorized_user_cloud_sdk_with_scopes

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_load_credentials_from_file_authorized_user_cloud_sdk_with_scopes():
    with pytest.warns(UserWarning, match="Cloud SDK"):
        credentials, project_id = _default.load_credentials_from_file(
            AUTHORIZED_USER_CLOUD_SDK_FILE,
            scopes=["https://www.google.com/calendar/feeds"],
        )
    assert isinstance(credentials, google.oauth2.credentials.Credentials)
    assert project_id is None
    assert credentials.scopes == ["https://www.google.com/calendar/feeds"] 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:11,代码来源:test__default.py

示例15: test_load_credentials_from_file_service_account

# 需要导入模块: from google.oauth2 import service_account [as 别名]
# 或者: from google.oauth2.service_account import Credentials [as 别名]
def test_load_credentials_from_file_service_account():
    credentials, project_id = _default.load_credentials_from_file(SERVICE_ACCOUNT_FILE)
    assert isinstance(credentials, service_account.Credentials)
    assert project_id == SERVICE_ACCOUNT_FILE_DATA["project_id"] 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:6,代码来源:test__default.py


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