66 :license: MIT, see LICENSE for more details.
77"""
88# pylint: disable=invalid-name
9+ import os
910import time
1011import warnings
1112
@@ -144,7 +145,8 @@ def create_client_from_env(username=None,
144145
145146
146147def employee_client (username = None ,
147- api_key = None ,
148+ access_token = None ,
149+ password = None ,
148150 endpoint_url = None ,
149151 timeout = None ,
150152 auth = None ,
@@ -159,7 +161,8 @@ def employee_client(username=None,
159161 config file.
160162
161163 :param username: your user ID
162- :param api_key: hash from SoftLayer_User_Employee::performExternalAuthentication(username, password, 2fa_string)
164+ :param access_token: hash from SoftLayer_User_Employee::performExternalAuthentication(username, password, 2fa_string)
165+ :param password: password to use for employee authentication
163166 :param endpoint_url: the API endpoint base URL you wish to connect to.
164167 Set this to API_PRIVATE_ENDPOINT to connect via SoftLayer's private
165168 network.
@@ -185,15 +188,21 @@ def employee_client(username=None,
185188
186189 """
187190 settings = config .get_client_settings (username = username ,
188- api_key = api_key ,
191+ api_key = None ,
189192 endpoint_url = endpoint_url ,
190193 timeout = timeout ,
191194 proxy = proxy ,
192195 verify = verify ,
193196 config_file = config_file )
194197
198+ url = settings .get ('endpoint_url' ) or consts .API_EMPLOYEE_ENDPOINT
199+
200+ if 'internal' not in url :
201+ raise exceptions .SoftLayerError ("{} does not look like an Internal Employee url. Try {}" .format (
202+ url , consts .API_EMPLOYEE_ENDPOINT ))
203+
195204 if transport is None :
196- url = settings . get ( 'endpoint_url' )
205+
197206 if url is not None and '/rest' in url :
198207 # If this looks like a rest endpoint, use the rest transport
199208 transport = transports .RestTransport (
@@ -214,24 +223,26 @@ def employee_client(username=None,
214223 )
215224
216225
217- if auth is None and settings .get ('username' ) and settings .get ('api_key' ):
218- real_transport = getattr (transport , 'transport' , transport )
219- if isinstance (real_transport , transports .XmlRpcTransport ):
220- auth = slauth .EmployeeAuthentication (
221- settings .get ('username' ),
222- settings .get ('api_key' ),
223- )
226+ if access_token is None :
227+ access_token = settings .get ('access_token' )
228+
229+ user_id = settings .get ('user_id' )
230+
231+ # Assume access_token is valid for now, user has logged in before at least.
232+ if access_token and user_id :
233+ auth = slauth .EmployeeAuthentication (user_id , access_token )
234+ return EmployeeClient (auth = auth , transport = transport )
235+ else :
236+ return EmployeeClient (auth = None , transport = transport )
224237
225- return BaseClient (auth = auth , transport = transport )
226238
227239
228240def Client (** kwargs ):
229241 """Get a SoftLayer API Client using environmental settings.
230242
231243 Deprecated in favor of create_client_from_env()
232244 """
233- warnings .warn ("use SoftLayer.create_client_from_env() instead" ,
234- DeprecationWarning )
245+ warnings .warn ("use SoftLayer.create_client_from_env() instead" , DeprecationWarning )
235246 return create_client_from_env (** kwargs )
236247
237248
0 commit comments