@@ -126,17 +126,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
126126 self.token = token
127127 self.server = server
128128 self.skip_tls = skip_tls
129- self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)
130-
131- def _gen_ca_cert_path(self, ca_cert_path: str):
132- if ca_cert_path is not None:
133- return ca_cert_path
134- elif "CF_SDK_CA_CERT_PATH" in os.environ:
135- return os.environ.get("CF_SDK_CA_CERT_PATH")
136- elif os.path.exists(WORKBENCH_CA_CERT_PATH):
137- return WORKBENCH_CA_CERT_PATH
138- else:
139- return None
129+ self.ca_cert_path = _gen_ca_cert_path(ca_cert_path)
140130
141131 def login(self) -> str:
142132 """
@@ -152,25 +142,14 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
152142 configuration.host = self.server
153143 configuration.api_key["authorization"] = self.token
154144
145+ api_client = client.ApiClient(configuration)
155146 if not self.skip_tls:
156- if self.ca_cert_path is None:
157- configuration.ssl_ca_cert = None
158- elif os.path.isfile(self.ca_cert_path):
159- print(
160- f"Authenticated with certificate located at {self.ca_cert_path}"
161- )
162- configuration.ssl_ca_cert = self.ca_cert_path
163- else:
164- raise FileNotFoundError(
165- f"Certificate file not found at {self.ca_cert_path}"
166- )
167- configuration.verify_ssl = True
147+ _client_with_cert(api_client, self.ca_cert_path)
168148 else:
169149 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
170150 print("Insecure request warnings have been disabled")
171151 configuration.verify_ssl = False
172152
173- api_client = client.ApiClient(configuration)
174153 client.AuthenticationApi(api_client).get_api_group()
175154 config_path = None
176155 return "Logged into %s" % self.server
@@ -244,14 +223,36 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
244223 return config_path
245224
246225
247- def api_config_handler() -> Optional[client.ApiClient]:
248- """
249- This function is used to load the api client if the user has logged in
250- """
251- if api_client != None and config_path == None:
252- return api_client
226+ def _client_with_cert(client: client.ApiClient, ca_cert_path: Optional[str] = None):
227+ client.configuration.verify_ssl = True
228+ cert_path = _gen_ca_cert_path(ca_cert_path)
229+ if cert_path is None:
230+ client.configuration.ssl_ca_cert = None
231+ elif os.path.isfile(cert_path):
232+ client.configuration.ssl_ca_cert = cert_path
253233 else:
254- return None</ code > </ pre >
234+ raise FileNotFoundError(f"Certificate file not found at {cert_path}")
235+
236+
237+ def _gen_ca_cert_path(ca_cert_path: Optional[str]):
238+ """Gets the path to the default CA certificate file either through env config or default path"""
239+ if ca_cert_path is not None:
240+ return ca_cert_path
241+ elif "CF_SDK_CA_CERT_PATH" in os.environ:
242+ return os.environ.get("CF_SDK_CA_CERT_PATH")
243+ elif os.path.exists(WORKBENCH_CA_CERT_PATH):
244+ return WORKBENCH_CA_CERT_PATH
245+ else:
246+ return None
247+
248+
249+ def get_api_client() -> client.ApiClient:
250+ "This function should load the api client with defaults"
251+ if api_client != None:
252+ return api_client
253+ to_return = client.ApiClient()
254+ _client_with_cert(to_return)
255+ return to_return</ code > </ pre >
255256</ details >
256257</ section >
257258< section >
@@ -261,25 +262,6 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
261262< section >
262263< h2 class ="section-title " id ="header-functions "> Functions</ h2 >
263264< dl >
264- < dt id ="codeflare_sdk.cluster.auth.api_config_handler "> < code class ="name flex ">
265- < span > def < span class ="ident "> api_config_handler</ span > </ span > (< span > ) ‑> Optional[kubernetes.client.api_client.ApiClient]</ span >
266- </ code > </ dt >
267- < dd >
268- < div class ="desc "> < p > This function is used to load the api client if the user has logged in</ p > </ div >
269- < details class ="source ">
270- < summary >
271- < span > Expand source code</ span >
272- </ summary >
273- < pre > < code class ="python "> def api_config_handler() -> Optional[client.ApiClient]:
274- """
275- This function is used to load the api client if the user has logged in
276- """
277- if api_client != None and config_path == None:
278- return api_client
279- else:
280- return None</ code > </ pre >
281- </ details >
282- </ dd >
283265< dt id ="codeflare_sdk.cluster.auth.config_check "> < code class ="name flex ">
284266< span > def < span class ="ident "> config_check</ span > </ span > (< span > ) ‑> str</ span >
285267</ code > </ dt >
@@ -318,6 +300,24 @@ <h2 class="section-title" id="header-functions">Functions</h2>
318300 return config_path</ code > </ pre >
319301</ details >
320302</ dd >
303+ < dt id ="codeflare_sdk.cluster.auth.get_api_client "> < code class ="name flex ">
304+ < span > def < span class ="ident "> get_api_client</ span > </ span > (< span > ) ‑> kubernetes.client.api_client.ApiClient</ span >
305+ </ code > </ dt >
306+ < dd >
307+ < div class ="desc "> < p > This function should load the api client with defaults</ p > </ div >
308+ < details class ="source ">
309+ < summary >
310+ < span > Expand source code</ span >
311+ </ summary >
312+ < pre > < code class ="python "> def get_api_client() -> client.ApiClient:
313+ "This function should load the api client with defaults"
314+ if api_client != None:
315+ return api_client
316+ to_return = client.ApiClient()
317+ _client_with_cert(to_return)
318+ return to_return</ code > </ pre >
319+ </ details >
320+ </ dd >
321321</ dl >
322322</ section >
323323< section >
@@ -573,17 +573,7 @@ <h3>Methods</h3>
573573 self.token = token
574574 self.server = server
575575 self.skip_tls = skip_tls
576- self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)
577-
578- def _gen_ca_cert_path(self, ca_cert_path: str):
579- if ca_cert_path is not None:
580- return ca_cert_path
581- elif "CF_SDK_CA_CERT_PATH" in os.environ:
582- return os.environ.get("CF_SDK_CA_CERT_PATH")
583- elif os.path.exists(WORKBENCH_CA_CERT_PATH):
584- return WORKBENCH_CA_CERT_PATH
585- else:
586- return None
576+ self.ca_cert_path = _gen_ca_cert_path(ca_cert_path)
587577
588578 def login(self) -> str:
589579 """
@@ -599,25 +589,14 @@ <h3>Methods</h3>
599589 configuration.host = self.server
600590 configuration.api_key["authorization"] = self.token
601591
592+ api_client = client.ApiClient(configuration)
602593 if not self.skip_tls:
603- if self.ca_cert_path is None:
604- configuration.ssl_ca_cert = None
605- elif os.path.isfile(self.ca_cert_path):
606- print(
607- f"Authenticated with certificate located at {self.ca_cert_path}"
608- )
609- configuration.ssl_ca_cert = self.ca_cert_path
610- else:
611- raise FileNotFoundError(
612- f"Certificate file not found at {self.ca_cert_path}"
613- )
614- configuration.verify_ssl = True
594+ _client_with_cert(api_client, self.ca_cert_path)
615595 else:
616596 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
617597 print("Insecure request warnings have been disabled")
618598 configuration.verify_ssl = False
619599
620- api_client = client.ApiClient(configuration)
621600 client.AuthenticationApi(api_client).get_api_group()
622601 config_path = None
623602 return "Logged into %s" % self.server
@@ -665,25 +644,14 @@ <h3>Methods</h3>
665644 configuration.host = self.server
666645 configuration.api_key["authorization"] = self.token
667646
647+ api_client = client.ApiClient(configuration)
668648 if not self.skip_tls:
669- if self.ca_cert_path is None:
670- configuration.ssl_ca_cert = None
671- elif os.path.isfile(self.ca_cert_path):
672- print(
673- f"Authenticated with certificate located at {self.ca_cert_path}"
674- )
675- configuration.ssl_ca_cert = self.ca_cert_path
676- else:
677- raise FileNotFoundError(
678- f"Certificate file not found at {self.ca_cert_path}"
679- )
680- configuration.verify_ssl = True
649+ _client_with_cert(api_client, self.ca_cert_path)
681650 else:
682651 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
683652 print("Insecure request warnings have been disabled")
684653 configuration.verify_ssl = False
685654
686- api_client = client.ApiClient(configuration)
687655 client.AuthenticationApi(api_client).get_api_group()
688656 config_path = None
689657 return "Logged into %s" % self.server
@@ -729,8 +697,8 @@ <h1>Index</h1>
729697</ li >
730698< li > < h3 > < a href ="#header-functions "> Functions</ a > </ h3 >
731699< ul class ="">
732- < li > < code > < a title ="codeflare_sdk.cluster.auth.api_config_handler " href ="#codeflare_sdk.cluster.auth.api_config_handler "> api_config_handler</ a > </ code > </ li >
733700< li > < code > < a title ="codeflare_sdk.cluster.auth.config_check " href ="#codeflare_sdk.cluster.auth.config_check "> config_check</ a > </ code > </ li >
701+ < li > < code > < a title ="codeflare_sdk.cluster.auth.get_api_client " href ="#codeflare_sdk.cluster.auth.get_api_client "> get_api_client</ a > </ code > </ li >
734702</ ul >
735703</ li >
736704< li > < h3 > < a href ="#header-classes "> Classes</ a > </ h3 >
0 commit comments