aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Masood Malekghassemi <soltanmm@users.noreply.github.com>2015-03-30 15:12:02 -0700
committerGravatar Masood Malekghassemi <soltanmm@users.noreply.github.com>2015-03-30 15:12:02 -0700
commit99c2997456f66d6a5dad181f81a13120f1a9e3e6 (patch)
tree1c151a066a94867d19d0e01db9a2384921fd647a /src
parent875eece77b799aaa337557efba572e09c7c55944 (diff)
parentf492b16d48b48ec45adb8dfce41d0756afeb3e96 (diff)
Merge pull request #1148 from nathanielmanistaatgoogle/construction-functions
Unify early_adopter construction functions
Diffstat (limited to 'src')
-rw-r--r--src/compiler/python_generator.cc19
-rw-r--r--src/python/interop/interop/_insecure_interop_test.py4
-rw-r--r--src/python/interop/interop/_secure_interop_test.py9
-rw-r--r--src/python/interop/interop/client.py8
-rw-r--r--src/python/interop/interop/server.py8
-rw-r--r--src/python/src/grpc/early_adopter/implementations.py80
-rw-r--r--src/python/src/grpc/early_adopter/implementations_test.py4
7 files changed, 45 insertions, 87 deletions
diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc
index 748417e477..d32213f7d5 100644
--- a/src/compiler/python_generator.cc
+++ b/src/compiler/python_generator.cc
@@ -271,7 +271,7 @@ bool GetModuleAndMessagePath(const Descriptor* type,
bool PrintServerFactory(const grpc::string& package_qualified_service_name,
const ServiceDescriptor* service, Printer* out) {
out->Print("def early_adopter_create_$Service$_server(servicer, port, "
- "root_certificates, key_chain_pairs):\n",
+ "private_key=None, certificate_chain=None):\n",
"Service", service->name());
{
IndentScope raii_create_server_indent(out);
@@ -339,10 +339,10 @@ bool PrintServerFactory(const grpc::string& package_qualified_service_name,
}
out->Print("}\n");
out->Print(
- "return implementations.secure_server("
+ "return implementations.server("
"\"$PackageQualifiedServiceName$\","
- " method_service_descriptions, port, root_certificates,"
- " key_chain_pairs)\n",
+ " method_service_descriptions, port, private_key=private_key,"
+ " certificate_chain=certificate_chain)\n",
"PackageQualifiedServiceName", package_qualified_service_name);
}
return true;
@@ -353,7 +353,9 @@ bool PrintStubFactory(const grpc::string& package_qualified_service_name,
map<grpc::string, grpc::string> dict = ListToDict({
"Service", service->name(),
});
- out->Print(dict, "def early_adopter_create_$Service$_stub(host, port):\n");
+ out->Print(dict, "def early_adopter_create_$Service$_stub(host, port,"
+ " secure=False, root_certificates=None, private_key=None,"
+ " certificate_chain=None, server_host_override=None):\n");
{
IndentScope raii_create_server_indent(out);
map<grpc::string, grpc::string> method_description_constructors;
@@ -419,9 +421,12 @@ bool PrintStubFactory(const grpc::string& package_qualified_service_name,
}
out->Print("}\n");
out->Print(
- "return implementations.insecure_stub("
+ "return implementations.stub("
"\"$PackageQualifiedServiceName$\","
- " method_invocation_descriptions, host, port)\n",
+ " method_invocation_descriptions, host, port, secure=secure,"
+ " root_certificates=root_certificates, private_key=private_key,"
+ " certificate_chain=certificate_chain,"
+ " server_host_override=server_host_override)\n",
"PackageQualifiedServiceName", package_qualified_service_name);
}
return true;
diff --git a/src/python/interop/interop/_insecure_interop_test.py b/src/python/interop/interop/_insecure_interop_test.py
index e4ddff1a0b..42e7a4d5c4 100644
--- a/src/python/interop/interop/_insecure_interop_test.py
+++ b/src/python/interop/interop/_insecure_interop_test.py
@@ -42,11 +42,11 @@ class InsecureInteropTest(
unittest.TestCase):
def setUp(self):
- self.server = implementations.insecure_server(
+ self.server = implementations.server(
methods.SERVICE_NAME, methods.SERVER_METHODS, 0)
self.server.start()
port = self.server.port()
- self.stub = implementations.insecure_stub(
+ self.stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, 'localhost', port)
def tearDown(self):
diff --git a/src/python/interop/interop/_secure_interop_test.py b/src/python/interop/interop/_secure_interop_test.py
index 214212dca4..27e76315b6 100644
--- a/src/python/interop/interop/_secure_interop_test.py
+++ b/src/python/interop/interop/_secure_interop_test.py
@@ -45,14 +45,15 @@ class SecureInteropTest(
unittest.TestCase):
def setUp(self):
- self.server = implementations.secure_server(
+ self.server = implementations.server(
methods.SERVICE_NAME, methods.SERVER_METHODS, 0,
- resources.private_key(), resources.certificate_chain())
+ private_key=resources.private_key(),
+ certificate_chain=resources.certificate_chain())
self.server.start()
port = self.server.port()
- self.stub = implementations.secure_stub(
+ self.stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, 'localhost', port,
- resources.test_root_certificates(), None, None,
+ secure=True, root_certificates=resources.test_root_certificates(),
server_host_override=_SERVER_HOST_OVERRIDE)
def tearDown(self):
diff --git a/src/python/interop/interop/client.py b/src/python/interop/interop/client.py
index fb7dfb5729..85a0dcd998 100644
--- a/src/python/interop/interop/client.py
+++ b/src/python/interop/interop/client.py
@@ -66,14 +66,14 @@ def _stub(args):
else:
root_certificates = resources.prod_root_certificates()
- stub = implementations.secure_stub(
+ stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, args.server_host,
- args.server_port, root_certificates, None, None,
+ args.server_port, secure=True, root_certificates=root_certificates,
server_host_override=args.server_host_override)
else:
- stub = implementations.insecure_stub(
+ stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, args.server_host,
- args.server_port)
+ args.server_port, secure=False)
return stub
diff --git a/src/python/interop/interop/server.py b/src/python/interop/interop/server.py
index 5791203743..a67d412038 100644
--- a/src/python/interop/interop/server.py
+++ b/src/python/interop/interop/server.py
@@ -53,11 +53,11 @@ def serve():
if args.use_tls:
private_key = resources.private_key()
certificate_chain = resources.certificate_chain()
- server = implementations.secure_server(
- methods.SERVICE_NAME, methods.SERVER_METHODS, args.port, private_key,
- certificate_chain)
+ server = implementations.server(
+ methods.SERVICE_NAME, methods.SERVER_METHODS, args.port,
+ private_key=private_key, certificate_chain=certificate_chain)
else:
- server = implementations.insecure_server(
+ server = implementations.server(
methods.SERVICE_NAME, methods.SERVER_METHODS, args.port)
server.start()
diff --git a/src/python/src/grpc/early_adopter/implementations.py b/src/python/src/grpc/early_adopter/implementations.py
index cc0b8ec9e8..7d3d29f06c 100644
--- a/src/python/src/grpc/early_adopter/implementations.py
+++ b/src/python/src/grpc/early_adopter/implementations.py
@@ -188,43 +188,10 @@ class _Stub(interfaces.Stub):
raise AttributeError(attr)
-def _build_stub(
- service_name, methods, host, port, secure, root_certificates, private_key,
- certificate_chain, server_host_override=None):
- breakdown = _face_utilities.break_down_invocation(service_name, methods)
- return _Stub(
- breakdown, host, port, secure, root_certificates, private_key,
- certificate_chain, server_host_override=server_host_override)
-
-
-def _build_server(service_name, methods, port, private_key, certificate_chain):
- breakdown = _face_utilities.break_down_service(service_name, methods)
- return _Server(breakdown, port, private_key, certificate_chain)
-
-
-def insecure_stub(service_name, methods, host, port):
- """Constructs an insecure interfaces.Stub.
-
- Args:
- service_name: The package-qualified full name of the service.
- methods: A dictionary from RPC method name to
- interfaces.RpcMethodInvocationDescription describing the RPCs to be
- supported by the created stub. The RPC method names in the dictionary are
- not qualified by the service name or decorated in any other way.
- host: The host to which to connect for RPC service.
- port: The port to which to connect for RPC service.
-
- Returns:
- An interfaces.Stub affording RPC invocation.
- """
- return _build_stub(
- service_name, methods, host, port, False, None, None, None)
-
-
-def secure_stub(
- service_name, methods, host, port, root_certificates, private_key,
- certificate_chain, server_host_override=None):
- """Constructs an insecure interfaces.Stub.
+def stub(
+ service_name, methods, host, port, secure=False, root_certificates=None,
+ private_key=None, certificate_chain=None, server_host_override=None):
+ """Constructs an interfaces.Stub.
Args:
service_name: The package-qualified full name of the service.
@@ -234,6 +201,7 @@ def secure_stub(
not qualified by the service name or decorated in any other way.
host: The host to which to connect for RPC service.
port: The port to which to connect for RPC service.
+ secure: Whether or not to construct the stub with a secure connection.
root_certificates: The PEM-encoded root certificates or None to ask for
them to be retrieved from a default location.
private_key: The PEM-encoded private key to use or None if no private key
@@ -246,32 +214,15 @@ def secure_stub(
Returns:
An interfaces.Stub affording RPC invocation.
"""
- return _build_stub(
- service_name, methods, host, port, True, root_certificates, private_key,
+ breakdown = _face_utilities.break_down_invocation(service_name, methods)
+ return _Stub(
+ breakdown, host, port, secure, root_certificates, private_key,
certificate_chain, server_host_override=server_host_override)
-def insecure_server(service_name, methods, port):
- """Constructs an insecure interfaces.Server.
-
- Args:
- service_name: The package-qualified full name of the service.
- methods: A dictionary from RPC method name to
- interfaces.RpcMethodServiceDescription describing the RPCs to
- be serviced by the created server. The RPC method names in the dictionary
- are not qualified by the service name or decorated in any other way.
- port: The desired port on which to serve or zero to ask for a port to
- be automatically selected.
-
- Returns:
- An interfaces.Server that will run with no security and
- service unsecured raw requests.
- """
- return _build_server(service_name, methods, port, None, None)
-
-
-def secure_server(service_name, methods, port, private_key, certificate_chain):
- """Constructs a secure interfaces.Server.
+def server(
+ service_name, methods, port, private_key=None, certificate_chain=None):
+ """Constructs an interfaces.Server.
Args:
service_name: The package-qualified full name of the service.
@@ -281,11 +232,12 @@ def secure_server(service_name, methods, port, private_key, certificate_chain):
are not qualified by the service name or decorated in any other way.
port: The port on which to serve or zero to ask for a port to be
automatically selected.
- private_key: A pem-encoded private key.
- certificate_chain: A pem-encoded certificate chain.
+ private_key: A pem-encoded private key, or None for an insecure server.
+ certificate_chain: A pem-encoded certificate chain, or None for an insecure
+ server.
Returns:
An interfaces.Server that will serve secure traffic.
"""
- return _build_server(
- service_name, methods, port, private_key, certificate_chain)
+ breakdown = _face_utilities.break_down_service(service_name, methods)
+ return _Server(breakdown, port, private_key, certificate_chain)
diff --git a/src/python/src/grpc/early_adopter/implementations_test.py b/src/python/src/grpc/early_adopter/implementations_test.py
index ae4adad90f..32b974724c 100644
--- a/src/python/src/grpc/early_adopter/implementations_test.py
+++ b/src/python/src/grpc/early_adopter/implementations_test.py
@@ -106,11 +106,11 @@ _TIMEOUT = 3
class EarlyAdopterImplementationsTest(unittest.TestCase):
def setUp(self):
- self.server = implementations.insecure_server(
+ self.server = implementations.server(
SERVICE_NAME, _SERVICE_DESCRIPTIONS, 0)
self.server.start()
port = self.server.port()
- self.stub = implementations.insecure_stub(
+ self.stub = implementations.stub(
SERVICE_NAME, _INVOCATION_DESCRIPTIONS, 'localhost', port)
def tearDown(self):