@@ -28,10 +28,36 @@ def cli(env):
2828 username: Set this in either the softlayer config, or SL_USER ENV variable
2929 password: Set this in SL_PASSWORD env variable. You will be prompted for them otherwise.
3030 """
31- settings = config .get_config (config_file = env .config_file )
32- username = settings .get ('username' ) or os .environ .get ('SLCLI_USER' )
31+ config_settings = config .get_config (config_file = env .config_file )
32+ settings = config_settings ['softlayer' ]
33+ username = settings .get ('username' ) or os .environ .get ('SLCLI_USER' , None )
3334 password = os .environ .get ('SLCLI_PASSWORD' , '' )
34- yubi = 123456
35+ yubi = None
36+ # client = EmployeeClient(config_file=env.config_file)
37+ client = env .client
38+
39+ # Might already be logged in, try and refresh token
40+ if settings .get ('access_token' ) and settings .get ('userid' ):
41+ client .authenticate_with_hash (settings .get ('userid' ), settings .get ('access_token' ))
42+ try :
43+ employee = client .call ('SoftLayer_User_Employee' , 'getObject' , id = settings .get ('userid' ), mask = "mask[id,username]" )
44+ print (employee )
45+ refresh = client .call ('SoftLayer_User_Employee' , 'refreshEncryptedToken' , settings .get ('access_token' ), id = settings .get ('userid' ))
46+ print ("REFRESH:\n {}\n " .format (refresh ))
47+ # we expect 2 results, a hash and a timeout
48+ if len (refresh ) > 1 :
49+ for returned_data in refresh :
50+ # Access tokens should be 188 characters, but just incase.
51+ if len (returned_data ) > 180 :
52+ settings ['access_token' ] = returned_data
53+ else :
54+ raise Exception ("Got unexpected data. Expected 2 properties: {}" .format (refresh ))
55+ config_settings ['softlayer' ] = settings
56+ config .write_config (config_settings , env .config_file )
57+ return
58+ except Exception as ex :
59+ print ("Error with Hash, try with password: {}" .format (ex ))
60+
3561
3662 url = settings .get ('endpoint_url' ) or consts .API_EMPLOYEE_ENDPOINT
3763 click .echo ("URL: {}" .format (url ))
@@ -41,11 +67,12 @@ def cli(env):
4167 if password is None :
4268 password = env .getpass ("Password: " )
4369 click .echo ("Password: {}" .format (censor_password (password )))
44- # yubi = input("Yubi: ")
70+ yubi = input ("Yubi: " )
4571
46- client = EmployeeClient ( config_file = env . config_file )
72+
4773 try :
48- client .authenticate_with_password (username , password , yubi )
74+ result = client .authenticate_with_password (username , password , str (yubi ))
75+ print (result )
4976 except Exception as e :
5077 click .echo ("EXCEPTION: {}" .format (e ))
5178
0 commit comments