Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

Commit ca61ee9

Browse files
authored
Merge pull request #8 from crawford/parse
main: handle unknown version case
2 parents c20110f + 1e71b27 commit ca61ee9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

validate.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/coreos/coreos-cloudinit/config/validate"
2828
ignConfig "github.com/coreos/ignition/config"
29+
"github.com/coreos/ignition/config/validate/report"
2930
"github.com/crawford/nap"
3031
"github.com/gorilla/mux"
3132
)
@@ -94,17 +95,24 @@ func putValidate(r *http.Request) (interface{}, nap.Status) {
9495

9596
config := bytes.Replace(body, []byte("\r"), []byte{}, -1)
9697

97-
_, report, err := ignConfig.Parse(config)
98+
_, rpt, err := ignConfig.Parse(config)
9899
switch err {
99100
case ignConfig.ErrCloudConfig, ignConfig.ErrEmpty, ignConfig.ErrScript:
100-
report, err := validate.Validate(config)
101+
rpt, err := validate.Validate(config)
101102
if err != nil {
102103
return nil, nap.InternalError{err.Error()}
103104
}
104-
return report.Entries(), nap.OK{}
105+
return rpt.Entries(), nap.OK{}
106+
case ignConfig.ErrUnknownVersion:
107+
return report.Report{
108+
Entries: []report.Entry{{
109+
Kind: report.EntryError,
110+
Message: "Failed to parse config. Is this a valid Ignition Config, Cloud-Config, or script?",
111+
}},
112+
}, nap.OK{}
105113
default:
106-
report.Sort()
107-
return report.Entries, nap.OK{}
114+
rpt.Sort()
115+
return rpt.Entries, nap.OK{}
108116
}
109117
}
110118

0 commit comments

Comments
 (0)