kairos-agent/internal/provider/install.go
Ettore Di Giacinto adce182ea2 art: Refactor out config sections
Now there is a `install` section in the config that has the fields that previously where in `c3os` but
were actually only used during install phase.

Also the k3s and c3os config were moved to the provider instead that in the global config.
2022-07-16 20:47:55 +00:00

36 lines
802 B
Go

package provider
import (
"context"
"encoding/json"
"github.com/c3os-io/c3os/pkg/bus"
"github.com/mudler/go-nodepair"
"github.com/mudler/go-pluggable"
)
func Install(e *pluggable.Event) pluggable.EventResponse {
cfg := &bus.InstallPayload{}
err := json.Unmarshal([]byte(e.Data), cfg)
if err != nil {
return ErrorEvent("Failed reading JSON input: %s", err.Error())
}
r := map[string]string{}
ctx := context.Background()
if err := nodepair.Receive(ctx, &r, nodepair.WithToken(cfg.Token)); err != nil {
return ErrorEvent("Failed reading JSON input: %s", err.Error())
}
payload, err := json.Marshal(r)
if err != nil {
return ErrorEvent("Failed marshalling JSON input: %s", err.Error())
}
return pluggable.EventResponse{
State: "",
Data: string(payload),
Error: "",
}
}