mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-14 06:11:56 +00:00
art: Expose interactive install to providers
In this way install can be driven from providers too Part of: https://github.com/c3os-io/c3os/issues/68
This commit is contained in:
@@ -25,6 +25,8 @@ const (
|
||||
// EventRecovery emitted while booting into recovery mode
|
||||
EventRecovery pluggable.EventType = "agent.recovery"
|
||||
EventRecoveryStop pluggable.EventType = "agent.recovery.stop"
|
||||
|
||||
EventInteractiveInstall pluggable.EventType = "agent.interactive-install"
|
||||
)
|
||||
|
||||
type InstallPayload struct {
|
||||
@@ -32,6 +34,17 @@ type InstallPayload struct {
|
||||
Config string `json:"config"`
|
||||
}
|
||||
|
||||
type YAMLPrompt struct {
|
||||
YAMLSection string
|
||||
Bool bool
|
||||
Prompt string
|
||||
Default string
|
||||
AskFirst bool
|
||||
AskPrompt string
|
||||
IfEmpty string
|
||||
PlaceHolder string
|
||||
}
|
||||
|
||||
type BootstrapPayload struct {
|
||||
APIAddress string `json:"api"`
|
||||
Config string `json:"config"`
|
||||
@@ -49,6 +62,7 @@ var AllEvents = []pluggable.EventType{
|
||||
EventBoot,
|
||||
EventInstall,
|
||||
EventRecovery,
|
||||
EventInteractiveInstall,
|
||||
EventRecoveryStop,
|
||||
}
|
||||
|
||||
|
72
sdk/unstructured/yaml.go
Normal file
72
sdk/unstructured/yaml.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package unstructured
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/itchyny/gojq"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func jq(command string, data map[string]interface{}) (map[string]interface{}, error) {
|
||||
query, err := gojq.Parse(command)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code, err := gojq.Compile(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iter := code.Run(data)
|
||||
|
||||
v, ok := iter.Next()
|
||||
if !ok {
|
||||
return nil, errors.New("failed getting rsult from gojq")
|
||||
}
|
||||
if err, ok := v.(error); ok {
|
||||
return nil, err
|
||||
}
|
||||
if t, ok := v.(map[string]interface{}); ok {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
return make(map[string]interface{}), nil
|
||||
}
|
||||
|
||||
func ToYAML(v map[string]interface{}) ([]byte, error) {
|
||||
data := map[string]interface{}{}
|
||||
var errs error
|
||||
|
||||
for k, value := range v {
|
||||
tmpl := ".%s=\"%s\""
|
||||
// support boolean types
|
||||
if value == "true" || value == "false" {
|
||||
tmpl = ".%s=%s"
|
||||
}
|
||||
newData, err := jq(fmt.Sprintf(tmpl, k, value), data)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
continue
|
||||
}
|
||||
data = newData
|
||||
}
|
||||
|
||||
out, err := yaml.Marshal(&data)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
return out, errs
|
||||
}
|
||||
|
||||
// ToYAMLMap turns a map string interface in dot.yaml format to a fully deep marshalled yaml
|
||||
func ToYAMLMap(v map[string]interface{}) (map[string]interface{}, error) {
|
||||
result := map[string]interface{}{}
|
||||
tempData, err := ToYAML(v)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
err = yaml.Unmarshal(tempData, &result)
|
||||
|
||||
return result, err
|
||||
}
|
Reference in New Issue
Block a user