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


Python credentials.signer_email方法代码示例

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


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

示例1: test_it

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def test_it(self):
        sig_bytes = b"DEADBEEF"
        account_name = mock.sentinel.service_account_email
        credentials = _make_credentials(signer_email=account_name)
        credentials.sign_bytes.return_value = sig_bytes
        expiration = 100
        string_to_sign = "dummy_signature"
        result = self._call_fut(credentials, expiration, string_to_sign)

        expected = {
            "GoogleAccessId": account_name,
            "Expires": expiration,
            "Signature": base64.b64encode(sig_bytes),
        }
        self.assertEqual(result, expected)
        credentials.sign_bytes.assert_called_once_with(string_to_sign) 
开发者ID:googleapis,项目名称:python-storage,代码行数:18,代码来源:test__signing.py

示例2: from_signing_credentials

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def from_signing_credentials(cls, credentials, audience, **kwargs):
        """Creates a new :class:`google.auth.jwt.Credentials` instance from an
        existing :class:`google.auth.credentials.Signing` instance.

        The new instance will use the same signer as the existing instance and
        will use the existing instance's signer email as the issuer and
        subject by default.

        Example::

            svc_creds = service_account.Credentials.from_service_account_file(
                'service_account.json')
            audience = (
                'https://pubsub.googleapis.com/google.pubsub.v1.Publisher')
            jwt_creds = jwt.Credentials.from_signing_credentials(
                svc_creds, audience=audience)

        Args:
            credentials (google.auth.credentials.Signing): The credentials to
                use to construct the new credentials.
            audience (str): the `aud` claim. The intended audience for the
                credentials.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.jwt.Credentials: A new Credentials instance.
        """
        kwargs.setdefault("issuer", credentials.signer_email)
        kwargs.setdefault("subject", credentials.signer_email)
        return cls(credentials.signer, audience=audience, **kwargs) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:32,代码来源:jwt.py

示例3: signer_email

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def signer_email(self):
        return self._issuer 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:4,代码来源:jwt.py

示例4: from_signing_credentials

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def from_signing_credentials(cls, credentials, audience, **kwargs):
        """Creates a new :class:`google.auth.jwt.Credentials` instance from an
        existing :class:`google.auth.credentials.Signing` instance.

        The new instance will use the same signer as the existing instance and
        will use the existing instance's signer email as the issuer and
        subject by default.

        Example::

            svc_creds = service_account.Credentials.from_service_account_file(
                'service_account.json')
            audience = (
                'https://pubsub.googleapis.com/google.pubsub.v1.Publisher')
            jwt_creds = jwt.Credentials.from_signing_credentials(
                svc_creds, audience=audience)

        Args:
            credentials (google.auth.credentials.Signing): The credentials to
                use to construct the new credentials.
            audience (str): the `aud` claim. The intended audience for the
                credentials.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.jwt.Credentials: A new Credentials instance.
        """
        kwargs.setdefault('issuer', credentials.signer_email)
        kwargs.setdefault('subject', credentials.signer_email)
        return cls(
            credentials.signer,
            audience=audience,
            **kwargs) 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:35,代码来源:jwt.py

示例5: _test_generate_upload_policy_helper

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def _test_generate_upload_policy_helper(self, **kwargs):
        import base64
        import json

        credentials = _create_signing_credentials()
        credentials.signer_email = mock.sentinel.signer_email
        credentials.sign_bytes.return_value = b"DEADBEEF"
        connection = _Connection()
        connection.credentials = credentials
        client = _Client(connection)
        name = "name"
        bucket = self._make_one(client=client, name=name)

        conditions = [["starts-with", "$key", ""]]

        policy_fields = bucket.generate_upload_policy(conditions, **kwargs)

        self.assertEqual(policy_fields["bucket"], bucket.name)
        self.assertEqual(policy_fields["GoogleAccessId"], mock.sentinel.signer_email)
        self.assertEqual(
            policy_fields["signature"], base64.b64encode(b"DEADBEEF").decode("utf-8")
        )

        policy = json.loads(base64.b64decode(policy_fields["policy"]).decode("utf-8"))

        policy_conditions = policy["conditions"]
        expected_conditions = [{"bucket": bucket.name}] + conditions
        for expected_condition in expected_conditions:
            for condition in policy_conditions:
                if condition == expected_condition:
                    break
            else:  # pragma: NO COVER
                self.fail(
                    "Condition {} not found in {}".format(
                        expected_condition, policy_conditions
                    )
                )

        return policy_fields, policy 
开发者ID:googleapis,项目名称:python-storage,代码行数:41,代码来源:test_bucket.py

示例6: test_with_access_token

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def test_with_access_token(self):
        resource = "/name/path"
        signer_email = "service@example.com"
        credentials = _make_credentials(signer_email=signer_email)
        with mock.patch(
            "google.cloud.storage._signing._sign_message", return_value=b"DEADBEEF"
        ):
            self._call_fut(
                credentials,
                resource=resource,
                expiration=datetime.timedelta(days=5),
                service_account_email=signer_email,
                access_token="token",
            ) 
开发者ID:googleapis,项目名称:python-storage,代码行数:16,代码来源:test__signing.py

示例7: _make_credentials

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def _make_credentials(signer_email=None):
    import google.auth.credentials

    if signer_email:
        credentials = mock.Mock(spec=google.auth.credentials.Signing)
        credentials.signer_email = signer_email
        return credentials
    else:
        return mock.Mock(spec=google.auth.credentials.Credentials) 
开发者ID:googleapis,项目名称:python-storage,代码行数:11,代码来源:test__signing.py

示例8: _create_signing_credentials

# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def _create_signing_credentials():
    import google.auth.credentials

    class _SigningCredentials(
        google.auth.credentials.Credentials, google.auth.credentials.Signing
    ):
        pass

    credentials = mock.Mock(spec=_SigningCredentials)
    credentials.sign_bytes = mock.Mock(return_value=b"Signature_bytes")
    credentials.signer_email = "test@mail.com"
    return credentials 
开发者ID:googleapis,项目名称:python-storage,代码行数:14,代码来源:test_client.py


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