mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-25 21:43:58 +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:
@@ -1,50 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/mudler/edgevpn/pkg/config"
|
||||
)
|
||||
|
||||
func Network(token, address, loglevel, i string) *config.Config {
|
||||
return &config.Config{
|
||||
NetworkToken: token,
|
||||
Address: address,
|
||||
Libp2pLogLevel: "error",
|
||||
FrameTimeout: "30s",
|
||||
BootstrapIface: true,
|
||||
LogLevel: loglevel,
|
||||
LowProfile: true,
|
||||
VPNLowProfile: true,
|
||||
Interface: i,
|
||||
Concurrency: runtime.NumCPU(),
|
||||
PacketMTU: 1420,
|
||||
InterfaceMTU: 1200,
|
||||
Ledger: config.Ledger{
|
||||
AnnounceInterval: time.Duration(30) * time.Second,
|
||||
SyncInterval: time.Duration(30) * time.Second,
|
||||
},
|
||||
NAT: config.NAT{
|
||||
Service: true,
|
||||
Map: true,
|
||||
RateLimit: true,
|
||||
RateLimitGlobal: 10,
|
||||
RateLimitPeer: 10,
|
||||
RateLimitInterval: time.Duration(10) * time.Second,
|
||||
},
|
||||
Discovery: config.Discovery{
|
||||
DHT: true,
|
||||
MDNS: true,
|
||||
Interval: time.Duration(120) * time.Second,
|
||||
},
|
||||
Connection: config.Connection{
|
||||
RelayV1: true,
|
||||
|
||||
AutoRelay: true,
|
||||
MaxConnections: 100,
|
||||
MaxStreams: 100,
|
||||
HolePunch: true,
|
||||
},
|
||||
}
|
||||
}
|
@@ -1,15 +1,11 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/c3os-io/c3os/sdk/unstructured"
|
||||
"github.com/google/shlex"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/itchyny/gojq"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func DotToYAML(file string) ([]byte, error) {
|
||||
@@ -23,7 +19,7 @@ func DotToYAML(file string) ([]byte, error) {
|
||||
|
||||
v := stringToMap(string(dat))
|
||||
|
||||
return dotToYAML(v)
|
||||
return unstructured.ToYAML(v)
|
||||
}
|
||||
|
||||
func stringToMap(s string) map[string]interface{} {
|
||||
@@ -42,47 +38,3 @@ func stringToMap(s string) map[string]interface{} {
|
||||
|
||||
return v
|
||||
}
|
||||
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 dotToYAML(v map[string]interface{}) ([]byte, error) {
|
||||
data := map[string]interface{}{}
|
||||
var errs error
|
||||
|
||||
for k, value := range v {
|
||||
newData, err := jq(fmt.Sprintf(".%s=\"%s\"", 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user