Skip to content

Commit

Permalink
tlock: vault: fix: Don't require validations on replace token if the …
Browse files Browse the repository at this point in the history
…secret is same
eklairs committed May 9, 2024
1 parent 876c64b commit f3787d4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tlock-vault/token_ext.go
Original file line number Diff line number Diff line change
@@ -67,14 +67,17 @@ func (vault *Vault) AddTokenFromToken(folder string, token Token) error {
func (vault *Vault) ReplaceToken(fromFolder string, token, newToken Token) error {
var err error

if newToken.Secret, err = vault.validateToken(newToken.Secret); err == nil {
if newToken.Secret, err = vault.validateToken(newToken.Secret); token.Secret == newToken.Secret || err == nil {
// Get folder index
if index := vault.findFolder(fromFolder); index != -1 {
// Replace
vault.Folders[index].Tokens[vault.findToken(index, token.Secret)] = newToken

// Write
vault.write()

// Ok!
return nil
}
}

@@ -163,7 +166,7 @@ func (vault *Vault) findToken(folder int, secret string) int {

// Checks if the token exists with a secret
func (vault *Vault) tokenExists(secret string) bool {
for i := 0; i <= len(vault.Folders); i++ {
for i := 0; i < len(vault.Folders); i++ {
if vault.findToken(i, secret) != -1 {
return true
}

0 comments on commit f3787d4

Please sign in to comment.