better http frontend configuration semantics (#48)

This commit is contained in:
Michael Quigley 2022-09-06 15:01:38 -04:00
parent 778de526e1
commit 8095128c91
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
6 changed files with 49 additions and 19 deletions

View File

@ -5,5 +5,5 @@ scp -i ~/.ssh/nf-zrok-ubuntu ~/local/zrok/bin/zrok ctrl-01.zrok.io:local/zrok/bi
ssh -i ~/.ssh/nf-zrok-ubuntu ctrl-01.zrok.io sudo systemctl start zrok-ctrl
ssh -i ~/.ssh/nf-zrok-ubuntu in-01.zrok.io sudo systemctl stop zrok-http-frontend
scp -i ~/.ssh/nf-zrok-ubuntu ~/local/zrok/bin/zrok in-01.zrok.io:local/zrok/bin/zrok-ctrl
ssh -i ~/.ssh/nf-zrok-ubuntu in-01.zrok.io sudo systemctl start zrok-http-frontend
scp -i ~/.ssh/nf-zrok-ubuntu ~/local/zrok/bin/zrok in-01.zrok.io:local/zrok/bin/zrok
ssh -i ~/.ssh/nf-zrok-ubuntu in-01.zrok.io sudo systemctl start zrok-http-frontend

View File

@ -1,7 +1,9 @@
package main
import (
"github.com/michaelquigley/cf"
"github.com/openziti-test-kitchen/zrok/controller"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -30,6 +32,7 @@ func (cmd *controllerCommand) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
logrus.Infof(cf.Dump(cfg, cf.DefaultOptions()))
if err := controller.Run(cfg); err != nil {
panic(err)
}

View File

@ -1,7 +1,9 @@
package main
import (
"github.com/michaelquigley/cf"
"github.com/openziti-test-kitchen/zrok/endpoints/frontend"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -10,28 +12,30 @@ func init() {
}
type httpFrontendCommand struct {
endpoint string
cmd *cobra.Command
cmd *cobra.Command
}
func newHttpFrontendCommand() *httpFrontendCommand {
cmd := &cobra.Command{
Use: "frontend <zitiIdentity>",
Use: "frontend [<configPath>]",
Aliases: []string{"fe"},
Short: "Create an HTTP frontend",
Args: cobra.ExactArgs(1),
Args: cobra.RangeArgs(0, 1),
}
command := &httpFrontendCommand{cmd: cmd}
cmd.Flags().StringVarP(&command.endpoint, "endpoint", "e", "0.0.0.0:10180", "Bind address for HTTP frontend")
cmd.Run = command.run
return command
}
func (self *httpFrontendCommand) run(_ *cobra.Command, args []string) {
httpListener, err := frontend.NewHTTP(&frontend.Config{
IdentityPath: args[0],
Address: self.endpoint,
})
cfg := frontend.DefaultConfig()
if len(args) == 1 {
if err := cfg.Load(args[0]); err != nil {
panic(err)
}
}
logrus.Infof(cf.Dump(cfg, cf.DefaultOptions()))
httpListener, err := frontend.NewHTTP(cfg)
if err != nil {
panic(err)
}

View File

@ -4,7 +4,6 @@ import (
"github.com/michaelquigley/cf"
"github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type Config struct {
@ -35,6 +34,5 @@ func LoadConfig(path string) (*Config, error) {
if err := cf.BindYaml(cfg, path, cf.DefaultOptions()); err != nil {
return nil, errors.Wrapf(err, "error loading controller config '%v'", path)
}
logrus.Info(cf.Dump(cfg, cf.DefaultOptions()))
return cfg, nil
}

View File

@ -0,0 +1,25 @@
package frontend
import (
"github.com/michaelquigley/cf"
"github.com/pkg/errors"
)
type Config struct {
Identity string
Address string
}
func DefaultConfig() *Config {
return &Config{
Identity: "frontend",
Address: "0.0.0.0:8080",
}
}
func (c *Config) Load(path string) error {
if err := cf.BindYaml(c, path, cf.DefaultOptions()); err != nil {
return errors.Wrapf(err, "error loading frontend config '%v'", path)
}
return nil
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/openziti-test-kitchen/zrok/model"
"github.com/openziti-test-kitchen/zrok/util"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/config"
"github.com/openziti/sdk-golang/ziti/edge"
@ -17,11 +18,6 @@ import (
"strings"
)
type Config struct {
IdentityPath string
Address string
}
type httpListen struct {
cfg *Config
zCtx ziti.Context
@ -29,7 +25,11 @@ type httpListen struct {
}
func NewHTTP(cfg *Config) (*httpListen, error) {
zCfg, err := config.NewFromFile(cfg.IdentityPath)
zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.Identity)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.Identity)
}
zCfg, err := config.NewFromFile(zCfgPath)
if err != nil {
return nil, errors.Wrap(err, "error loading config")
}