@@ -417,12 +417,17 @@ def info( # noqa: PLR0915
417417 "user_info" : {},
418418 "groups" : {},
419419 }
420+ client = initialize_client_sync ()
421+ fetch_user_details = client .config .username or client .config .api_token
422+
420423 try :
421- client = initialize_client_sync ()
422424 info ["infrahub_version" ] = client .get_version ()
423- info ["user_info" ] = client .get_user ()
425+
426+ if fetch_user_details :
427+ info ["user_info" ] = client .get_user ()
428+ info ["groups" ] = client .get_user_permissions ()
429+
424430 info ["status" ] = ":white_heavy_check_mark:"
425- info ["groups" ] = client .get_user_permissions ()
426431 except Exception as e :
427432 info ["error" ] = f"{ e !s} ({ e .__class__ .__name__ } )"
428433
@@ -469,7 +474,7 @@ def info( # noqa: PLR0915
469474 pretty_model = Pretty (client .config .model_dump (), expand_all = True )
470475 layout ["client_info" ].update (Panel (pretty_model , title = "Client Info" ))
471476
472- # Infrahub information planel
477+ # Infrahub information panel
473478 infrahub_info = Table (show_header = False , box = None )
474479 if info ["user_info" ]:
475480 infrahub_info .add_row ("User:" , info ["user_info" ]["AccountProfile" ]["display_label" ])
@@ -487,6 +492,8 @@ def info( # noqa: PLR0915
487492 infrahub_info .add_row ("Groups:" , "" )
488493 for group , roles in groups .items ():
489494 infrahub_info .add_row ("" , group , ", " .join (roles ))
495+ else :
496+ infrahub_info .add_row ("User:" , "anonymous" )
490497
491498 layout ["infrahub_info" ].update (Panel (infrahub_info , title = "Infrahub Info" ))
492499
0 commit comments