@@ -212,6 +212,17 @@ func (sc *SetupConfig) newMFASession() (*session.Session, error) {
212
212
return mfaSession , nil
213
213
}
214
214
215
+ func (sc * SetupConfig ) deleteSession (profile string ) error {
216
+ credsKeyring := vault.CredentialKeyring {Keyring : * sc .Keyring }
217
+ sessions := credsKeyring .Sessions ()
218
+
219
+ if n , _ := sessions .Delete (profile ); n > 0 {
220
+ sc .Logger .Printf ("Deleted %d existing sessions.\n " , n )
221
+ }
222
+
223
+ return nil
224
+ }
225
+
215
226
// GetMFADevice gets the user's existing virtual MFA device and updates the
216
227
// MFA serial in the profile field.
217
228
func (sc * SetupConfig ) GetMFADevice () error {
@@ -383,7 +394,7 @@ func (sc *SetupConfig) AddVaultProfile() error {
383
394
384
395
sc .Logger .Printf ("Added credentials to profile %q in vault" , sc .BaseProfileName )
385
396
386
- err := deleteSession (sc .BaseProfileName , sc . Keyring , sc . Logger )
397
+ err := sc . deleteSession (sc .BaseProfileName )
387
398
if err != nil {
388
399
return fmt .Errorf ("unable to delete session: %w" , err )
389
400
}
@@ -443,7 +454,7 @@ func (sc *SetupConfig) UpdateAWSConfigFile() error {
443
454
// RemoveVaultSession removes the aws-vault session for the profile.
444
455
func (sc * SetupConfig ) RemoveVaultSession () error {
445
456
sc .Logger .Printf ("Removing aws-vault session" )
446
- err := deleteSession (sc .BaseProfile .Name , sc . Keyring , sc . Logger )
457
+ err := sc . deleteSession (sc .BaseProfile .Name )
447
458
if err != nil {
448
459
return fmt .Errorf ("unable to delete session: %w" , err )
449
460
}
0 commit comments