Skip to content

Commit

Permalink
fix key cound when looking at deeply nested values
Browse files Browse the repository at this point in the history
  • Loading branch information
esilva-everbridge committed Oct 2, 2019
1 parent aa25119 commit afe4f6e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"os"
"path/filepath"
"reflect"

"github.com/Everbridge/generate-secure-pillar/sls"
"github.com/Everbridge/generate-secure-pillar/utils"
Expand Down Expand Up @@ -74,7 +75,7 @@ var keysCmd = &cobra.Command{
}
var vals []string
for _, v := range s.KeyMap {
vals = append(vals, v.(string))
vals = append(vals, getNode(v.(interface{})).(string))
}
unique := removeDuplicates(vals)
if verbose {
Expand Down Expand Up @@ -115,3 +116,20 @@ func removeDuplicates(elements []string) []string {

return result
}

func getNode(v interface{}) interface{} {
var node interface{}
vtype := reflect.TypeOf(v)
kind := vtype.Kind()

switch kind {
case reflect.Slice:
case reflect.Map:
for _, v2 := range v.(map[string]interface{}) {
node = getNode(v2.(interface{}))
}
default:
node = fmt.Sprintf("%v", v)
}
return node
}

0 comments on commit afe4f6e

Please sign in to comment.