-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add service account credentials #25
Conversation
|
||
from google.auth import _helpers | ||
from google.auth import crypt | ||
from google.auth import credentials |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def __init__(self, signer, service_account_email, token_uri, scopes=None, | ||
subject=None, additional_claims=None): | ||
""" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self._service_account_email = service_account_email | ||
self._subject = subject | ||
self._token_uri = token_uri | ||
self._additional_claims = additional_claims or {} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
email = info['client_email'] | ||
key_id = info['private_key_id'] | ||
private_key = info['private_key'] | ||
token_uri = info['token_uri'] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
Args: | ||
filename (str): The path to the service account json file. | ||
kwargs: Additional arguments to pass to the constructor. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
assert credentials._additional_claims['meta'] == 'data' | ||
|
||
def test_from_service_account_bad_key(self): | ||
info = dict(SERVICE_ACCOUNT_INFO) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
with pytest.raises(ValueError) as excinfo: | ||
service_account.Credentials.from_service_account_info(info) | ||
|
||
assert excinfo.match(r'No key could be detected') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
info = {} | ||
|
||
with pytest.raises(KeyError): | ||
service_account.Credentials.from_service_account_info(info) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def test_sign_bytes(self): | ||
to_sign = b'123' | ||
signature = self.credentials.sign_bytes(to_sign) | ||
crypt.verify_signature(to_sign, signature, PUBLIC_CERT_BYTES) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
# Check jwt grant call. | ||
assert jwt_grant_mock.called | ||
request, token_uri, assertion = jwt_grant_mock.call_args[0] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@pytest.fixture(autouse=True) | ||
def credentials(self, signer): | ||
self.credentials = service_account.Credentials( | ||
signer, self.SERVICE_ACCOUNT_EMAIL, self.TOKEN_URI) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
LGTM after |
No description provided.