55import click
66
77import SoftLayer
8- from SoftLayer import auth
98from SoftLayer .CLI import config
109from SoftLayer .CLI import environment
1110from SoftLayer .CLI import exceptions
@@ -22,7 +21,6 @@ def get_api_key(client, username, secret):
2221 # Try to use a client with username/api key
2322 if len (secret ) == 64 :
2423 try :
25- client .auth = auth .BasicAuthentication (username , secret )
2624 client ['Account' ].getCurrentUser ()
2725 return secret
2826 except SoftLayer .SoftLayerAPIError as ex :
@@ -32,12 +30,10 @@ def get_api_key(client, username, secret):
3230 # Try to use a client with username/password
3331 client .authenticate_with_password (username , secret )
3432
35- user_record = client ['Account' ].getCurrentUser (
36- mask = 'id, apiAuthenticationKeys' )
33+ user_record = client ['Account' ].getCurrentUser (mask = 'id, apiAuthenticationKeys' )
3734 api_keys = user_record ['apiAuthenticationKeys' ]
3835 if len (api_keys ) == 0 :
39- return client ['User_Customer' ].addApiAuthenticationKey (
40- id = user_record ['id' ])
36+ return client ['User_Customer' ].addApiAuthenticationKey (id = user_record ['id' ])
4137 return api_keys [0 ]['authenticationKey' ]
4238
4339
@@ -47,9 +43,8 @@ def cli(env):
4743 """Edit configuration."""
4844
4945 username , secret , endpoint_url , timeout = get_user_input (env )
50-
51- env .client .transport .transport .endpoint_url = endpoint_url
52- api_key = get_api_key (env .client , username , secret )
46+ new_client = SoftLayer .Client (username = username , api_key = secret , endpoint_url = endpoint_url , timeout = timeout )
47+ api_key = get_api_key (new_client , username , secret )
5348
5449 path = '~/.softlayer'
5550 if env .config_file :
@@ -103,17 +98,20 @@ def get_user_input(env):
10398 secret = env .getpass ('API Key or Password' , default = defaults ['api_key' ])
10499
105100 # Ask for which endpoint they want to use
101+ endpoint = defaults .get ('endpoint_url' , 'public' )
106102 endpoint_type = env .input (
107- 'Endpoint (public|private|custom)' , default = 'public' )
103+ 'Endpoint (public|private|custom)' , default = endpoint )
108104 endpoint_type = endpoint_type .lower ()
109105
110- if endpoint_type == 'custom' :
111- endpoint_url = env .input ('Endpoint URL' ,
112- default = defaults ['endpoint_url' ])
106+ if endpoint_type == 'public' :
107+ endpoint_url = SoftLayer .API_PUBLIC_ENDPOINT
113108 elif endpoint_type == 'private' :
114109 endpoint_url = SoftLayer .API_PRIVATE_ENDPOINT
115110 else :
116- endpoint_url = SoftLayer .API_PUBLIC_ENDPOINT
111+ if endpoint_type == 'custom' :
112+ endpoint_url = env .input ('Endpoint URL' , default = endpoint )
113+ else :
114+ endpoint_url = endpoint_type
117115
118116 # Ask for timeout
119117 timeout = env .input ('Timeout' , default = defaults ['timeout' ] or 0 )
0 commit comments