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:
mudler
2022-08-12 12:21:12 +02:00
committed by Itxaka
parent ba3c157cf8
commit 21d6393de3
2 changed files with 2 additions and 100 deletions

View File

@@ -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,
},
}
}

View File

@@ -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
}