3434
3535
3636class TofuPilotClient :
37- """Wrapper for TofuPilot's API that provides additional support for handling attachments."""
37+ """Wrapper for TofuPilot's API that provides additional support for handling attachments.
38+
39+ Args:
40+ api_key (Optional[str]): API key for authentication with TofuPilot's API.
41+ If not provided, the TOFUPILOT_API_KEY environment variable will be used.
42+ url (Optional[str]): Base URL for TofuPilot's API.
43+ If not provided, the TOFUPILOT_URL environment variable or the default endpoint will be used.
44+ verify (Optional[str]): Path to a CA bundle file to verify TofuPilot's server certificate.
45+ Useful for connecting to instances with custom/self-signed certificates.
46+ """
3847
39- def __init__ (self , api_key : Optional [str ] = None , url : Optional [str ] = None ):
48+ def __init__ (
49+ self ,
50+ api_key : Optional [str ] = None ,
51+ url : Optional [str ] = None ,
52+ verify : Optional [str ] = None ,
53+ ):
4054 self ._current_version = version ("tofupilot" )
4155 print_version_banner (self ._current_version )
4256 self ._logger = setup_logger (logging .INFO )
@@ -52,6 +66,7 @@ def __init__(self, api_key: Optional[str] = None, url: Optional[str] = None):
5266 "Content-Type" : "application/json" ,
5367 "Authorization" : f"Bearer { self ._api_key } " ,
5468 }
69+ self ._verify = verify
5570 self ._max_attachments = CLIENT_MAX_ATTACHMENTS
5671 self ._max_file_size = FILE_MAX_SIZE
5772 check_latest_version (self ._logger , self ._current_version , "tofupilot" )
@@ -159,14 +174,20 @@ def create_run( # pylint: disable=too-many-arguments,too-many-locals
159174 json = payload ,
160175 headers = self ._headers ,
161176 timeout = SECONDS_BEFORE_TIMEOUT ,
177+ verify = self ._verify ,
162178 )
163179 response .raise_for_status ()
164180 result = handle_response (self ._logger , response )
165181
166182 run_id = result .get ("id" )
167183 if run_id and attachments :
168184 upload_attachments (
169- self ._logger , self ._headers , self ._url , attachments , run_id
185+ self ._logger ,
186+ self ._headers ,
187+ self ._url ,
188+ attachments ,
189+ run_id ,
190+ self ._verify ,
170191 )
171192
172193 return result
@@ -229,6 +250,7 @@ def create_run_from_openhtf_report(self, file_path: str):
229250 initialize_url ,
230251 data = json .dumps (payload ),
231252 headers = self ._headers ,
253+ verify = self ._verify ,
232254 timeout = SECONDS_BEFORE_TIMEOUT ,
233255 )
234256
@@ -249,7 +271,13 @@ def create_run_from_openhtf_report(self, file_path: str):
249271 timeout = SECONDS_BEFORE_TIMEOUT ,
250272 )
251273
252- notify_server (self ._headers , self ._url , upload_id , run_id )
274+ notify_server (
275+ self ._headers ,
276+ self ._url ,
277+ upload_id ,
278+ run_id ,
279+ self ._verify ,
280+ )
253281
254282 self ._logger .success (
255283 "Attachment %s successfully uploaded and linked to run." ,
@@ -293,6 +321,7 @@ def get_runs(self, serial_number: str) -> dict:
293321 response = requests .get (
294322 f"{ self ._url } /runs" ,
295323 headers = self ._headers ,
324+ verify = self ._verify ,
296325 params = params ,
297326 timeout = SECONDS_BEFORE_TIMEOUT ,
298327 )
@@ -326,6 +355,7 @@ def delete_run(self, run_id: str) -> dict:
326355 response = requests .delete (
327356 f"{ self ._url } /runs/{ run_id } " ,
328357 headers = self ._headers ,
358+ verify = self ._verify ,
329359 timeout = SECONDS_BEFORE_TIMEOUT ,
330360 )
331361 response .raise_for_status ()
@@ -366,6 +396,7 @@ def update_unit(
366396 f"{ self ._url } /units/{ serial_number } " ,
367397 json = payload ,
368398 headers = self ._headers ,
399+ verify = self ._verify ,
369400 timeout = SECONDS_BEFORE_TIMEOUT ,
370401 )
371402 response .raise_for_status ()
@@ -399,6 +430,7 @@ def delete_unit(self, serial_number: str) -> dict:
399430 response = requests .delete (
400431 f"{ self ._url } /units/{ serial_number } " ,
401432 headers = self ._headers ,
433+ verify = self ._verify ,
402434 timeout = SECONDS_BEFORE_TIMEOUT ,
403435 )
404436 response .raise_for_status ()
@@ -430,7 +462,9 @@ def upload_and_create_from_openhtf_report(
430462
431463 # Upload report
432464 try :
433- upload_id = upload_file (self ._headers , self ._url , file_path )
465+ upload_id = upload_file (
466+ self ._headers , self ._url , file_path , self ._verify
467+ )
434468 except requests .exceptions .HTTPError as http_err :
435469 return handle_http_error (self ._logger , http_err )
436470 except requests .RequestException as e :
@@ -451,6 +485,7 @@ def upload_and_create_from_openhtf_report(
451485 f"{ self ._url } /import" ,
452486 json = payload ,
453487 headers = self ._headers ,
488+ verify = self ._verify ,
454489 timeout = SECONDS_BEFORE_TIMEOUT ,
455490 )
456491 response .raise_for_status ()
@@ -478,6 +513,7 @@ def get_websocket_url(self) -> dict:
478513 response = requests .get (
479514 f"{ self ._url } /rooms" ,
480515 headers = self ._headers ,
516+ verify = self ._verify ,
481517 timeout = SECONDS_BEFORE_TIMEOUT ,
482518 )
483519 response .raise_for_status ()
0 commit comments