15
15
import copy
16
16
import json
17
17
import logging
18
- import os
19
18
import ssl
20
19
from json import JSONDecodeError
21
20
from typing import Any , AsyncGenerator
@@ -71,34 +70,10 @@ def __init__(self, config: HttpConfiguration):
71
70
self .headers = {"Content-Type" : "application/json" }
72
71
i = self .config .timeout
73
72
self ._timeout = int (i ) if i is not None else None
74
- # Help ssl.create_default_context() find mounted certificates
75
- self ._setup_ssl_context ()
76
73
77
74
def task_gen_timeout (self , task_count = 1 ):
78
75
return self ._timeout * task_count if self ._timeout else None
79
76
80
- def _setup_ssl_context (self ):
81
- """Let ssl.create_default_context() discover certs.
82
- Following container best practices - use environment variables to help
83
- Python's default SSL context find mounted certificates automatically.
84
- This avoids explicit certificate path management in application code.
85
- """
86
- if self .config .verify_ssl :
87
- # Check for mounted service-ca certificate (container/K8s pattern)
88
- service_ca = settings .SERVICE_CA_PATH
89
- if os .path .exists (service_ca ):
90
- os .environ .setdefault ("REQUESTS_CA_BUNDLE" , service_ca )
91
- os .environ .setdefault ("SSL_CERT_FILE" , service_ca )
92
- logger .info ("Configured SSL context to use mounted service-ca certificate" )
93
-
94
- def get_ssl_verification (self ):
95
- """Just return verify_ssl boolean.
96
- ssl.create_default_context() will automatically discover certificates
97
- via environment variables set in _setup_ssl_context().
98
- No explicit certificate path management needed.
99
- """
100
- return self .config .verify_ssl
101
-
102
77
103
78
@Register (api_type = "http" )
104
79
class HttpCompletionsPipeline (HttpMetaData , ModelPipelineCompletions [HttpConfiguration ]):
@@ -122,7 +97,9 @@ def invoke(self, params: CompletionsParameters) -> CompletionsResponse:
122
97
headers = self .headers ,
123
98
json = model_input ,
124
99
timeout = self .task_gen_timeout (task_count ),
125
- verify = self .get_ssl_verification (),
100
+ verify = (
101
+ self .config .ca_cert_file if self .config .ca_cert_file else self .config .verify_ssl
102
+ ),
126
103
)
127
104
result .raise_for_status ()
128
105
response = json .loads (result .text )
@@ -142,7 +119,9 @@ def self_test(self) -> HealthCheckSummary:
142
119
try :
143
120
res = requests .get (
144
121
url ,
145
- verify = self .get_ssl_verification (),
122
+ verify = (
123
+ self .config .ca_cert_file if self .config .ca_cert_file else self .config .verify_ssl
124
+ ),
146
125
timeout = 1 ,
147
126
)
148
127
res .raise_for_status ()
@@ -176,7 +155,9 @@ def self_test(self) -> HealthCheckSummary:
176
155
self .config .inference_url + "/readiness" ,
177
156
headers = headers ,
178
157
timeout = 1 ,
179
- verify = self .get_ssl_verification (),
158
+ verify = (
159
+ self .config .ca_cert_file if self .config .ca_cert_file else self .config .verify_ssl
160
+ ),
180
161
)
181
162
r .raise_for_status ()
182
163
@@ -233,7 +214,7 @@ def invoke(self, params: ChatBotParameters) -> ChatBotResponse:
233
214
headers = self .headers ,
234
215
json = data ,
235
216
timeout = self .task_gen_timeout (1 ),
236
- verify = self .get_ssl_verification () ,
217
+ verify = self .config . ca_cert_file if self . config . ca_cert_file else self . config . verify_ssl ,
237
218
)
238
219
239
220
if response .status_code == 200 :
@@ -296,8 +277,9 @@ def send_schema1_event(self, ev):
296
277
297
278
async def async_invoke (self , params : StreamingChatBotParameters ) -> AsyncGenerator :
298
279
299
- if self .config .verify_ssl :
300
- ssl_context = ssl .create_default_context ()
280
+ # Configure SSL context based on verify_ssl setting
281
+ if self .config .ca_cert_file :
282
+ ssl_context = ssl .create_default_context (cafile = self .config .ca_cert_file )
301
283
connector = aiohttp .TCPConnector (ssl = ssl_context )
302
284
else :
303
285
connector = aiohttp .TCPConnector (ssl = self .config .verify_ssl )
0 commit comments