Skip to content

Commit

Permalink
base/validate.go: Added switch statement for Validate Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam0Brien committed Aug 10, 2023
1 parent 3d444ad commit cc1fd07
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions base/v0_6_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,33 @@ import (
func (rs Resource) Validate(c path.ContextPath) (r report.Report) {
var field string
sources := 0
if rs.Local != nil {
sources++
field = "local"
config := *rs.Local
_, report, err := exp.Parse([]byte(config))
if err != nil {
r.Merge(report)
} else {
r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport)
}
}
if rs.Inline != nil {
sources++
field = "inline"
config := *rs.Inline
_, report, err := exp.Parse([]byte(config))
if err != nil {
r.Merge(report)
} else {
r.AddOnError(c.Append("ignition", "config", "merge", "local"), common.ErrEmptyReport)
}
}
if rs.Source != nil {
sources++
field = "source"
var config string
switch {
case rs.Local != nil:
sources++
field = "local"
config = *rs.Local
case rs.Inline != nil:
sources++
field = "inline"
config = *rs.Inline
case rs.Source != nil:
sources++
field = "source"
}
if sources > 1 {
r.AddOnError(c.Append(field), common.ErrTooManyResourceSources)
} else {
if field == "local" || field == "inline" {
_, report, err := exp.Parse([]byte(config))
if err != nil {
r.Merge(report)
} else {
r.AddOnWarn(c.Append("ignition", "config", "merge", field), err)
}
}
}

return r
return
}

func (fs Filesystem) Validate(c path.ContextPath) (r report.Report) {
Expand Down

0 comments on commit cc1fd07

Please sign in to comment.