Skip to content

Commit

Permalink
Merge pull request #2147 from allmightyspiff/emploginupdates
Browse files Browse the repository at this point in the history
Emploginupdates
  • Loading branch information
allmightyspiff authored May 10, 2024
2 parents 6ce7991 + c753641 commit 0c6520b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
17 changes: 11 additions & 6 deletions SoftLayer/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions SoftLayer/CLI/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -31,7 +30,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'):
Expand All @@ -49,7 +48,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: ")
Expand Down
9 changes: 8 additions & 1 deletion SoftLayer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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
elif isinstance(r_config["verify"], str):
os.environ['SSL_CERT_FILE'] = r_config["verify"]
return r_config


SETTING_RESOLVERS = [get_client_settings_args,
Expand Down

0 comments on commit 0c6520b

Please sign in to comment.