From aa823641e864a0958b0fb3d272993b2fef62e7e7 Mon Sep 17 00:00:00 2001 From: Michael Haigh Date: Fri, 15 Mar 2024 14:47:49 -0400 Subject: [PATCH] modifying ssl_verify disabling Signed-off-by: Michael Haigh --- astraSDK/common.py | 12 ++++++-- astraSDK/k8s.py | 70 ++++++++++++++++++++++++++-------------------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/astraSDK/common.py b/astraSDK/common.py index 67c3fc4..6840d23 100644 --- a/astraSDK/common.py +++ b/astraSDK/common.py @@ -248,8 +248,13 @@ def printVerbose(self, url, method, headers, data, params): class KubeCommon(BaseCommon): - def __init__(self, config_context=None, silently_fail=False): + def __init__(self, config_context=None, client_configuration=None, silently_fail=False): super().__init__() + if ( + isinstance(client_configuration, kubernetes.client.configuration.Configuration) + and client_configuration.verify_ssl is False + ): + disable_warnings() # Setup the config_file and context based on the config_context input config_file, context = None, None @@ -278,9 +283,10 @@ def __init__(self, config_context=None, silently_fail=False): config_file = config_context try: # Create the api_client - self.api_client = kubernetes.config.new_client_from_config( - config_file=config_file, context=context + kubernetes.config.load_kube_config( + config_file=config_file, context=context, client_configuration=client_configuration ) + self.api_client = kubernetes.client.ApiClient(configuration=client_configuration) # If that fails, then try an incluster config except kubernetes.config.config_exception.ConfigException as err: diff --git a/astraSDK/k8s.py b/astraSDK/k8s.py index 24c0d23..30d1653 100644 --- a/astraSDK/k8s.py +++ b/astraSDK/k8s.py @@ -46,9 +46,10 @@ def __init__( self.output = output self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main( self, @@ -290,9 +291,10 @@ def __init__( self.output = output self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main( self, @@ -355,9 +357,10 @@ def __init__( self.dry_run = dry_run self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main( self, @@ -415,9 +418,10 @@ def __init__( self.dry_run = dry_run self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main( self, @@ -473,9 +477,10 @@ def __init__( self.dry_run = dry_run self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main( self, @@ -526,9 +531,10 @@ def __init__( self.output = output self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main(self, systemNS=None, nameFilter=None, unassociated=False, minuteFilter=False): """Default behavior (systemNS=None) is to remove typical system namespaces from the @@ -619,9 +625,10 @@ def __init__( self.output = output self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main(self, namespace="astra-connector"): api_instance = kubernetes.client.CoreV1Api(self.api_client) @@ -673,9 +680,10 @@ def __init__( self.dry_run = dry_run self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main(self, name, namespace="astra-connector"): api_instance = kubernetes.client.CoreV1Api(self.api_client) @@ -719,9 +727,10 @@ def __init__( self.output = output self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main(self): api_instance = kubernetes.client.StorageV1Api(self.api_client) @@ -766,9 +775,10 @@ def __init__( self.dry_run = dry_run self.verbose = verbose self.skip_tls_verify = skip_tls_verify - super().__init__(config_context=config_context) - self.api_client.configuration.debug = self.verbose - self.api_client.configuration.verify_ssl = not self.skip_tls_verify + self.conf = kubernetes.client.Configuration() + self.conf.debug = self.verbose + self.conf.verify_ssl = not self.skip_tls_verify + super().__init__(config_context=config_context, client_configuration=self.conf) def main(self, v1SecretObj, namespace="astra-connector"): api_instance = kubernetes.client.CoreV1Api(self.api_client)