Skip to content
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

Switch from oauth2client to google-auth #2726

Merged
merged 25 commits into from
Dec 2, 2016

Conversation

theacodes
Copy link
Contributor

@theacodes theacodes commented Nov 11, 2016

  • Removes all use of oauth2client from every package and tests.
  • Updates core to use google-auth's default credentials, project ID, and scoping logic.
  • Updates bigtable to use google-auth's scoping logic.

@theacodes theacodes added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Nov 11, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 11, 2016
Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really great changes! Why do we don't merge this?

import grpc
except ImportError: # pragma: NO COVER
grpc = None
import six
from six.moves import http_client
from six.moves import configparser

from google.cloud.environment_vars import PROJECT

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

def _determine_default_project(project=None):
"""Determine default project ID explicitly or implicitly as fall-back.

In implicit case, supports three environments. In order of precedence, the
implicit environments are:

* GOOGLE_CLOUD_PROJECT environment variable
* GOOGLE_CLOUD_PROJECT and GCLOUD_PROJECT environment variable

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

if project is None:
project = _compute_engine_id()

_, project = google.auth.default()

This comment was marked as spam.

This comment was marked as spam.

json_credentials_path)
kwargs['credentials'] = credentials
return cls(*args, **kwargs)

@classmethod
def from_service_account_p12(cls, client_email, private_key_path,

This comment was marked as spam.

@@ -84,7 +85,8 @@ def get_credentials():
:returns: A new credentials instance corresponding to the implicit
environment.
"""
return client.GoogleCredentials.get_application_default()
credentials, _ = google.auth.default()

This comment was marked as spam.

@@ -4,6 +4,7 @@ envlist =

[testing]
deps =
mock

This comment was marked as spam.

This comment was marked as spam.

returned_project = self._call_fut(project)

return returned_project, _callers
def test(self):

This comment was marked as spam.

This comment was marked as spam.

def test(self):
with mock.patch('google.auth.default', autospec=True) as default:
default.return_value = (
mock.sentinel.credentials, mock.sentinel.project)

This comment was marked as spam.

This comment was marked as spam.

project = self._call_fut(mock.sentinel.project)

self.assertEqual(project, mock.sentinel.project)
self.assertFalse(default.called)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

conn = self._make_one(credentials)
self.assertIs(conn.credentials, credentials)
self.assertIs(conn.credentials, mock.sentinel.credentials)

This comment was marked as spam.

This comment was marked as spam.

try:
import google_auth_httplib2

try: # pragma: NO COVER

This comment was marked as spam.

This comment was marked as spam.

with _Monkey(MUT, grpc=grpc_mod,
MetadataPlugin=mock_plugin):

grpc_patch = mock.patch.object(MUT, 'grpc', new=grpc_mod)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

request_patch = mock.patch('google_auth_httplib2.Request')
plugin_patch = mock.patch.object(
MUT, 'AuthMetadataPlugin', create=True)
with grpc_patch, request_patch as request_mock, plugin_patch as plugin:

This comment was marked as spam.

