-
Notifications
You must be signed in to change notification settings - Fork 430
Populate token expiry for GCE credentials #473
Populate token expiry for GCE credentials #473
Conversation
@@ -27,6 +28,7 @@ | |||
|
|||
from oauth2client._helpers import _from_bytes | |||
from oauth2client import util | |||
from oauth2client.client import _UTCNOW |
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.
@@ -73,6 +78,8 @@ def _refresh_success_helper(self, bytes_response=False): | |||
self.assertEquals(None, credentials.access_token) | |||
credentials.refresh(http) | |||
self.assertEquals(access_token, credentials.access_token) | |||
self.assertFalse(credentials.access_token_expired) | |||
self.assertTrue(credentials.token_expiry > datetime.utcnow()) |
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.
/cc @elibixby |
@@ -135,6 +136,8 @@ def _refresh(self, http_request): | |||
raise HttpAccessTokenRefreshError(str(e), | |||
status=response.status) | |||
self.access_token = token_content['access_token'] | |||
delta = datetime.timedelta(seconds=int(token_content['expires_in'])) |
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.
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.
Hi bendemaree@ thanks for the contribution, but I'm actually working on a larger update to GCE credentials that includes this. Still writing tests but I'll go ahead and submit a pull request so more work doesn't get duplicated =( |
@elibixby smaller PRs are much easier to review FWIW. |
See #476 I rewrote the wrapper function for the metadata server so that it can be used by lots of common calls that will need to be made, so I would like the first PR to contain that. However, if after that we want to rewrite the interface in a bunch of small PRs that's fine with me. Still, I think all these changes are quite related and should be reviewed together. Just my .02 (Also FYI, I AM splitting up the PR with the GCE credential updates, and the PR to add IAM blob signing, as IAM blob signing could potentially be used in other credential types) |
Ah, alright, thanks for the review anyway! Looking forward to the update; we're trying out some optimistic credential refresh logic since the OAuth dance takes a bit and could cause a request to hang while the token is implicitly refreshed. Closing out; feel free to reopen if needed. |
I'm going to split #476 into smaller PRs and submit those. It's on my plate for the next couple weeks. I think the right thing to do here is write a |
@elibixby @jonparrott Sorry to bring this back to your attention again, but is there any chance we can merge this in? I don't think it's more than a minor bugfix, and at this point it's been 2 months without the major refactor needed to get this behavioral fix. 😢 I don't have the familiarity or bandwidth to re-wrap the metadata server myself, unfortunately. |
@dhermes are you fine with this being merged? |
@bendemaree Sorry about taking so long. I will have some time in the next week to work on my PRs, but if you'd like to go ahead and submit this for merge. That's understandable. |
https://coveralls.io/builds/5540724 What happened to 100% coverage? |
Ahhh I know. This needs to be rebased against |
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
Populates the token_expiry property for GCE App Assertion credentials (thus enabling access_token_expired). This corrects assumptions like the one in the access_token_expired property on GCE specifically: it's stated there "If the token_expiry isn't set, we assume the token doesn't expire" which seems to be incorrect for tokens retrieved from the GCE Metadata service. Remove usage of _UTCNOW
54613ba
to
b124d19
Compare
CLAs look good, thanks! |
@dhermes Squashed and rebased (eventually!). @elibixby @jonparrott Thanks a lot for circling back on this; much obliged! |
@@ -135,6 +136,8 @@ def _refresh(self, http_request): | |||
raise HttpAccessTokenRefreshError(str(e), | |||
status=response.status) | |||
self.access_token = token_content['access_token'] | |||
delta = datetime.timedelta(seconds=int(token_content['expires_in'])) | |||
self.token_expiry = delta + datetime.datetime.utcnow() |
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.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Bump. 😁 |
This LGTM. |
@dhermes if you have any post-merge objections, let me know and I'll fix myself. |
@jonparrott Is there an upcoming release planned that will include this? |
Yes, it will be 3.0.0. I'm waiting for a few outstanding PRs to be resolved first. |
Populates the
token_expiry
property for GCE App Assertion credentials. The token responses from the metadata service have aexpires_in
value in the response that can be leveraged to make things work better on the baseOAuth2Credentials
class, likeaccess_token_expired
.I largely followed the implementation in the base client though less defensively; I don't see any reason why
expires_in
wouldn't be present though perhaps someone knows better. I did note that the existing tests actually assert this value is not set in the mocked token response so perhaps that provides evidence against my assumption.