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
base/validate.go: Fix merge report logic
  • Loading branch information
Adam0Brien committed Aug 10, 2023
1 parent 3d444ad commit 1198407
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 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 {
var config string
switch {
case 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 {
config = *rs.Local
case 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 {
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 len(report.Entries) > 0 {
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 1198407

Please sign in to comment.