Update keyringwrapper.go

This commit is contained in:
Daniel Hougaard
2024-07-29 12:31:02 +02:00
parent 91cee20cc8
commit 2b630f75aa

View File

@@ -1,7 +1,12 @@
package util
import (
"encoding/base64"
"fmt"
"os"
"github.com/zalando/go-keyring"
"golang.org/x/term"
)
const MAIN_KEYRING_SERVICE = "infisical-cli"
@@ -23,7 +28,26 @@ func SetValueInKeyring(key, value string) error {
err = keyring.Set(currentVaultBackend, MAIN_KEYRING_SERVICE, key, value)
if err != nil {
configFile, _ := GetConfigFile()
PrintWarning("Fallback file keyring is being used\n\nYou can persist your file passphrase by running the following command:\ninfisical vault set file --passphrase <your-passphrase>\n")
if configFile.VaultBackendPassphrase == "" {
fmt.Print("\n\nEnter the passphrase to use for keyring encryption: ")
bytePassphrase, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return err
}
encodedPassphrase := base64.StdEncoding.EncodeToString([]byte(string(bytePassphrase)))
configFile.VaultBackendPassphrase = encodedPassphrase
err = WriteConfigFile(&configFile)
if err != nil {
return err
}
// We call this function at last to trigger the environment variable to be set
GetConfigFile()
}
err = keyring.Set(VAULT_BACKEND_FILE_MODE, MAIN_KEYRING_SERVICE, key, value)
}