@@ -126,17 +126,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
126
126
self.token = token
127
127
self.server = server
128
128
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)
140
130
141
131
def login(self) -> str:
142
132
"""
@@ -152,25 +142,14 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
152
142
configuration.host = self.server
153
143
configuration.api_key["authorization"] = self.token
154
144
145
+ api_client = client.ApiClient(configuration)
155
146
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)
168
148
else:
169
149
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
170
150
print("Insecure request warnings have been disabled")
171
151
configuration.verify_ssl = False
172
152
173
- api_client = client.ApiClient(configuration)
174
153
client.AuthenticationApi(api_client).get_api_group()
175
154
config_path = None
176
155
return "Logged into %s" % self.server
@@ -244,14 +223,36 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
244
223
return config_path
245
224
246
225
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
253
233
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 >
255
256
</ details >
256
257
</ section >
257
258
< section >
@@ -261,25 +262,6 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
261
262
< section >
262
263
< h2 class ="section-title " id ="header-functions "> Functions</ h2 >
263
264
< 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 >
283
265
< dt id ="codeflare_sdk.cluster.auth.config_check "> < code class ="name flex ">
284
266
< span > def < span class ="ident "> config_check</ span > </ span > (< span > ) ‑> str</ span >
285
267
</ code > </ dt >
@@ -318,6 +300,24 @@ <h2 class="section-title" id="header-functions">Functions</h2>
318
300
return config_path</ code > </ pre >
319
301
</ details >
320
302
</ 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 >
321
321
</ dl >
322
322
</ section >
323
323
< section >
@@ -573,17 +573,7 @@ <h3>Methods</h3>
573
573
self.token = token
574
574
self.server = server
575
575
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)
587
577
588
578
def login(self) -> str:
589
579
"""
@@ -599,25 +589,14 @@ <h3>Methods</h3>
599
589
configuration.host = self.server
600
590
configuration.api_key["authorization"] = self.token
601
591
592
+ api_client = client.ApiClient(configuration)
602
593
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)
615
595
else:
616
596
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
617
597
print("Insecure request warnings have been disabled")
618
598
configuration.verify_ssl = False
619
599
620
- api_client = client.ApiClient(configuration)
621
600
client.AuthenticationApi(api_client).get_api_group()
622
601
config_path = None
623
602
return "Logged into %s" % self.server
@@ -665,25 +644,14 @@ <h3>Methods</h3>
665
644
configuration.host = self.server
666
645
configuration.api_key["authorization"] = self.token
667
646
647
+ api_client = client.ApiClient(configuration)
668
648
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)
681
650
else:
682
651
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
683
652
print("Insecure request warnings have been disabled")
684
653
configuration.verify_ssl = False
685
654
686
- api_client = client.ApiClient(configuration)
687
655
client.AuthenticationApi(api_client).get_api_group()
688
656
config_path = None
689
657
return "Logged into %s" % self.server
@@ -729,8 +697,8 @@ <h1>Index</h1>
729
697
</ li >
730
698
< li > < h3 > < a href ="#header-functions "> Functions</ a > </ h3 >
731
699
< 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 >
733
700
< 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 >
734
702
</ ul >
735
703
</ li >
736
704
< li > < h3 > < a href ="#header-classes "> Classes</ a > </ h3 >
0 commit comments