2022-07-04 20:39:34 +00:00
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
|
2022-08-09 06:01:54 +00:00
|
|
|
"github.com/c3os-io/c3os/sdk/bus"
|
|
|
|
|
2022-07-04 20:39:34 +00:00
|
|
|
"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 {
|
2022-07-16 20:47:55 +00:00
|
|
|
return ErrorEvent("Failed reading JSON input: %s", err.Error())
|
2022-07-04 20:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r := map[string]string{}
|
|
|
|
ctx := context.Background()
|
|
|
|
if err := nodepair.Receive(ctx, &r, nodepair.WithToken(cfg.Token)); err != nil {
|
2022-07-16 20:47:55 +00:00
|
|
|
return ErrorEvent("Failed reading JSON input: %s", err.Error())
|
2022-07-04 20:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
payload, err := json.Marshal(r)
|
|
|
|
if err != nil {
|
2022-07-16 20:47:55 +00:00
|
|
|
return ErrorEvent("Failed marshalling JSON input: %s", err.Error())
|
2022-07-04 20:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pluggable.EventResponse{
|
|
|
|
State: "",
|
|
|
|
Data: string(payload),
|
|
|
|
Error: "",
|
|
|
|
}
|
|
|
|
}
|