本文整理汇总了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)
示例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)
示例3: signer_email
# 需要导入模块: from google.auth import credentials [as 别名]
# 或者: from google.auth.credentials import signer_email [as 别名]
def signer_email(self):
return self._issuer
示例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)
示例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
示例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",
)
示例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)
示例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