mirror of
https://github.com/siderolabs/image-factory.git
synced 2025-09-21 13:51:08 +02:00
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>
50 lines
1.0 KiB
Go
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)
|
|
}
|