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