bootcfg/http/ignition: Just warn for raw Ignition errors

* When raw Ignition (.ign/.ignition) content is provided, Parse
the contents with ignition, but return the contents as JSON
regardless of the result to respect user pass-through expectations
* Warn on parse errors which can occur if a newer Ignition format
is used than the version of Ignition that bootcfg was compiled
with
This commit is contained in:
Dalton Hubble
2016-06-23 15:51:20 -07:00
parent 114a229ade
commit 62e0ec1976
3 changed files with 9 additions and 7 deletions

View File

@@ -39,13 +39,11 @@ func ignitionHandler(srv server.Server) ContextHandler {
// Skip rendering if raw Ignition JSON is provided
if isIgnition(profile.IgnitionId) {
cfg, err := ignition.Parse([]byte(contents))
_, err := ignition.Parse([]byte(contents))
if err != nil {
log.Errorf("error parsing Ignition JSON: %v", err)
http.NotFound(w, req)
return
log.Warningf("warning parsing Ignition JSON: %v", err)
}
renderJSON(w, cfg)
writeJSON(w, []byte(contents))
return
}

View File

@@ -19,7 +19,7 @@ var (
)
func TestIgnitionHandler_V2JSON(t *testing.T) {
content := `{"ignition":{"version":"2.0.0","config":{}},"systemd":{"units":[{"name":"etcd2.service","enable":true},{"name":"a1b2c3d4.service","enable":true}]}}`
content := `{"ignition":{"version":"2.0.0","config":{}},"storage":{},"systemd":{"units":[{"name":"etcd2.service","enable":true},{"name":"a1b2c3d4.service","enable":true}]},"networkd":{},"passwd":{}}`
profile := &storagepb.Profile{
Id: fake.Group.Profile,
IgnitionId: "file.ign",

View File

@@ -21,9 +21,13 @@ func renderJSON(w http.ResponseWriter, v interface{}) {
w.WriteHeader(http.StatusInternalServerError)
return
}
writeJSON(w, js)
}
// writeJSON writes the given bytes with a JSON Content-Type.
func writeJSON(w http.ResponseWriter, data []byte) {
w.Header().Set(contentType, jsonContentType)
_, err = w.Write(js)
_, err := w.Write(data)
if err != nil {
log.Errorf("error writing to response: %v", err)
w.WriteHeader(http.StatusInternalServerError)