@@ -268,14 +268,14 @@ def show(ctx):
268268 """
269269 Show your config
270270 """
271- with StackletContext (ctx .obj ["config" ], ctx .obj ["raw_config" ]) as context :
272- fmt = Formatter .registry .get (ctx .obj ["output" ])()
273- if os .path .exists (os .path .expanduser (StackletContext .DEFAULT_ID )):
274- with open (os .path .expanduser (StackletContext .DEFAULT_ID ), "r" ) as f :
275- id_details = jwt .decode (f .read (), options = {"verify_signature" : False })
276- click .echo (fmt (id_details ))
277- click .echo ()
278- click .echo (fmt (context .config .to_json ()))
271+ context = StackletContext (ctx .obj ["config" ], ctx .obj ["raw_config" ])
272+ fmt = Formatter .registry .get (ctx .obj ["output" ])()
273+ if os .path .exists (os .path .expanduser (StackletContext .DEFAULT_ID )):
274+ with open (os .path .expanduser (StackletContext .DEFAULT_ID ), "r" ) as f :
275+ id_details = jwt .decode (f .read (), options = {"verify_signature" : False })
276+ click .echo (fmt (id_details ))
277+ click .echo ()
278+ click .echo (fmt (context .config .to_json ()))
279279
280280
281281@cli .command (short_help = "Login to Stacklet" )
@@ -295,40 +295,38 @@ def login(ctx, username, password):
295295
296296 If password is not passed in, your password will be prompted
297297 """
298- with StackletContext (ctx .obj ["config" ], ctx .obj ["raw_config" ]) as context :
299- # sso login
300- if context .can_sso_login () and not any ([username , password ]):
301- from stacklet .client .platform .vendored .auth import BrowserAuthenticator
302-
303- BrowserAuthenticator (
304- authority_url = context .config .auth_url ,
305- client_id = context .config .cognito_client_id ,
306- idp_id = context .config .idp_id ,
307- )()
308- return
309- elif not context .can_sso_login () and not any ([username , password ]):
310- click .echo (
311- "To login with SSO ensure that your configuration includes "
312- + "auth_url, and cognito_client_id values."
313- )
314- raise Exception ()
315-
316- # handle login with username/password
317- if not username :
318- username = click .prompt ("Username" )
319- if not password :
320- password = click .prompt ("Password" , hide_input = True )
321- manager = CognitoUserManager .from_context (context )
322- res = manager .login (
323- user = username ,
324- password = password ,
298+ context = StackletContext (ctx .obj ["config" ], ctx .obj ["raw_config" ])
299+ # sso login
300+ if context .can_sso_login () and not any ([username , password ]):
301+ from stacklet .client .platform .vendored .auth import BrowserAuthenticator
302+
303+ BrowserAuthenticator (
304+ authority_url = context .config .auth_url ,
305+ client_id = context .config .cognito_client_id ,
306+ idp_id = context .config .idp_id ,
307+ )()
308+ return
309+ elif not context .can_sso_login () and not any ([username , password ]):
310+ click .echo (
311+ "To login with SSO ensure that your configuration includes "
312+ + "auth_url, and cognito_client_id values."
325313 )
326- if not os .path .exists (
327- os .path .dirname (os .path .expanduser (StackletContext .DEFAULT_CREDENTIALS ))
328- ):
329- os .makedirs (os .path .dirname (os .path .expanduser (StackletContext .DEFAULT_CREDENTIALS )))
330- with open (os .path .expanduser (StackletContext .DEFAULT_CREDENTIALS ), "w+" ) as f : # noqa
331- f .write (res )
314+ raise Exception ()
315+
316+ # handle login with username/password
317+ if not username :
318+ username = click .prompt ("Username" )
319+ if not password :
320+ password = click .prompt ("Password" , hide_input = True )
321+ manager = CognitoUserManager .from_context (context )
322+ res = manager .login (
323+ user = username ,
324+ password = password ,
325+ )
326+ if not os .path .exists (os .path .dirname (os .path .expanduser (StackletContext .DEFAULT_CREDENTIALS ))):
327+ os .makedirs (os .path .dirname (os .path .expanduser (StackletContext .DEFAULT_CREDENTIALS )))
328+ with open (os .path .expanduser (StackletContext .DEFAULT_CREDENTIALS ), "w+" ) as f : # noqa
329+ f .write (res )
332330
333331
334332for c in commands :
0 commit comments