Skip to content

Commit

Permalink
Merge pull request #2252 from Infisical/maidul-dhusduqwdhj
Browse files Browse the repository at this point in the history
Patch CLI auto select file vault
  • Loading branch information
maidul98 authored Aug 7, 2024
2 parents 68e05b7 + 79181a1 commit 09c6fcb
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions cli/packages/util/keyringwrapper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package util

import (
"encoding/base64"
"fmt"

"github.com/manifoldco/promptui"
Expand Down Expand Up @@ -32,18 +31,16 @@ func SetValueInKeyring(key, value string) error {
configFile, _ := GetConfigFile()

if configFile.VaultBackendPassphrase == "" {
PrintWarning("System keyring could not be used, falling back to `file` vault for sensitive data storage.")
passphrasePrompt := promptui.Prompt{
Label: "Enter the passphrase to use for keyring encryption",
Label: "Enter a passphrase to encrypt sensitive CLI data at rest",
}
passphrase, err := passphrasePrompt.Run()
if err != nil {
return err
}

encodedPassphrase := base64.StdEncoding.EncodeToString([]byte(passphrase))
configFile.VaultBackendPassphrase = encodedPassphrase
err = WriteConfigFile(&configFile)
configFile.VaultBackendType = VAULT_BACKEND_FILE_MODE
if err != nil {
return err
}
Expand All @@ -65,12 +62,7 @@ func GetValueInKeyring(key string) (string, error) {
PrintErrorAndExit(1, err, "Unable to get current vault. Tip: run [infisical reset] then try again")
}

value, err := keyring.Get(currentVaultBackend, MAIN_KEYRING_SERVICE, key)

if err != nil {
value, err = keyring.Get(VAULT_BACKEND_FILE_MODE, MAIN_KEYRING_SERVICE, key)
}
return value, err
return keyring.Get(currentVaultBackend, MAIN_KEYRING_SERVICE, key)

}

Expand All @@ -80,11 +72,6 @@ func DeleteValueInKeyring(key string) error {
return err
}

err = keyring.Delete(currentVaultBackend, MAIN_KEYRING_SERVICE, key)
return keyring.Delete(currentVaultBackend, MAIN_KEYRING_SERVICE, key)

if err != nil {
err = keyring.Delete(VAULT_BACKEND_FILE_MODE, MAIN_KEYRING_SERVICE, key)
}

return err
}

0 comments on commit 09c6fcb

Please sign in to comment.