@@ -30,58 +30,9 @@
def get_credentials():
"""Gets credentials implicitly from the current environment.

.. note::

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

import grpc
except ImportError: # pragma: NO COVER
from google.auth.transport.grpc import AuthMetadataPlugin

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

def create_scoped(self, scope):
self._scopes = scope
return self
pass

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

``$ gcloud beta auth application-default login``
* Google App Engine application ID
* Google Compute Engine project ID (from metadata server)
See :func:`google.auth.default` for details on how the default project

This comment was marked as spam.

This comment was marked as spam.

custom_metadata_plugin = MetadataPlugin(credentials)
http = httplib2.Http()
custom_metadata_plugin = AuthMetadataPlugin(
credentials, google_auth_httplib2.Request(http=http))

This comment was marked as spam.

This comment was marked as spam.

@@ -90,7 +90,7 @@ def _httplib2_debug_level(http_request, level, http=None):
old_level = httplib2.debuglevel
http_levels = {}
httplib2.debuglevel = level
if http is not None:
if http is not None and hasattr(http, 'connections'):

This comment was marked as spam.

This comment was marked as spam.

@@ -52,8 +52,9 @@
REQUIREMENTS = [
'httplib2 >= 0.9.1',
'googleapis-common-protos >= 1.3.4',
'oauth2client >= 3.0.0, < 4.0.0dev',

This comment was marked as spam.

This comment was marked as spam.

project = self._call_fut(mock.sentinel.project)

self.assertEqual(project, mock.sentinel.project)
self.assertFalse(default.called)

This comment was marked as spam.

Copy link
Contributor Author

@theacodes theacodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhermes I think I addressed all of the comments - let me know if there's anything left.

Do not merge remains until I get all system tests to pass.

def create_scoped(self, scope):
self._scopes = scope
return self
pass

This comment was marked as spam.

``$ gcloud beta auth application-default login``
* Google App Engine application ID
* Google Compute Engine project ID (from metadata server)
See :func:`google.auth.default` for details on how the default project

This comment was marked as spam.

@@ -90,7 +90,7 @@ def _httplib2_debug_level(http_request, level, http=None):
old_level = httplib2.debuglevel
http_levels = {}
httplib2.debuglevel = level
if http is not None:
if http is not None and hasattr(http, 'connections'):

This comment was marked as spam.

@theacodes
Copy link
Contributor Author

Unit tests all pass on Circle. Going to try to run through the system tests locally now.

@theacodes
Copy link
Contributor Author

bigquery, bigtable, and datastore are passing.

@theacodes
Copy link
Contributor Author

language, logging, monitoring, pubsub, speech, and storage are passing.

Translate seems to be failing for unrelated reasons?

======================================================================
ERROR: test_translate (translate.TestTranslate)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jonwayne/workspace/gcloud-python/system_tests/translate.py", line 59, in test_translate
    values, target_language='de', model=translate.NMT)
  File "/Users/jonwayne/workspace/gcloud-python/.tox/system-tests/lib/python2.7/site-packages/google/cloud/translate/client.py", line 246, in translate
    method='GET', path='', query_params=query_params)
  File "/Users/jonwayne/workspace/gcloud-python/.tox/system-tests/lib/python2.7/site-packages/google/cloud/_http.py", line 335, in api_request
    error_info=method + ' ' + url)
BadRequest: 400 Invalid JSON payload received. Unknown name "model": Cannot bind 'nmt'. Field 'model' could not be found in request message. (GET https://translation.googleapis.com/language/translate/v2?target=de&q=hvala+ti&q=dankon&q=Me+llamo+Jeff&q=My+name+is+Jeff&model=nmt)

That's everything. All seems good?

@theacodes theacodes changed the title [DO NOT MERGE] Switch core to google-auth. Switch core to google-auth. Dec 2, 2016
@theacodes theacodes removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 2, 2016
@theacodes theacodes changed the title Switch core to google-auth. Switch from oauth2client to google-auth Dec 2, 2016
@dhermes
Copy link
Contributor

dhermes commented Dec 2, 2016

@jonparrott Your translate failure may be a rebase issue? Or an old tox env?

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with malice

@theacodes
Copy link
Contributor Author

Merging with ill intent.

@theacodes theacodes merged commit 0581c28 into googleapis:master Dec 2, 2016
@theacodes theacodes deleted the google-auth branch December 2, 2016 23:02
nicolaslecrique added a commit to gator-life/gator.life that referenced this pull request Dec 10, 2016
…kground-update)

There is no specific reason to fix version and to manage this dependency differently (get last version), and it solved the issue below:

for recent image push I have this error with gcloud 0.21.0:

Traceback (most recent call last):
  File "./src/orchestrator/launch_backgroundupdate.py", line 8, in <module>
    init_gcloud_log(GCLOUD_PROJECT, u'background_update', IS_TEST_ENV)
  File "/usr/local/lib/python2.7/site-packages/common/log.py", line 14, in init_gcloud_log
    handler = CloudLoggingHandler(client, logger_name)
  File "/usr/local/lib/python2.7/site-packages/google/cloud/logging/handlers/handlers.py", line 80, in __init__
    self.transport = transport(client, name)
  File "/usr/local/lib/python2.7/site-packages/google/cloud/logging/handlers/transports/background_thread.py", line 154, in __init__
    http = client._connection.credentials.authorize(http)
AttributeError: 'Credentials' object has no attribute 'authorize'

It seems related to change:
googleapis/google-cloud-python#2726

Upgrade to 0.21.1 fix the issue.
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
atulep pushed a commit that referenced this pull request Apr 3, 2023
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
atulep pushed a commit that referenced this pull request Apr 18, 2023
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
parthea pushed a commit that referenced this pull request Jun 4, 2023
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
parthea pushed a commit that referenced this pull request Jul 6, 2023
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
parthea pushed a commit that referenced this pull request Oct 21, 2023
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
parthea pushed a commit that referenced this pull request Oct 21, 2023
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
parthea pushed a commit that referenced this pull request Oct 22, 2023
* Removes all use of oauth2client from every package and tests.
* Updates core to use google-auth's default credentials, project ID, and scoping logic.
* Updates bigtable to use google-auth's scoping logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants