From 1e8725ddef23655217d2f7fddc5b81746a228782 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Thu, 9 May 2024 18:15:56 -0500 Subject: [PATCH 1/3] Fixed a few bugs when reading from a custom config file --- SoftLayer/API.py | 13 +++++++++---- SoftLayer/CLI/login.py | 4 ++-- SoftLayer/config.py | 9 ++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/SoftLayer/API.py b/SoftLayer/API.py index dc24914fe..42c3709d5 100644 --- a/SoftLayer/API.py +++ b/SoftLayer/API.py @@ -191,7 +191,7 @@ def employee_client(username=None, if url is not None and '/rest' in url: # If this looks like a rest endpoint, use the rest transport transport = transports.RestTransport( - endpoint_url=settings.get('endpoint_url'), + endpoint_url=url, proxy=settings.get('proxy'), timeout=settings.get('timeout'), user_agent=user_agent, @@ -200,7 +200,7 @@ def employee_client(username=None, else: # Default the transport to use XMLRPC transport = transports.XmlRpcTransport( - endpoint_url=settings.get('endpoint_url'), + endpoint_url=url, proxy=settings.get('proxy'), timeout=settings.get('timeout'), user_agent=user_agent, @@ -250,6 +250,11 @@ def __setAuth(self, auth=None): def __setTransport(self, transport=None): """Prepares the transport property""" + verify = self.settings['softlayer'].get('verify') + if verify == "False": + verify = False + elif verify == "True": + verify = True if transport is None: url = self.settings['softlayer'].get('endpoint_url') if url is not None and '/rest' in url: @@ -260,7 +265,7 @@ def __setTransport(self, transport=None): # prevents an exception incase timeout is a float number. timeout=int(self.settings['softlayer'].getfloat('timeout', 0)), user_agent=consts.USER_AGENT, - verify=self.settings['softlayer'].getboolean('verify'), + verify=verify, ) else: # Default the transport to use XMLRPC @@ -269,7 +274,7 @@ def __setTransport(self, transport=None): proxy=self.settings['softlayer'].get('proxy'), timeout=int(self.settings['softlayer'].getfloat('timeout', 0)), user_agent=consts.USER_AGENT, - verify=self.settings['softlayer'].getboolean('verify'), + verify=verify, ) self.transport = transport diff --git a/SoftLayer/CLI/login.py b/SoftLayer/CLI/login.py index 7f3e76e35..c088873b3 100644 --- a/SoftLayer/CLI/login.py +++ b/SoftLayer/CLI/login.py @@ -31,7 +31,7 @@ def cli(env): username = settings.get('username') or os.environ.get('SLCLI_USER', None) password = os.environ.get('SLCLI_PASSWORD', '') yubi = None - client = employee_client() + client = employee_client(config_file=env.config_file) # Might already be logged in, try and refresh token if settings.get('access_token') and settings.get('userid'): @@ -49,7 +49,7 @@ def cli(env): except Exception as ex: print("Error with Hash Authentication, try with password: {}".format(ex)) - url = settings.get('endpoint_url') or consts.API_EMPLOYEE_ENDPOINT + url = settings.get('endpoint_url') click.echo("URL: {}".format(url)) if username is None: username = input("Username: ") diff --git a/SoftLayer/config.py b/SoftLayer/config.py index c32c0b5e1..c3ae5d5a0 100644 --- a/SoftLayer/config.py +++ b/SoftLayer/config.py @@ -66,7 +66,7 @@ def get_client_settings_config_file(**kwargs): # pylint: disable=inconsistent-r config.read(config_files) if config.has_section('softlayer'): - return { + r_config = { 'endpoint_url': config.get('softlayer', 'endpoint_url'), 'timeout': config.getfloat('softlayer', 'timeout'), 'proxy': config.get('softlayer', 'proxy'), @@ -76,6 +76,13 @@ def get_client_settings_config_file(**kwargs): # pylint: disable=inconsistent-r 'access_token': config.get('softlayer', 'access_token'), 'verify': config.get('softlayer', 'verify') } + if r_config["verify"].lower() == "true": + r_config["verify"] = True + elif r_config["verify"].lower() == "false": + r_config["verify"] = False + else: + os.environ['SSL_CERT_FILE'] = r_config["verify"] + return r_config SETTING_RESOLVERS = [get_client_settings_args, From 97d34f7de6726364c42393d580c568121953f942 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Thu, 9 May 2024 18:31:53 -0500 Subject: [PATCH 2/3] Fixed a few config remembering issues --- SoftLayer/API.py | 4 ++-- SoftLayer/config.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SoftLayer/API.py b/SoftLayer/API.py index 42c3709d5..0a2788b63 100644 --- a/SoftLayer/API.py +++ b/SoftLayer/API.py @@ -215,11 +215,11 @@ def employee_client(username=None, # Assume access_token is valid for now, user has logged in before at least. if access_token and user_id: auth = slauth.EmployeeAuthentication(user_id, access_token) - return EmployeeClient(auth=auth, transport=transport) + return EmployeeClient(auth=auth, transport=transport, config_file=config_file) else: # This is for logging in mostly. LOGGER.info("No access_token or userid found in settings, creating a No Auth client for now.") - return EmployeeClient(auth=None, transport=transport) + return EmployeeClient(auth=None, transport=transport, config_file=config_file) def Client(**kwargs): diff --git a/SoftLayer/config.py b/SoftLayer/config.py index c3ae5d5a0..1cc9bb7a2 100644 --- a/SoftLayer/config.py +++ b/SoftLayer/config.py @@ -80,7 +80,7 @@ def get_client_settings_config_file(**kwargs): # pylint: disable=inconsistent-r r_config["verify"] = True elif r_config["verify"].lower() == "false": r_config["verify"] = False - else: + elif r_config["verify"]: os.environ['SSL_CERT_FILE'] = r_config["verify"] return r_config From c7536418cd3bc13fc389152daad5a17a7861998d Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Fri, 10 May 2024 09:53:40 -0500 Subject: [PATCH 3/3] Fixed tox issues --- SoftLayer/CLI/login.py | 1 - SoftLayer/config.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/SoftLayer/CLI/login.py b/SoftLayer/CLI/login.py index c088873b3..8ee981979 100644 --- a/SoftLayer/CLI/login.py +++ b/SoftLayer/CLI/login.py @@ -8,7 +8,6 @@ from SoftLayer.CLI.command import SLCommand as SLCommand from SoftLayer.CLI import environment from SoftLayer import config -from SoftLayer import consts def censor_password(value): diff --git a/SoftLayer/config.py b/SoftLayer/config.py index 1cc9bb7a2..97ccb9d0c 100644 --- a/SoftLayer/config.py +++ b/SoftLayer/config.py @@ -80,7 +80,7 @@ def get_client_settings_config_file(**kwargs): # pylint: disable=inconsistent-r r_config["verify"] = True elif r_config["verify"].lower() == "false": r_config["verify"] = False - elif r_config["verify"]: + elif isinstance(r_config["verify"], str): os.environ['SSL_CERT_FILE'] = r_config["verify"] return r_config