diff --git a/pkg/config/network.go b/pkg/config/network.go deleted file mode 100644 index 5c4e176..0000000 --- a/pkg/config/network.go +++ /dev/null @@ -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, - }, - } -} diff --git a/pkg/machine/bootcmdline.go b/pkg/machine/bootcmdline.go index ede22c1..180ead6 100644 --- a/pkg/machine/bootcmdline.go +++ b/pkg/machine/bootcmdline.go @@ -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 -}