-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adding scope to credentials in Connection constructors. #840
Conversation
I might be misremembering, but it feels like we've been around a complete circle here. |
What's the circle? I don't recall the |
6ebc65e moved the scope handling from |
The idea behind this commit is not just churn / moving the code. We want people to be able to get credentials from elsewhere and pass them in to a connection without worrying about adding the scopes. If we never expect people to construct a This was all brought about by @jgeewax pointing out some alternate auth / credentials flows. |
@tseaver Can we keep moving on this? |
@@ -94,6 +93,25 @@ def http(self): | |||
self._http = self._credentials.authorize(self._http) | |||
return self._http | |||
|
|||
@staticmethod | |||
def _scoped_credentials(credentials, scope): |
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.
If I recall correctly, the difference this makes becomes apparent when you look at the case where you want to use some credentials from a specific file to talk to a service. Old way: from gcloud.credentials import get_for_service_account_json
from gcloud import pubsub
credentials = get_for_service_account_json('/path/to/key.json')
credentials = credentials.create_scoped(pubsub.SCOPE) # <-- The thing I don't want to have to type...
connection = pubsub.Connection(credentials=credentials)
pubsub.set_default_connection(connection)
pubsub.Topic('topic_name').create() (Also note that in New way from gcloud.credentials import get_for_service_account_json
from gcloud import pubsub
credentials = get_for_service_account_json('/path/to/key.json')
connection = pubsub.Connection(credentials=credentials) # Scoping happens here, where we know we need it...
pubsub.set_default_connection(connection)
pubsub.Topic('topic_name').create() Is there a reason why you'd want to keep the "scope credentials" action separate from the "create connection" action? I can't think of a reason but maybe you guys know more about this... If there isn't then I fully support this change -- seems much more convenient to do this when creating the connection (and expecting the connection to know which scopes are necessary on the credentials you supplied). |
I also fully support this change FWIW |
@tseaver PTAL |
:class:`NoneType` | ||
:returns: A new credentials object that has a scope added (if needed). | ||
""" | ||
if credentials and credentials.create_scoped_required(): |
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.
0cb6fc9
to
7cfc884
Compare
Just rebased on top of @tseaver Can we resolve the discussion and move forward here? |
@tseaver Can we wrap this up? |
@@ -17,6 +17,10 @@ | |||
from gcloud import connection as base_connection | |||
|
|||
|
|||
SCOPE = ('https://www.googleapis.com/auth/pubsub', | |||
'https://www.googleapis.com/auth/cloud-platform') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
LGTM, module my comments this morning on the |
This also obsoletes get_scoped_connection() so it is removed.
7cfc884
to
b44b25b
Compare
Adding scope to credentials in Connection constructors.
This also obsoletes get_scoped_connection() so it is removed.
FYI @jgeewax thanks for nudging in this direction. It moves the scope adding behavior into the
Connection
constructors.