Skip to content

Commit

Permalink
Validate attribute names are correct when parsing JSON/YAML (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
aelsabbahy committed Apr 15, 2016
1 parent 2f712f8 commit 763f9b0
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 0 deletions.
2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ import:
ref: c72df929b80ef4930aaa75d5e486887ff2f3e06a
- package: gopkg.in/yaml.v2
ref: f7716cbe52baa25d2e9b0d0da546fcf909fc16b4
- package: github.com/oleiade/reflections
ref: 632977f98cd34d217c4b57d0840ec188b3d3dcaf
14 changes: 14 additions & 0 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/aelsabbahy/goss/system"
"github.com/oleiade/reflections"
)

type Resource interface {
Expand Down Expand Up @@ -43,3 +45,15 @@ func deprecateAtoI(depr interface{}, desc string) interface{} {
}
return float64(i)
}

func validAttrs(i interface{}, t string) (map[string]bool, error) {
validAttrs := make(map[string]bool)
tags, err := reflections.Tags(i, t)
if err != nil {
return nil, err
}
for _, v := range tags {
validAttrs[strings.Split(v, ",")[0]] = true
}
return validAttrs, nil
}
Loading

0 comments on commit 763f9b0

Please sign in to comment.