Skip to content

Commit

Permalink
Extract fn ConfigFromContext
Browse files Browse the repository at this point in the history
This allows it to be consumed by other clients like `kairosctl bridge`
without having to duplicate the functionality.

Signed-off-by: Mauro Morales <contact@mauromorales.com>
  • Loading branch information
mauromorales committed Apr 25, 2024
1 parent c3f4657 commit 9f6b14f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
"github.com/mudler/edgevpn/internal"
"github.com/mudler/edgevpn/pkg/config"
nodeConfig "github.com/mudler/edgevpn/pkg/config"
"github.com/multiformats/go-multiaddr"

"github.com/mudler/edgevpn/pkg/logger"
Expand Down Expand Up @@ -391,8 +390,8 @@ func stringsToMultiAddr(peers []string) []multiaddr.Multiaddr {
return res
}

func cliToOpts(c *cli.Context) ([]node.Option, []vpn.Option, *logger.Logger) {

// ConfigFromContext returns a config object from a cli context
func ConfigFromContext(c *cli.Context) *config.Config {
var limitConfig *rcmgr.PartialLimitConfig

autorelayInterval, err := time.ParseDuration(c.String("autorelay-discovery-interval"))
Expand All @@ -405,7 +404,7 @@ func cliToOpts(c *cli.Context) ([]node.Option, []vpn.Option, *logger.Logger) {
d := map[string]map[string]interface{}{}
json.Unmarshal([]byte(pa), &d)

nc := nodeConfig.Config{
return &config.Config{
NetworkConfig: c.String("config"),
NetworkToken: c.String("token"),
Address: c.String("address"),
Expand Down Expand Up @@ -467,6 +466,10 @@ func cliToOpts(c *cli.Context) ([]node.Option, []vpn.Option, *logger.Logger) {
AuthProviders: d,
},
}
}

func cliToOpts(c *cli.Context) ([]node.Option, []vpn.Option, *logger.Logger) {
nc := ConfigFromContext(c)

lvl, err := log.LevelFromString(nc.LogLevel)
if err != nil {
Expand Down

0 comments on commit 9f6b14f

Please sign in to comment.