diff --git a/examples/BUILD b/examples/BUILD index 057940abd3a..5dbde0febe4 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -245,35 +245,3 @@ proto_library( name = "route_guide_proto", srcs = ["protos/route_guide.proto"], ) - -py_binary( - name = "data_transmission_server", - python_version = "PY3", - srcs_version = "PY2AND3", - main = "alts_server.py", - srcs = [ - "python/data_transmission/alts_server.py", - "python/data_transmission/demo_pb2.py", - "python/data_transmission/demo_pb2_grpc.py", - "python/data_transmission/server.py", - ], - deps = [ - "//src/python/grpcio/grpc:grpcio", - ], -) - -py_binary( - name = "data_transmission_client", - python_version = "PY3", - srcs_version = "PY2AND3", - main = "alts_client.py", - srcs = [ - "python/data_transmission/alts_client.py", - "python/data_transmission/client.py", - "python/data_transmission/demo_pb2.py", - "python/data_transmission/demo_pb2_grpc.py", - ], - deps = [ - "//src/python/grpcio/grpc:grpcio", - ], -) diff --git a/examples/python/data_transmission/BUILD b/examples/python/data_transmission/BUILD new file mode 100644 index 00000000000..528cd325a1b --- /dev/null +++ b/examples/python/data_transmission/BUILD @@ -0,0 +1,49 @@ +# Copyright 2017 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +licenses(["notice"]) # 3-clause BSD + +load("@grpc_python_dependencies//:requirements.bzl", "requirement") + +py_binary( + name = "alts_server", + python_version = "PY3", + srcs_version = "PY2AND3", + main = "alts_server.py", + srcs = [ + "alts_server.py", + "demo_pb2.py", + "demo_pb2_grpc.py", + "server.py", + ], + deps = [ + "//src/python/grpcio/grpc:grpcio", + ], +) + +py_binary( + name = "alts_client", + python_version = "PY3", + srcs_version = "PY2AND3", + main = "alts_client.py", + srcs = [ + "alts_client.py", + "client.py", + "demo_pb2.py", + "demo_pb2_grpc.py", + ], + deps = [ + "//src/python/grpcio/grpc:grpcio", + ], +) diff --git a/examples/python/data_transmission/alts_client.py b/examples/python/data_transmission/alts_client.py index a1dc8ec558e..e3ddb281930 100644 --- a/examples/python/data_transmission/alts_client.py +++ b/examples/python/data_transmission/alts_client.py @@ -13,12 +13,10 @@ # limitations under the License. """The example of using ALTS credentials to setup gRPC client.""" -import time import grpc import client import demo_pb2_grpc -import demo_pb2 SERVER_ADDRESS = "localhost:23333" diff --git a/examples/python/data_transmission/alts_server.py b/examples/python/data_transmission/alts_server.py index 29a8417152e..e91a1545377 100644 --- a/examples/python/data_transmission/alts_server.py +++ b/examples/python/data_transmission/alts_server.py @@ -13,12 +13,10 @@ # limitations under the License. """The example of using ALTS credentials to setup gRPC server in python.""" -from threading import Thread from concurrent import futures import grpc import demo_pb2_grpc -import demo_pb2 import server SERVER_ADDRESS = 'localhost:23333' diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi index e7ed15cd16b..d3d0f758b16 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi @@ -355,7 +355,7 @@ def server_credentials_local(grpc_local_connect_type local_connect_type): cdef class ALTSChannelCredentials(ChannelCredentials): - def __cinit__(self, service_accounts): + def __cinit__(self, list service_accounts): self.c_options = grpc_alts_credentials_client_options_create() for account in service_accounts: grpc_alts_credentials_client_options_add_target_service_account(self.c_options, account) @@ -368,7 +368,7 @@ cdef class ALTSChannelCredentials(ChannelCredentials): return grpc_alts_credentials_create(self.c_options) -def channel_credentials_alts(service_accounts): +def channel_credentials_alts(list service_accounts): return ALTSChannelCredentials(service_accounts) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index 4a7af822b69..f7cd7c6b8a1 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -220,7 +220,6 @@ class TestGevent(setuptools.Command): 'unit._cython._channel_test.ChannelTest.test_negative_deadline_connectivity', # TODO(https://github.com/grpc/grpc/issues/15411) enable this test 'unit._local_credentials_test.LocalCredentialsTest', - 'unit._alts_credentials_test.ALTSCredentialsTest', 'testing._time_test.StrictRealTimeTest', ) BANNED_WINDOWS_TESTS = ( diff --git a/src/python/grpcio_tests/tests/interop/client.py b/src/python/grpcio_tests/tests/interop/client.py index 03f6113a88c..04b82c0b401 100644 --- a/src/python/grpcio_tests/tests/interop/client.py +++ b/src/python/grpcio_tests/tests/interop/client.py @@ -106,8 +106,8 @@ def get_secure_channel_parameters(args): 'grpc.ssl_target_name_override', args.server_host_override, ),) - else args.use_alts: - channel_credentials = grpc.alts_channel_credentials(['svc_account1@gmail.com']) + elif args.use_alts: + channel_credentials = grpc.alts_channel_credentials() return channel_credentials, channel_opts diff --git a/src/python/grpcio_tests/tests/unit/_alts_credentials_test.py b/src/python/grpcio_tests/tests/unit/_alts_credentials_test.py index a6809c02a1a..07a3c849c8b 100644 --- a/src/python/grpcio_tests/tests/unit/_alts_credentials_test.py +++ b/src/python/grpcio_tests/tests/unit/_alts_credentials_test.py @@ -19,6 +19,9 @@ from concurrent.futures import ThreadPoolExecutor import grpc +REQUEST = b'abc' + + class _GenericHandler(grpc.GenericRpcHandler): def service(self, handler_call_details): @@ -33,11 +36,9 @@ class ALTSCredentialsTest(unittest.TestCase): server.add_generic_rpc_handlers((_GenericHandler(),)) return server - @unittest.skipIf(os.name == 'nt', - 'TODO(https://github.com/grpc/grpc/issues/20078)') def test_alts(self): server_addr = 'localhost:{}' - channel_creds = grpc.alts_channel_credentials(['svcacct@server.com']) + channel_creds = grpc.alts_channel_credentials([]) server_creds = grpc.alts_server_credentials() server = self._create_server() @@ -46,8 +47,8 @@ class ALTSCredentialsTest(unittest.TestCase): with grpc.secure_channel(server_addr.format(port), channel_creds) as channel: self.assertEqual( - b'abc', - channel.unary_unary('/test/method')(b'abc', + REQUEST, + channel.unary_unary('/test/method')(REQUEST, wait_for_ready=True)) server.stop(None)