@@ -104,11 +104,26 @@ def _cleanup_credentials(self):
104104 self .credential_manager .delete ()
105105
106106 def logout (self ):
107+ # if dealing with a token there is no concept of logout
107108 if self .token :
108109 raise click .ClickException ('Logout not available when using an API token.' )
109- self .login ()
110- self .b .delete (f'https://{ Britive .parse_tenant (self .tenant_name )} /api/auth' )
111- self ._cleanup_credentials ()
110+
111+ self .tenant_name = self .config .get_tenant ()['name' ]
112+ self .tenant_alias = self .config .alias
113+ self .set_credential_manager ()
114+
115+ # let's see if we have credentials for this tenant already
116+ # if we do we need to invalidate them at the tenant and clean them up on the client side
117+ # if we don't have valid credentials for the tenant then there is no need to logout
118+ if self .credential_manager .has_valid_credentials ():
119+
120+ self .b = Britive (
121+ tenant = self .tenant_name ,
122+ token = self .credential_manager .get_token (),
123+ query_features = False
124+ )
125+ self .b .delete (f'https://{ Britive .parse_tenant (self .tenant_name )} /api/auth' )
126+ self ._cleanup_credentials ()
112127
113128 def debug (self , data : object , ignore_silent : bool = False ):
114129 if debug_enabled :
@@ -183,11 +198,11 @@ def user(self):
183198 output = f'{ username } @ { self .tenant_name } '
184199 if alias != self .tenant_name :
185200 output += f' (alias: { alias } )'
186- self .print (output )
201+ self .print (output , ignore_silent = True )
187202
188203 def list_secrets (self ):
189204 self .login ()
190- self .print (self .b .my_secrets .list ())
205+ self .print (self .b .my_secrets .list (), ignore_silent = True )
191206
192207 def list_profiles (self , checked_out : bool = False ):
193208 self .login ()
@@ -219,7 +234,7 @@ def list_profiles(self, checked_out: bool = False):
219234 if self .output_format == 'list' :
220235 self .output_format = 'list-profiles'
221236
222- self .print (data )
237+ self .print (data , ignore_silent = True )
223238
224239 # and set it back
225240 if self .output_format == 'list-profiles' :
@@ -242,7 +257,7 @@ def list_applications(self):
242257
243258 }
244259 data .append (row )
245- self .print (data )
260+ self .print (data , ignore_silent = True )
246261
247262 def list_environments (self ):
248263 self .login ()
@@ -262,7 +277,7 @@ def list_environments(self):
262277 'Type' : env ['app_type' ]
263278 }
264279 data .append (row )
265- self .print (data )
280+ self .print (data , ignore_silent = True )
266281
267282 def _set_available_profiles (self ):
268283 if not self .available_profiles :
@@ -555,7 +570,7 @@ def viewsecret(self, path, blocktime, justification, maxpolltime):
555570 pass
556571
557572 # and finally print the secret data
558- self .print (value )
573+ self .print (value , ignore_silent = True )
559574
560575 def downloadsecret (self , path , blocktime , justification , maxpolltime , file ):
561576 self ._validate_justification (justification )
@@ -578,7 +593,7 @@ def downloadsecret(self, path, blocktime, justification, maxpolltime, file):
578593
579594 if file == '-' :
580595 try :
581- self .print (content .decode ('utf-8' ))
596+ self .print (content .decode ('utf-8' ), ignore_silent = True )
582597 except UnicodeDecodeError as e :
583598 raise click .ClickException (
584599 'Secret file contents cannot be decoded to utf-8. '
@@ -707,7 +722,7 @@ def api(self, method, parameters={}, query=None):
707722 pass
708723
709724 # output the response, optionally filtering based on provided jmespath query/search
710- self .print (jmespath .search (query , response ) if query else response )
725+ self .print (jmespath .search (query , response ) if query else response , ignore_silent = True )
711726
712727 # yes - this method exits in b.my_access as _get_profile_and_environment_ids_given_names
713728 # but we are doing additional business logic here to enhance the cli experience so there is
0 commit comments