mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-18 00:07:08 +00:00
* 🎨 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
37 lines
864 B
Go
37 lines
864 B
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/c3os-io/c3os/pkg/bus"
|
|
"github.com/c3os-io/c3os/pkg/config"
|
|
"github.com/mudler/go-nodepair"
|
|
"github.com/mudler/go-pluggable"
|
|
)
|
|
|
|
func Challenge(e *pluggable.Event) pluggable.EventResponse {
|
|
p := &bus.EventPayload{}
|
|
err := json.Unmarshal([]byte(e.Data), p)
|
|
if err != nil {
|
|
return pluggable.EventResponse{Error: fmt.Sprintf("Failed reading JSON input: %s input '%s'", err.Error(), e.Data)}
|
|
}
|
|
|
|
cfg := &config.Config{}
|
|
err = config.FromString(p.Config, cfg)
|
|
if err != nil {
|
|
return pluggable.EventResponse{Error: fmt.Sprintf("Failed reading JSON input: %s input '%s'", err.Error(), p.Config)}
|
|
}
|
|
|
|
tk := ""
|
|
if cfg.C3OS != nil && cfg.C3OS.NetworkToken != "" {
|
|
tk = cfg.C3OS.NetworkToken
|
|
}
|
|
if tk == "" {
|
|
tk = nodepair.GenerateToken()
|
|
}
|
|
return pluggable.EventResponse{
|
|
Data: tk,
|
|
}
|
|
}
|