Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions stores/dotenv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions stores/stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading