@@ -195,36 +195,36 @@ def _setup_grpc_channel(self):
195
195
options = opts ,
196
196
)
197
197
else :
198
- if (
198
+ if self ._server_name != "" :
199
+ opts .append (("grpc.ssl_target_name_override" , self ._server_name ))
200
+
201
+ root_cert , private_k , cert_chain = None , None , None
202
+ if self ._server_pem_path != "" :
203
+ with Path (self ._server_pem_path ).open ("rb" ) as f :
204
+ root_cert = f .read ()
205
+ elif (
199
206
self ._client_pem_path != ""
200
207
and self ._client_key_path != ""
201
208
and self ._ca_pem_path != ""
202
- and self ._server_name != ""
203
209
):
204
- opts .append (("grpc.ssl_target_name_override" , self ._server_name ))
205
- with Path (self ._client_pem_path ).open ("rb" ) as f :
206
- certificate_chain = f .read ()
207
- with Path (self ._client_key_path ).open ("rb" ) as f :
208
- private_key = f .read ()
209
210
with Path (self ._ca_pem_path ).open ("rb" ) as f :
210
- root_certificates = f .read ()
211
- creds = grpc .ssl_channel_credentials (
212
- root_certificates , private_key , certificate_chain
213
- )
214
- elif self ._server_pem_path != "" and self ._server_name != "" :
215
- opts .append (("grpc.ssl_target_name_override" , self ._server_name ))
216
- with Path (self ._server_pem_path ).open ("rb" ) as f :
217
- server_pem = f .read ()
218
- creds = grpc .ssl_channel_credentials (root_certificates = server_pem )
219
- else :
220
- creds = grpc .ssl_channel_credentials (
221
- root_certificates = None , private_key = None , certificate_chain = None
222
- )
211
+ root_cert = f .read ()
212
+ with Path (self ._client_key_path ).open ("rb" ) as f :
213
+ private_k = f .read ()
214
+ with Path (self ._client_pem_path ).open ("rb" ) as f :
215
+ cert_chain = f .read ()
216
+
217
+ creds = grpc .ssl_channel_credentials (
218
+ root_certificates = root_cert ,
219
+ private_key = private_k ,
220
+ certificate_chain = cert_chain ,
221
+ )
223
222
self ._channel = grpc .secure_channel (
224
223
self ._address ,
225
224
creds ,
226
225
options = opts ,
227
226
)
227
+
228
228
# avoid to add duplicate headers.
229
229
self ._final_channel = self ._channel
230
230
if self ._authorization_interceptor :
0 commit comments