diff --git a/cmd/sops/main.go b/cmd/sops/main.go index f24606f1c..cfa968408 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -241,8 +241,8 @@ func main() { var env []string for _, item := range tree.Branches[0] { - if dotenv.IsComplexValue(item.Value) { - return cli.NewExitError(fmt.Errorf("cannot use complex value in environment: %s", item.Value), codes.ErrorGeneric) + if stores.IsComplexValue(item.Value) { + return cli.NewExitError(fmt.Errorf("cannot use complex value in environment; offending key %s", item.Key), codes.ErrorGeneric) } if _, ok := item.Key.(sops.Comment); ok { continue diff --git a/stores/dotenv/store.go b/stores/dotenv/store.go index d42db65c0..e0fd2c69b 100644 --- a/stores/dotenv/store.go +++ b/stores/dotenv/store.go @@ -138,8 +138,8 @@ func (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) { func (store *Store) EmitPlainFile(in sops.TreeBranches) ([]byte, error) { buffer := bytes.Buffer{} for _, item := range in[0] { - if IsComplexValue(item.Value) { - return nil, fmt.Errorf("cannot use complex value in dotenv file: %s", item.Value) + if stores.IsComplexValue(item.Value) { + return nil, fmt.Errorf("cannot use complex value in dotenv file; offending key %s", item.Key) } var line string if comment, ok := item.Key.(sops.Comment); ok { @@ -176,14 +176,9 @@ func (store *Store) EmitExample() []byte { return bytes } +// Deprecated: use stores.IsComplexValue() instead! func IsComplexValue(v interface{}) bool { - switch v.(type) { - case []interface{}: - return true - case sops.TreeBranch: - return true - } - return false + return stores.IsComplexValue(v) } // HasSopsTopLevelKey checks whether a top-level "sops" key exists. diff --git a/stores/stores.go b/stores/stores.go index 4cd74b2f3..4d7f3788c 100644 --- a/stores/stores.go +++ b/stores/stores.go @@ -535,6 +535,17 @@ func HasSopsTopLevelKey(branch sops.TreeBranch) bool { return false } +// IsComplexValue returns true if the given value is an array or dictionary/hash. +func IsComplexValue(v interface{}) bool { + switch v.(type) { + case []interface{}: + return true + case sops.TreeBranch: + return true + } + return false +} + // ValToString converts a simple value to a string. // It does not handle complex values (arrays and mappings). func ValToString(v interface{}) string {