Skip to content

Commit

Permalink
Added config utils (#55)
Browse files Browse the repository at this point in the history
* added config utils, dropped not needed config, fixed some naming
* fix pr change requests

---------

Co-authored-by: Tafseer Khan <[email protected]>
  • Loading branch information
samyfodil and tafseer-khan authored Aug 9, 2023
1 parent a7388ae commit d6e6629
Show file tree
Hide file tree
Showing 58 changed files with 513 additions and 160 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,12 @@ ports:
location:
lat: 120
long: 21
http-listen: 0.0.0.0:443
network-url: example.com
domains:
key:
private: keys/test.key
services: ^[^.]+\.tau\.example\.com
generated: g.example.com
whitelist:
postfix: [test.com]
regex:
- '^[^.]+\.test\.example\.com'
services: ^[^.]+\.tau\.example\.com$
generated: g\.example\.com$
```
### Running `tau`
Expand Down
53 changes: 9 additions & 44 deletions cli/app/app.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,24 @@
package app

import (
"fmt"

"github.com/taubyte/tau/cli/node"
"github.com/taubyte/tau/config"
"github.com/urfave/cli/v2"
)

func Run(args ...string) error {
err := App().Run(args)
if err != nil {
return err
}

return nil
}

func App() *cli.App {
func newApp() *cli.App {
app := &cli.App{
Commands: []*cli.Command{
startShape(),
startCommand(),
configCommand(),
},
}
return app
}

func startShape() *cli.Command {
return &cli.Command{
Name: "start",
Description: "start a shape",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "shape",
Required: true,
Aliases: []string{"s"},
},
&cli.PathFlag{
Name: "root",
DefaultText: config.DefaultRoot,
},
&cli.BoolFlag{
Name: "dev-mode",
Aliases: []string{"dev"},
},
},

Action: func(ctx *cli.Context) error {
protocolConfig, sourceConfig, err := parseSourceConfig(ctx)
if err != nil {
return fmt.Errorf("parsing config failed with: %s", err)
}

setNetworkDomains(sourceConfig)
return node.Start(ctx.Context, protocolConfig)
},
func Run(args ...string) error {
err := newApp().Run(args)
if err != nil {
return err
}

return nil
}
89 changes: 89 additions & 0 deletions cli/app/config_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package app

import (
"github.com/pterm/pterm"
"github.com/taubyte/tau/config"
"github.com/urfave/cli/v2"
)

func configCommand() *cli.Command {
return &cli.Command{
Name: "config",
Aliases: []string{"cnf", "conf"},
Description: "configuration utils",
Subcommands: []*cli.Command{
{
Name: "validate",
Aliases: []string{"check", "ok", "ok?", "valid?"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "shape",
Aliases: []string{"s"},
},
&cli.PathFlag{
Name: "root",
DefaultText: config.DefaultRoot,
},
&cli.PathFlag{
Name: "path",
Aliases: []string{"p"},
},
},
Action: func(ctx *cli.Context) error {
_, _, err := parseSourceConfig(ctx)
return err
},
},
{
Name: "generate",
Aliases: []string{"gen"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "shape",
Aliases: []string{"s"},
},
&cli.PathFlag{
Name: "root",
Value: config.DefaultRoot,
},
&cli.StringFlag{
Name: "protocols",
Aliases: []string{"proto", "protos"},
},
&cli.StringFlag{
Name: "network",
Aliases: []string{"fqdn"},
Value: "example.com",
},
&cli.IntFlag{
Name: "p2p-port",
Aliases: []string{"port", "p2p"},
Value: 4242,
},
&cli.StringSliceFlag{
Name: "ip",
Aliases: []string{"address", "addr"},
},
&cli.StringSliceFlag{
Name: "bootstrap",
},
&cli.BoolFlag{
Name: "swarm-key",
Aliases: []string{"swarm"},
},
&cli.BoolFlag{
Name: "dv-keys",
Aliases: []string{"dv"},
},
},
Action: func(ctx *cli.Context) error {
id, err := generateSourceConfig(ctx)
if id != "" {
pterm.Info.Println("ID:", id)
}
return err
},
},
},
}
}
37 changes: 37 additions & 0 deletions cli/app/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app

import (
"context"
"log"
"os"
"testing"
"time"

_ "embed"

"gotest.tools/v3/assert"
)

func TestConfig(t *testing.T) {
app := newApp()

ctx, ctxC := context.WithTimeout(context.Background(), time.Second*15)
defer ctxC()

root, err := os.MkdirTemp("/tmp", "tau-test")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(root)

os.Mkdir(root+"/storage", 0750)
os.Mkdir(root+"/storage/test", 0750)
os.Mkdir(root+"/config", 0750)
os.Mkdir(root+"/config/keys", 0750)

err = app.RunContext(ctx, []string{os.Args[0], "cnf", "gen", "-s", "test", "--root", root, "--protos", "auth,seer,monkey", "--swarm-key", "--dv-keys"})
assert.NilError(t, err)

err = app.RunContext(ctx, []string{os.Args[0], "cnf", "ok?", "-s", "test", "--root", root})
assert.NilError(t, err)
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ ports:
location:
lat: 120
long: 21
http-listen: 0.0.0.0:443
network-url: example.com
domains:
key:
Expand Down
File renamed without changes.
Loading

0 comments on commit d6e6629

Please sign in to comment.