diff --git a/go.mod b/go.mod index b787e0b..3a8cd56 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/coreos/butane v0.13.1 + github.com/coreos/ignition/v2 v2.11.0 github.com/gorilla/mux v1.8.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 diff --git a/pkg/server.go b/pkg/server.go index 743a590..db477c9 100644 --- a/pkg/server.go +++ b/pkg/server.go @@ -55,7 +55,7 @@ func (s *Server) Run() { func (s *Server) serveButaneTranslator(w http.ResponseWriter, r *http.Request) { // Set content type to json - w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.Header().Set("Content-Type", "application/json") // Set hostname from host header fqdn := strings.Split(r.Host, ":")[0] diff --git a/pkg/zippo.go b/pkg/zippo.go index b1c7878..ed5ec6e 100644 --- a/pkg/zippo.go +++ b/pkg/zippo.go @@ -2,11 +2,13 @@ package zippo import ( "bytes" + "encoding/json" "io/ioutil" "text/template" "github.com/coreos/butane/config" "github.com/coreos/butane/config/common" + "github.com/coreos/ignition/v2/config/v3_1/types" "github.com/pkg/errors" ) @@ -34,16 +36,21 @@ func Render(templatePath string, args interface{}) (*bytes.Buffer, error) { } // CreateIgnitionConfig creates an ignition config from a rendered butane template with a given hostname -func CreateIgnitionConfig(butaneTemplate string, hostname interface{}) (string, error) { +func CreateIgnitionConfig(butaneTemplate string, hostname interface{}) (types.Config, error) { + var ignitionConfig types.Config butaneConfig, err := Render(butaneTemplate, hostname) if err != nil { - return "", err + return ignitionConfig, err } - ignitionConfig, r, err := config.TranslateBytes(butaneConfig.Bytes(), common.TranslateBytesOptions{Pretty: true}) + ignitionBytes, r, err := config.TranslateBytes(butaneConfig.Bytes(), common.TranslateBytesOptions{Pretty: true}) if err != nil { - return "", errors.Wrapf(err, "error translating config: %s", r.String()) + return ignitionConfig, errors.Wrapf(err, "error translating config: %s", r.String()) } - return string(ignitionConfig), nil + err = json.Unmarshal(ignitionBytes, &ignitionConfig) + if err != nil { + return ignitionConfig, errors.Wrapf(err, "error translating config: %s", r.String()) + } + return ignitionConfig, nil }