mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Update keyringwrapper.go
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user