66 :license: MIT, see LICENSE for more details.
77"""
88# pylint: disable=invalid-name
9- import os
109import time
11- import warnings
1210
1311import concurrent .futures as cf
1412import json
@@ -148,7 +146,6 @@ def create_client_from_env(username=None,
148146
149147def employee_client (username = None ,
150148 access_token = None ,
151- password = None ,
152149 endpoint_url = None ,
153150 timeout = None ,
154151 auth = None ,
@@ -159,27 +156,22 @@ def employee_client(username=None,
159156 verify = False ):
160157 """Creates an INTERNAL SoftLayer API client using your environment.
161158
162- Settings are loaded via keyword arguments, environemtal variables and
163- config file.
159+ Settings are loaded via keyword arguments, environemtal variables and config file.
164160
165161 :param username: your user ID
166- :param access_token: hash from SoftLayer_User_Employee::performExternalAuthentication(username, password, 2fa_string )
162+ :param access_token: hash from SoftLayer_User_Employee::performExternalAuthentication(username, password, token )
167163 :param password: password to use for employee authentication
168164 :param endpoint_url: the API endpoint base URL you wish to connect to.
169- Set this to API_PRIVATE_ENDPOINT to connect via SoftLayer's private
170- network.
165+ Set this to API_PRIVATE_ENDPOINT to connect via SoftLayer's private network.
171166 :param proxy: proxy to be used to make API calls
172167 :param integer timeout: timeout for API requests
173- :param auth: an object which responds to get_headers() to be inserted into
174- the xml-rpc headers. Example: `BasicAuthentication`
168+ :param auth: an object which responds to get_headers() to be inserted into the xml-rpc headers.
169+ Example: `BasicAuthentication`
175170 :param config_file: A path to a configuration file used to load settings
176171 :param user_agent: an optional User Agent to report when making API
177172 calls if you wish to bypass the packages built in User Agent string
178- :param transport: An object that's callable with this signature:
179- transport(SoftLayer.transports.Request)
180- :param bool verify: decide to verify the server's SSL/TLS cert. DO NOT SET
181- TO FALSE WITHOUT UNDERSTANDING THE IMPLICATIONS.
182-
173+ :param transport: An object that's callable with this signature: transport(SoftLayer.transports.Request)
174+ :param bool verify: decide to verify the server's SSL/TLS cert.
183175 """
184176 settings = config .get_client_settings (username = username ,
185177 api_key = None ,
@@ -214,7 +206,6 @@ def employee_client(username=None,
214206 verify = verify ,
215207 )
216208
217-
218209 if access_token is None :
219210 access_token = settings .get ('access_token' )
220211
@@ -241,16 +232,23 @@ class BaseClient(object):
241232 :param auth: auth driver that looks like SoftLayer.auth.AuthenticationBase
242233 :param transport: An object that's callable with this signature: transport(SoftLayer.transports.Request)
243234 """
244-
245235 _prefix = "SoftLayer_"
236+ auth : slauth .AuthenticationBase
246237
247238 def __init__ (self , auth = None , transport = None , config_file = None ):
248239 if config_file is None :
249240 config_file = CONFIG_FILE
250- self .auth = auth
251241 self .config_file = config_file
252242 self .settings = config .get_config (self .config_file )
243+ self .__setAuth (auth )
244+ self .__setTransport (transport )
245+
246+ def __setAuth (self , auth = None ):
247+ """Prepares the authentication property"""
248+ self .auth = auth
253249
250+ def __setTransport (self , transport = None ):
251+ """Prepares the transport property"""
254252 if transport is None :
255253 url = self .settings ['softlayer' ].get ('endpoint_url' )
256254 if url is not None and '/rest' in url :
@@ -469,6 +467,7 @@ def __repr__(self):
469467 def __len__ (self ):
470468 return 0
471469
470+
472471class CertificateClient (BaseClient ):
473472 """Client that works with a X509 Certificate for authentication.
474473
@@ -479,42 +478,20 @@ class CertificateClient(BaseClient):
479478 """
480479
481480 def __init__ (self , auth = None , transport = None , config_file = None ):
482- if config_file is None :
483- config_file = CONFIG_FILE
484- self .config_file = config_file
485- self .settings = config .get_config (self .config_file )
481+ BaseClient .__init__ (self , auth , transport , config_file )
482+ self .__setAuth (auth )
486483
484+ def __setAuth (self , auth = None ):
485+ """Prepares the authentication property"""
487486 if auth is None :
488487 auth_cert = self .settings ['softlayer' ].get ('auth_cert' )
489488 serv_cert = self .settings ['softlayer' ].get ('server_cert' , None )
490489 auth = slauth .X509Authentication (auth_cert , serv_cert )
491- self .auth = auth
492-
493-
490+ self .auth = auth
494491
495- if transport is None :
496- url = self .settings ['softlayer' ].get ('endpoint_url' )
497- if url is not None and '/rest' in url :
498- # If this looks like a rest endpoint, use the rest transport
499- transport = transports .RestTransport (
500- endpoint_url = url ,
501- proxy = self .settings ['softlayer' ].get ('proxy' ),
502- # prevents an exception incase timeout is a float number.
503- timeout = int (self .settings ['softlayer' ].getfloat ('timeout' , 0 )),
504- user_agent = consts .USER_AGENT ,
505- verify = self .settings ['softlayer' ].getboolean ('verify' ),
506- )
507- else :
508- # Default the transport to use XMLRPC
509- transport = transports .XmlRpcTransport (
510- endpoint_url = url ,
511- proxy = self .settings ['softlayer' ].get ('proxy' ),
512- timeout = int (self .settings ['softlayer' ].getfloat ('timeout' , 0 )),
513- user_agent = consts .USER_AGENT ,
514- verify = self .settings ['softlayer' ].getboolean ('verify' ),
515- )
492+ def __repr__ (self ):
493+ return "CertificateClient(transport=%r, auth=%r)" % (self .transport , self .auth )
516494
517- self .transport = transport
518495
519496class IAMClient (BaseClient ):
520497 """IBM ID Client for using IAM authentication
@@ -711,9 +688,8 @@ def __init__(self, auth=None, transport=None, config_file=None, account_id=None)
711688 BaseClient .__init__ (self , auth , transport , config_file )
712689 self .account_id = account_id
713690
714-
715- def authenticate_with_password (self , username , password , security_token = None ):
716- """Performs IBM IAM Username/Password Authentication
691+ def authenticate_with_internal (self , username , password , security_token = None ):
692+ """Performs internal authentication
717693
718694 :param string username: your softlayer username
719695 :param string password: your softlayer password
@@ -724,12 +700,11 @@ def authenticate_with_password(self, username, password, security_token=None):
724700 if security_token is None :
725701 security_token = input ("Enter your 2FA Token now: " )
726702 if len (security_token ) != 6 :
727- raise Exception ("Invalid security token: {}" .format (security_token ))
703+ raise exceptions . SoftLayerAPIError ("Invalid security token: {}" .format (security_token ))
728704
729705 auth_result = self .call ('SoftLayer_User_Employee' , 'performExternalAuthentication' ,
730706 username , password , security_token )
731707
732-
733708 self .settings ['softlayer' ]['access_token' ] = auth_result ['hash' ]
734709 self .settings ['softlayer' ]['userid' ] = str (auth_result ['userId' ])
735710 # self.settings['softlayer']['refresh_token'] = tokens['refresh_token']
@@ -739,8 +714,6 @@ def authenticate_with_password(self, username, password, security_token=None):
739714
740715 return auth_result
741716
742-
743-
744717 def authenticate_with_hash (self , userId , access_token ):
745718 """Authenticates to the Internal SL API with an employee userid + token
746719
@@ -791,6 +764,7 @@ def call(self, service, method, *args, **kwargs):
791764 def __repr__ (self ):
792765 return "EmployeeClient(transport=%r, auth=%r)" % (self .transport , self .auth )
793766
767+
794768class Service (object ):
795769 """A SoftLayer Service.
796770
0 commit comments