mirror of
https://github.com/openziti/zrok.git
synced 2025-06-19 17:27:54 +02:00
cf-based config (#23)
This commit is contained in:
parent
8606072b80
commit
36b08f1e00
@ -2,11 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/openziti-test-kitchen/zrok/controller"
|
"github.com/openziti-test-kitchen/zrok/controller"
|
||||||
"github.com/openziti-test-kitchen/zrok/controller/store"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -20,35 +16,24 @@ type controllerCommand struct {
|
|||||||
|
|
||||||
func newControllerCommand() *controllerCommand {
|
func newControllerCommand() *controllerCommand {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "controller",
|
Use: "controller <configPath>",
|
||||||
Short: "Start a zrok controller",
|
Short: "Start a zrok controller",
|
||||||
Aliases: []string{"ctrl"},
|
Aliases: []string{"ctrl"},
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
}
|
}
|
||||||
ccmd := &controllerCommand{
|
ccmd := &controllerCommand{
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
}
|
}
|
||||||
cmd.Run = ccmd.run
|
cmd.Run = ccmd.run
|
||||||
cmd.Flags().StringVarP(&ccmd.dbPath, "database", "d", "zrok.db", "Path to zrok controller database")
|
|
||||||
return ccmd
|
return ccmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *controllerCommand) run(_ *cobra.Command, _ []string) {
|
func (cmd *controllerCommand) run(_ *cobra.Command, args []string) {
|
||||||
tokens := strings.Split(endpoint, ":")
|
cfg, err := controller.LoadConfig(args[0])
|
||||||
if len(tokens) != 2 {
|
|
||||||
panic(errors.Errorf("malformed endpoint '%v'", endpoint))
|
|
||||||
}
|
|
||||||
host := tokens[0]
|
|
||||||
port, err := strconv.Atoi(tokens[1])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := controller.Run(&controller.Config{
|
if err := controller.Run(cfg); err != nil {
|
||||||
Endpoint: controller.EndpointConfig{
|
|
||||||
Host: host,
|
|
||||||
Port: port,
|
|
||||||
},
|
|
||||||
Store: &store.Config{Path: cmd.dbPath},
|
|
||||||
}); err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import "github.com/openziti-test-kitchen/zrok/controller/store"
|
import (
|
||||||
|
"github.com/michaelquigley/cf"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/controller/store"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Endpoint EndpointConfig
|
Endpoint *EndpointConfig
|
||||||
Proxy ProxyConfig
|
Proxy *ProxyConfig
|
||||||
Store *store.Config
|
Store *store.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,3 +20,11 @@ type EndpointConfig struct {
|
|||||||
type ProxyConfig struct {
|
type ProxyConfig struct {
|
||||||
UrlTemplate string
|
UrlTemplate string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LoadConfig(path string) (*Config, error) {
|
||||||
|
cfg := &Config{}
|
||||||
|
if err := cf.BindYaml(cfg, path, cf.DefaultOptions()); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error loading controller config '%v'", path)
|
||||||
|
}
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
9
etc/ctrl.yml
Normal file
9
etc/ctrl.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
endpoint:
|
||||||
|
host: 0.0.0.0
|
||||||
|
port: 10888
|
||||||
|
|
||||||
|
proxy:
|
||||||
|
url_template: "http://{id}.zrok.quigley.com:10111/"
|
||||||
|
|
||||||
|
store:
|
||||||
|
path: zrok.db
|
2
go.mod
2
go.mod
@ -46,6 +46,7 @@ require (
|
|||||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||||
|
github.com/michaelquigley/cf v0.0.12 // indirect
|
||||||
github.com/miekg/pkcs11 v1.1.1 // indirect
|
github.com/miekg/pkcs11 v1.1.1 // indirect
|
||||||
github.com/mitchellh/go-ps v1.0.0 // indirect
|
github.com/mitchellh/go-ps v1.0.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
@ -73,4 +74,5 @@ require (
|
|||||||
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
|
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
|
||||||
google.golang.org/protobuf v1.28.0 // indirect
|
google.golang.org/protobuf v1.28.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -337,6 +337,8 @@ github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4
|
|||||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
||||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||||
|
github.com/michaelquigley/cf v0.0.12 h1:DEGncGj4gikWMSkpnAD5h7l472hjGgnaGYnT2zAS1V8=
|
||||||
|
github.com/michaelquigley/cf v0.0.12/go.mod h1:yzQJzoNRfeyB4pr5lxia1dtoS/7X96IoM5uZEIW6nzo=
|
||||||
github.com/michaelquigley/pfxlog v0.6.9 h1:K/weH6ARu58aEDQi0ccinItvV958CeO6Ri4jqeFwd/w=
|
github.com/michaelquigley/pfxlog v0.6.9 h1:K/weH6ARu58aEDQi0ccinItvV958CeO6Ri4jqeFwd/w=
|
||||||
github.com/michaelquigley/pfxlog v0.6.9/go.mod h1:D2vg1tPyPdSXWWkSnGk6Fomwh5b3clwVJDUh71tq8Sk=
|
github.com/michaelquigley/pfxlog v0.6.9/go.mod h1:D2vg1tPyPdSXWWkSnGk6Fomwh5b3clwVJDUh71tq8Sk=
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user