-
Notifications
You must be signed in to change notification settings - Fork 310
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
feat: asyncio http request logic and asynchronous credentials logic #572
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
||
import abc | ||
|
||
import six |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should six be needed for this? this surface is only usable for 3.6+ correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used six to change the exception types (line 143, 147) so that we could raise our defined transport error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module uses six
only for the six.add_metaclass(abc.ABCMeta)
class decorator. Given that it will only ever be imported under Python >= 3.6, it would be clearer to just use the direct Py3 syntax, e.g.:
class Credentials(credentials.Credentials, metaclass=abc.ABCMeta):
...
google/auth/transport/aiohttp_req.py
Outdated
from google.auth.transport import requests | ||
|
||
|
||
_OAUTH_SCOPES = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these shared with the other transport? Can we extract them to a common import to avoid duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit.
google/auth/transport/aiohttp_req.py
Outdated
This class can be useful if you want to manually refresh a | ||
:class:`~google.auth.credentials.Credentials` instance:: | ||
|
||
import google.auth.transport.aiohttp_req |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have raised this before, but I am -1 on abbreviations. is there a motivation for naming this aiohttp_req
? Instead of perhaps aiohttp
or aiohttp_request
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation was the length, could change this to aiohttp_request though if that would be better. I'm worried about the name change to aiohttp just because of naming collision to the aiohttp library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, changed to aiohttp_requests in all 3 PRs
google/auth/transport/aiohttp_req.py
Outdated
:class:`~google.auth.credentials.Credentials` instance:: | ||
|
||
import google.auth.transport.aiohttp_req | ||
import aiohttp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import doesn't seem to be used in this sample. Is it required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the aiohttp import is not required. Removed from the docstring.
google/auth/transport/aiohttp_req.py
Outdated
|
||
def __init__(self, session=None): | ||
""" | ||
self.session = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this commented out code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this change when switching the initialization of client session, deleted the commented out code now.
google/auth/transport/aiohttp_req.py
Outdated
Make an HTTP request using aiohttp. | ||
|
||
Args: | ||
url (str): The URI to be requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may be carry-over, does the old surface use a param url
and refer to it as a uri
as well? If so we can leave this but it seems a little strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was what the documentation was like in the old surface and therefore carried over on to here - I do agree the discrepancy is strange - it would seem that we want this to be URL. Changed in the current version.
google/auth/transport/aiohttp_req.py
Outdated
refresh_timeout=None, | ||
auth_request=None, | ||
): | ||
super(AuthorizedSession, self).__init__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are all of these vars unique to the implementation? It seems _loop
and _refresh_lock
are. Are any of these in the super() call and duplicate? If the args were passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_loop and _refresh_lock are unique to this implementation. I think that as they are class variables with the self. syntax we wouldn't need to include them in the super() call, we could talk about this on our next call.
noxfile.py
Outdated
] | ||
|
||
TEST_DEPENDENCIES2 = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we share this list, composing test_dependencies
from this list and adding the other two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit to only have the 1 TEST_DEPENDENCIES list.
noxfile.py
Outdated
@@ -107,7 +91,7 @@ def unit(session): | |||
|
|||
@nox.session(python=["2.7", "3.5"]) | |||
def unit_prev_versions(session): | |||
session.install(*TEST_DEPENDENCIES2) | |||
session.install(*TEST_DEPENDENCIES[:-2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a little nervous about this, expecting to see folks add more deps :D.
can you make two lists one "dependencies" and one "additional_python_3_dependencies". And for python3 create a set with the two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in the latest commit to have 2 lists and then a composition of both for the python3.6+ async tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me aside from the minor issues raised by @crwilcox . Nice work!
noxfile.py
Outdated
@@ -107,7 +91,7 @@ def unit(session): | |||
|
|||
@nox.session(python=["2.7", "3.5"]) | |||
def unit_prev_versions(session): | |||
session.install(*TEST_DEPENDENCIES2) | |||
session.install(*TEST_DEPENDENCIES[:-2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
|
||
import abc | ||
|
||
import six |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module uses six
only for the six.add_metaclass(abc.ABCMeta)
class decorator. Given that it will only ever be imported under Python >= 3.6, it would be clearer to just use the direct Py3 syntax, e.g.:
class Credentials(credentials.Credentials, metaclass=abc.ABCMeta):
...
|
||
"""Transport adapter for Async HTTP (aiohttp).""" | ||
|
||
from __future__ import absolute_import |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant under Python 3.x.
|
||
except aiohttp.ClientError as caught_exc: | ||
new_exc = exceptions.TransportError(caught_exc) | ||
six.raise_from(new_exc, caught_exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given Python 3 only, this can be simplified to:
except aiohttp.ClientError as caught_exc:
raise exceptions.TransportError(caught_exc) from caught_exc
|
||
except asyncio.TimeoutError as caught_exc: | ||
new_exc = exceptions.TransportError(caught_exc) | ||
six.raise_from(new_exc, caught_exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here:
except asyncio.TimeoutError as caught_exc:
raise exceptions.TransportError(caught_exc) from caught_exc
import flask | ||
import pytest | ||
from pytest_localserver.http import WSGIServer | ||
from six.moves import http_client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given Python3-only, this can be just:
import http.client
and then use http.client.OK
, etc., below.
* feat: asyncio http request logic and asynchronous credentials logic (#572) Co-authored-by: Anirudh Baddepudi <43104821+anibadde@users.noreply.github.com>
* refactor: split 'with_quota_project' into separate base class (#561) Co-authored-by: Tres Seaver <tseaver@palladion.com> * fix: dummy commit to trigger a auto release (#597) * chore: release 1.21.1 (#599) * chore: updated CHANGELOG.md [ci skip] * chore: updated setup.cfg [ci skip] * chore: updated setup.py Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: migrate signBlob to iamcredentials.googleapis.com (#600) Migrate signBlob from iam.googleapis.com to iamcredentials.googleapis.com. This API is deprecated and will be shutdown in one year. This is used google.auth.iam.Signer. Added a system_test to sanity check the implementation. * chore: release 1.21.2 (#601) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: fix expiry for `to_json()` (#589) * This patch for </issues/501> includes the following fixes: - The access token is always set to `None`, so the fix involves using (the access) `token` from the saved JSON credentials file. - For refresh needs, `expiry` also needs to be saved via `to_json()`. - DUMP: As `expiry` is a `datetime.datetime` object, serialize to `datetime.isoformat()` in the same [`oauth2client` format](https://github.com/googleapis/oauth2client/blob/master/oauth2client/client.py#L55) for consistency. - LOAD: Add code to restore `expiry` back to `datetime.datetime` object when imported. - LOAD: If `expiry` was unsaved, automatically set it as expired so refresh takes place. - Minor `scopes` updates - DUMP: Add property for `scopes` so `to_json()` can grab it - LOAD: `scopes` may be saved as a string instead of a JSON array (Python list), so ensure it is Sequence[str] when imported. * chore: add default CODEOWNERS (#609) * chore: release 1.21.3 (#607) * feat: add asyncio based auth flow (#612) * feat: asyncio http request logic and asynchronous credentials logic (#572) Co-authored-by: Anirudh Baddepudi <43104821+anibadde@users.noreply.github.com> * chore: release 1.22.0 (#615) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: move aiohttp to extra as it is currently internal surface (#619) Fix #618. Removes aiohttp from required dependencies to lessen dependency tree for google-auth. This will need to be looked at again as more folks use aiohttp and once the surfaces goes to public visibility. * chore: release 1.22.1 (#620) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: remove checks for ancient versions of Cryptography (#596) Refs #595 (comment) I see no point in checking whether someone is running a version of https://github.com/pyca/cryptography/ from 2014 that doesn't even compile against modern versions of OpenSSL anymore. * chore: sync to master Syncs to master. Fixes broken unit tests in Python 3.6 and 3.7. Aligns test_identity_pool.py with test_aws.py. Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: Tres Seaver <tseaver@palladion.com> Co-authored-by: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: wesley chun <wescpy@gmail.com> Co-authored-by: Christopher Wilcox <crwilcox@google.com> Co-authored-by: Anirudh Baddepudi <43104821+anibadde@users.noreply.github.com> Co-authored-by: Aarni Koskela <akx@iki.fi>
1st Async Auth Class PR