feat: cli client with spec schema validation

This commit is contained in:
2023-02-28 15:50:35 +01:00
parent 2a828afc89
commit 3310c09320
51 changed files with 1929 additions and 82 deletions

View File

@ -4,13 +4,13 @@ import (
"context"
"forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
"forge.cadoles.com/Cadoles/emissary/internal/spec/gateway"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
)
type Controller struct {
proxies map[spec.GatewayID]*ReverseProxy
proxies map[gateway.ID]*ReverseProxy
currentSpecRevision int
}
@ -21,9 +21,9 @@ func (c *Controller) Name() string {
// Reconcile implements node.Controller.
func (c *Controller) Reconcile(ctx context.Context, state *agent.State) error {
gatewaySpec := spec.NewGatewaySpec()
gatewaySpec := gateway.NewSpec()
if err := state.GetSpec(spec.NameGateway, gatewaySpec); err != nil {
if err := state.GetSpec(gateway.NameGateway, gatewaySpec); err != nil {
if errors.Is(err, agent.ErrSpecNotFound) {
logger.Info(ctx, "could not find gateway spec, stopping all remaining proxies")
@ -67,7 +67,7 @@ func (c *Controller) stopAllProxies(ctx context.Context) {
}
}
func (c *Controller) updateProxies(ctx context.Context, spec *spec.Gateway) {
func (c *Controller) updateProxies(ctx context.Context, spec *gateway.Spec) {
// Stop and remove obsolete gateways
for gatewayID, proxy := range c.proxies {
if _, exists := spec.Gateways[gatewayID]; exists {
@ -116,7 +116,7 @@ func (c *Controller) updateProxies(ctx context.Context, spec *spec.Gateway) {
func NewController() *Controller {
return &Controller{
proxies: make(map[spec.GatewayID]*ReverseProxy),
proxies: make(map[gateway.ID]*ReverseProxy),
currentSpecRevision: -1,
}
}

View File

@ -8,7 +8,7 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/openwrt/uci"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
ucispec "forge.cadoles.com/Cadoles/emissary/internal/spec/uci"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
)
@ -25,9 +25,9 @@ func (*UCIController) Name() string {
// Reconcile implements node.Controller.
func (c *UCIController) Reconcile(ctx context.Context, state *agent.State) error {
uciSpec := spec.NewUCISpec()
uciSpec := ucispec.NewSpec()
if err := state.GetSpec(spec.NameUCI, uciSpec); err != nil {
if err := state.GetSpec(ucispec.NameUCI, uciSpec); err != nil {
if errors.Is(err, agent.ErrSpecNotFound) {
logger.Info(ctx, "could not find uci spec, doing nothing")
@ -57,7 +57,7 @@ func (c *UCIController) Reconcile(ctx context.Context, state *agent.State) error
return nil
}
func (c *UCIController) updateConfiguration(ctx context.Context, spec *spec.UCI) error {
func (c *UCIController) updateConfiguration(ctx context.Context, spec *ucispec.Spec) error {
logger.Info(ctx, "importing uci config")
if err := c.importConfig(ctx, spec.Config); err != nil {
@ -91,7 +91,7 @@ func (c *UCIController) importConfig(ctx context.Context, uci *uci.UCI) error {
return nil
}
func (c *UCIController) execPostImportCommands(ctx context.Context, commands []*spec.UCIPostImportCommand) error {
func (c *UCIController) execPostImportCommands(ctx context.Context, commands []*ucispec.UCIPostImportCommand) error {
for _, postImportCmd := range commands {
cmd := exec.CommandContext(ctx, postImportCmd.Command, postImportCmd.Args...)