kairos-agent/internal/provider/install.go
Ettore Di Giacinto 63cd28d1cb Split off cli into separate binaries (#37)
* 🎨 Split off cli into separate binaries

This commit splits off the cli into 3 binaries:
- agent
- cli
- provider

The provider now is a separate component that can be tested by itself
and have its own lifecycle. This paves the way to a ligher c3os variant,
HA support and other features that can be provided on runtime.

This is working, but still there are low hanging fruit to care about.

Fixes #14

* 🤖 Add provider bin to releases

* ⚙️ Handle signals

* ⚙️ Reduce buildsize footprint

* 🎨 Scan for providers also in /system/providers

* 🤖 Run goreleaser

* 🎨 Refactoring
2022-07-04 22:39:34 +02:00

37 lines
908 B
Go

package provider
import (
"context"
"encoding/json"
"fmt"
"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 pluggable.EventResponse{Error: fmt.Sprintf("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 pluggable.EventResponse{Error: fmt.Sprintf("Failed reading JSON input: %s", err.Error())}
}
payload, err := json.Marshal(r)
if err != nil {
return pluggable.EventResponse{Error: fmt.Sprintf("Failed marshalling JSON input: %s", err.Error())}
}
return pluggable.EventResponse{
State: "",
Data: string(payload),
Error: "",
}
}