aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio_tests/tests
diff options
context:
space:
mode:
authorGravatar kpayson64 <kpayson@google.com>2017-05-15 23:34:47 -0700
committerGravatar GitHub <noreply@github.com>2017-05-15 23:34:47 -0700
commit6b7f893b58d5966c46190ca55bdac032095ed7cd (patch)
treeda82e0c50a8e8bb14bffcf94c2e6efdde69e5eca /src/python/grpcio_tests/tests
parent6756d75ca7e59459f822dfd62163c19ec93d7f4e (diff)
parent6c286b5170cd373ccf4400f5714a34b06ec1a008 (diff)
Merge pull request #11087 from kpayson64/update_python_auth
Update Python interop tests to use google-auth package
Diffstat (limited to 'src/python/grpcio_tests/tests')
-rw-r--r--src/python/grpcio_tests/tests/interop/client.py38
-rw-r--r--src/python/grpcio_tests/tests/interop/methods.py27
2 files changed, 32 insertions, 33 deletions
diff --git a/src/python/grpcio_tests/tests/interop/client.py b/src/python/grpcio_tests/tests/interop/client.py
index 97f6843d3c..9be3ba5945 100644
--- a/src/python/grpcio_tests/tests/interop/client.py
+++ b/src/python/grpcio_tests/tests/interop/client.py
@@ -29,10 +29,11 @@
"""The Python implementation of the GRPC interoperability test client."""
import argparse
-from oauth2client import client as oauth2client_client
+import os
+from google import auth as google_auth
+from google.auth import jwt as google_auth_jwt
import grpc
-from grpc.beta import implementations
from src.proto.grpc.testing import test_pb2
from tests.interop import methods
@@ -84,25 +85,24 @@ def _application_default_credentials():
def _stub(args):
target = '{}:{}'.format(args.server_host, args.server_port)
if args.test_case == 'oauth2_auth_token':
- google_credentials = _application_default_credentials()
- scoped_credentials = google_credentials.create_scoped(
- [args.oauth_scope])
- access_token = scoped_credentials.get_access_token().access_token
- call_credentials = grpc.access_token_call_credentials(access_token)
+ google_credentials, unused_project_id = google_auth.default(
+ scopes=[args.oauth_scope])
+ google_credentials.refresh(google_auth.transport.requests.Request())
+ call_credentials = grpc.access_token_call_credentials(
+ google_credentials.token)
elif args.test_case == 'compute_engine_creds':
- google_credentials = _application_default_credentials()
- scoped_credentials = google_credentials.create_scoped(
- [args.oauth_scope])
- # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last
- # remaining use of the Beta API.
- call_credentials = implementations.google_call_credentials(
- scoped_credentials)
+ google_credentials, unused_project_id = google_auth.default(
+ scopes=[args.oauth_scope])
+ call_credentials = grpc.metadata_call_credentials(
+ google_auth.transport.grpc.AuthMetadataPlugin(
+ credentials=google_credentials,
+ request=google_auth.transport.requests.Request()))
elif args.test_case == 'jwt_token_creds':
- google_credentials = _application_default_credentials()
- # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last
- # remaining use of the Beta API.
- call_credentials = implementations.google_call_credentials(
- google_credentials)
+ google_credentials = google_auth_jwt.OnDemandCredentials.from_service_account_file(
+ os.environ[google_auth.environment_vars.CREDENTIALS])
+ call_credentials = grpc.metadata_call_credentials(
+ google_auth.transport.grpc.AuthMetadataPlugin(
+ credentials=google_credentials, request=None))
else:
call_credentials = None
if args.use_tls:
diff --git a/src/python/grpcio_tests/tests/interop/methods.py b/src/python/grpcio_tests/tests/interop/methods.py
index e1016f7c0d..354b51da25 100644
--- a/src/python/grpcio_tests/tests/interop/methods.py
+++ b/src/python/grpcio_tests/tests/interop/methods.py
@@ -33,8 +33,10 @@ import json
import os
import threading
-from oauth2client import client as oauth2client_client
-
+from google import auth as google_auth
+from google.auth import environment_vars as google_auth_environment_vars
+from google.auth.transport import grpc as google_auth_transport_grpc
+from google.auth.transport import requests as google_auth_transport_requests
import grpc
from grpc.beta import implementations
@@ -401,8 +403,7 @@ def _compute_engine_creds(stub, args):
def _oauth2_auth_token(stub, args):
- json_key_filename = os.environ[
- oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS]
+ json_key_filename = os.environ[google_auth_environment_vars.CREDENTIALS]
wanted_email = json.load(open(json_key_filename, 'rb'))['client_email']
response = _large_unary_common_behavior(stub, True, True, None)
if wanted_email != response.username:
@@ -414,8 +415,7 @@ def _oauth2_auth_token(stub, args):
def _jwt_token_creds(stub, args):
- json_key_filename = os.environ[
- oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS]
+ json_key_filename = os.environ[google_auth_environment_vars.CREDENTIALS]
wanted_email = json.load(open(json_key_filename, 'rb'))['client_email']
response = _large_unary_common_behavior(stub, True, False, None)
if wanted_email != response.username:
@@ -424,15 +424,14 @@ def _jwt_token_creds(stub, args):
def _per_rpc_creds(stub, args):
- json_key_filename = os.environ[
- oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS]
+ json_key_filename = os.environ[google_auth_environment_vars.CREDENTIALS]
wanted_email = json.load(open(json_key_filename, 'rb'))['client_email']
- credentials = oauth2client_client.GoogleCredentials.get_application_default()
- scoped_credentials = credentials.create_scoped([args.oauth_scope])
- # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last
- # remaining use of the Beta API.
- call_credentials = implementations.google_call_credentials(
- scoped_credentials)
+ google_credentials, unused_project_id = google_auth.default(
+ scopes=[args.oauth_scope])
+ call_credentials = grpc.metadata_call_credentials(
+ google_auth_transport_grpc.AuthMetadataPlugin(
+ credentials=google_credentials,
+ request=google_auth_transport_requests.Request()))
response = _large_unary_common_behavior(stub, True, False, call_credentials)
if wanted_email != response.username:
raise ValueError('expected username %s, got %s' %