@@ -57,6 +57,7 @@ def __init__(self):
5757 self .quiet = None
5858 self .http_timeout = None
5959 self .cafile = None
60+ self .cadata = None
6061 self .insecure = None
6162 self .http = None
6263
@@ -73,6 +74,14 @@ def get_protocol_host_port(self, endpoint):
7374 else :
7475 return protocol , endpoint , self .mon_port
7576
77+ def get_cafile_data (self ):
78+ if self .cafile is None :
79+ return None
80+ if self .cadata is None :
81+ with open (self .cafile , 'rb' ) as f :
82+ self .cadata = f .read ()
83+ return self .cadata
84+
7685 def get_netloc (self , host , port ):
7786 netloc = '%s:%d' % (host , port )
7887 if netloc in name_cache :
@@ -317,10 +326,12 @@ def invoke_grpc(func, *params, explicit_host=None, host=None):
317326 options = [
318327 ('grpc.max_receive_message_length' , 256 << 20 ), # 256 MiB
319328 ]
320- with grpc .insecure_channel ('%s:%d' % (host , connection_params .grpc_port ), options ) as channel :
321- if connection_params .verbose :
322- p = ', ' .join ('<<< %s >>>' % text_format .MessageToString (param , as_one_line = True ) for param in params )
323- print ('INFO: issuing %s(%s) @%s:%d' % (func , p , host , connection_params .grpc_port ), file = sys .stderr )
329+ if connection_params .verbose :
330+ p = ', ' .join ('<<< %s >>>' % text_format .MessageToString (param , as_one_line = True ) for param in params )
331+ print ('INFO: issuing %s(%s) @%s:%d protocol %s' % (func , p , host , connection_params .grpc_port ,
332+ connection_params .mon_protocol ), file = sys .stderr )
333+
334+ def work (channel ):
324335 try :
325336 stub = kikimr_grpc .TGRpcServerStub (channel )
326337 res = getattr (stub , func )(* params )
@@ -332,6 +343,16 @@ def invoke_grpc(func, *params, explicit_host=None, host=None):
332343 print ('ERROR: exception %s' % e , file = sys .stderr )
333344 raise ConnectionError ("Can't connect to specified addresses by gRPC protocol" )
334345
346+ hostport = '%s:%d' % (host , connection_params .grpc_port )
347+ retval = None
348+ if connection_params .mon_protocol == 'grpcs' :
349+ creds = grpc .ssl_channel_credentials (connection_params .get_cafile_data ())
350+ with grpc .secure_channel (hostport , creds , options ) as channel :
351+ retval = work (channel )
352+ else :
353+ with grpc .insecure_channel (hostport , options ) as channel :
354+ retval = work (channel )
355+ return retval
335356
336357def invoke_bsc_request (request ):
337358 if connection_params .http :
0 commit comments