image-factory/internal/frontend/http/configuration.go
Andrew Rynhard 91bbcd2c82
chore: rename with new nomenclature
Themes the nomenclature to align with Talos Linux

Signed-off-by: Andrew Rynhard <andrew@rynhard.io>
Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2023-09-18 22:30:22 +04:00

50 lines
1.0 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package http
import (
"context"
"encoding/json"
"io"
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/siderolabs/image-factory/pkg/schematic"
)
// handleSchematicCreate handles creation of the schematic.
func (f *Frontend) handleSchematicCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, _ httprouter.Params) error {
data, err := io.ReadAll(r.Body)
if err != nil {
return err
}
if err = r.Body.Close(); err != nil {
return err
}
cfg, err := schematic.Unmarshal(data)
if err != nil {
return err
}
id, err := f.schematicFactory.Put(ctx, cfg)
if err != nil {
return err
}
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
resp := struct {
ID string `json:"id"`
}{
ID: id,
}
return json.NewEncoder(w).Encode(resp)
}