Skip to content

Commit

Permalink
modifying ssl_verify disabling
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Haigh <[email protected]>
  • Loading branch information
MichaelHaigh committed Mar 15, 2024
1 parent 22abb16 commit aa82364
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
12 changes: 9 additions & 3 deletions astraSDK/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
70 changes: 40 additions & 30 deletions astraSDK/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit aa82364

Please sign in to comment.