diff --git a/cmd/sops/main.go b/cmd/sops/main.go index 2c1a2b32c..6d45ef485 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -40,6 +40,7 @@ import ( "github.com/getsops/sops/v3/kms" "github.com/getsops/sops/v3/logging" "github.com/getsops/sops/v3/pgp" + "github.com/getsops/sops/v3/stores" "github.com/getsops/sops/v3/stores/dotenv" "github.com/getsops/sops/v3/stores/json" "github.com/getsops/sops/v3/version" @@ -255,7 +256,7 @@ func main() { } value, ok := item.Value.(string) if !ok { - return cli.NewExitError(fmt.Errorf("cannot use non-string values in environment, got %T", item.Value), codes.ErrorGeneric) + value = stores.ValToString(item.Value) } env = append(env, fmt.Sprintf("%s=%s", key, value)) } diff --git a/stores/dotenv/store.go b/stores/dotenv/store.go index 1e533341e..c6ec8b505 100644 --- a/stores/dotenv/store.go +++ b/stores/dotenv/store.go @@ -141,7 +141,13 @@ func (store *Store) EmitPlainFile(in sops.TreeBranches) ([]byte, error) { if comment, ok := item.Key.(sops.Comment); ok { line = fmt.Sprintf("#%s\n", comment.Value) } else { - value := strings.Replace(item.Value.(string), "\n", "\\n", -1) + value, ok := item.Value.(string) + if !ok { + value = stores.ValToString(item.Value) + } else { + value = strings.ReplaceAll(value, "\n", "\\n") + } + line = fmt.Sprintf("%s=%s\n", item.Key, value) } buffer.WriteString(line)