def _stub(args): if args.test_case == 'oauth2_auth_token': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) access_token = scoped_creds.get_access_token().access_token call_creds = implementations.access_token_call_credentials(access_token) elif args.test_case == 'compute_engine_creds': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) call_creds = implementations.google_call_credentials(scoped_creds) elif args.test_case == 'jwt_token_creds': creds = oauth2client_client.GoogleCredentials.get_application_default() call_creds = implementations.google_call_credentials(creds) else: call_creds = None if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = None # will load default roots. channel_creds = implementations.ssl_channel_credentials(root_certificates) if call_creds is not None: channel_creds = implementations.composite_channel_credentials( channel_creds, call_creds) channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, channel_creds, args.server_host_override) stub = test_pb2.beta_create_TestService_stub(channel) else: channel = implementations.insecure_channel( args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def test_google_call_credentials(self): creds = oauth2client_client.GoogleCredentials( 'token', 'client_id', 'secret', 'refresh_token', datetime.datetime(2008, 6, 24), 'https://refresh.uri.com/', 'user_agent') call_creds = implementations.google_call_credentials(creds) self.assertIsInstance(call_creds, implementations.CallCredentials)
def _stub(args): if args.test_case == 'oauth2_auth_token': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) access_token = scoped_creds.get_access_token().access_token call_creds = implementations.access_token_call_credentials( access_token) elif args.test_case == 'compute_engine_creds': creds = oauth2client_client.GoogleCredentials.get_application_default() scoped_creds = creds.create_scoped([args.oauth_scope]) call_creds = implementations.google_call_credentials(scoped_creds) else: call_creds = None if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = None # will load default roots. channel_creds = implementations.ssl_channel_credentials( root_certificates) if call_creds is not None: channel_creds = implementations.composite_channel_credentials( channel_creds, call_creds) channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, channel_creds, args.server_host_override) stub = test_pb2.beta_create_TestService_stub(channel) else: channel = implementations.insecure_channel(args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def test_google_call_credentials(self): creds = oauth2client_client.GoogleCredentials( 'token', 'client_id', 'secret', 'refresh_token', datetime.datetime(2008, 6, 24), 'https://refresh.uri.com/', 'user_agent') call_creds = implementations.google_call_credentials(creds) self.assertIsInstance(call_creds, implementations.CallCredentials)
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) 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) 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) else: call_credentials = None if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = None # will load default roots. channel_credentials = grpc.ssl_channel_credentials(root_certificates) if call_credentials is not None: channel_credentials = grpc.composite_channel_credentials( channel_credentials, call_credentials) channel = grpc.secure_channel(target, channel_credentials, (( 'grpc.ssl_target_name_override', args.server_host_override, ), )) else: channel = grpc.insecure_channel(target) if args.test_case == "unimplemented_service": return test_pb2.UnimplementedServiceStub(channel) else: return test_pb2.TestServiceStub(channel)
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) 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) 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) else: call_credentials = None if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = None # will load default roots. channel_credentials = grpc.ssl_channel_credentials(root_certificates) if call_credentials is not None: channel_credentials = grpc.composite_channel_credentials( channel_credentials, call_credentials) channel = grpc.secure_channel(target, channel_credentials, (( 'grpc.ssl_target_name_override', args.server_host_override,),)) else: channel = grpc.insecure_channel(target) if args.test_case == "unimplemented_service": return test_pb2.UnimplementedServiceStub(channel) else: return test_pb2.TestServiceStub(channel)
def _per_rpc_creds(stub, args): json_key_filename = os.environ[ oauth2client_client.GOOGLE_APPLICATION_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]) call_creds = implementations.google_call_credentials(scoped_credentials) options = interfaces.grpc_call_options(disable_compression=False, credentials=call_creds) response = _large_unary_common_behavior(stub, True, False, protocol_options=options) if wanted_email != response.username: raise ValueError( 'expected username %s, got %s' % (wanted_email, response.username))
def _per_rpc_creds(stub, args): json_key_filename = os.environ[ oauth2client_client.GOOGLE_APPLICATION_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) response = _large_unary_common_behavior(stub, True, False, call_credentials) if wanted_email != response.username: raise ValueError( 'expected username %s, got %s' % (wanted_email, response.username))
def _per_rpc_creds(stub, args): json_key_filename = os.environ[ oauth2client_client.GOOGLE_APPLICATION_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) response = _large_unary_common_behavior(stub, True, False, call_credentials) if wanted_email != response.username: raise ValueError('expected username %s, got %s' % (wanted_email, response.username))
def _per_rpc_creds(stub, args): json_key_filename = os.environ[ oauth2client_client.GOOGLE_APPLICATION_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]) call_creds = implementations.google_call_credentials(scoped_credentials) options = interfaces.grpc_call_options(disable_compression=False, credentials=call_creds) response = _large_unary_common_behavior(stub, True, False, protocol_options=options) if wanted_email != response.username: raise ValueError('expected username %s, got %s' % (wanted_email, response.username))