feat: initial commit
This commit is contained in:
17
internal/command/agent/root.go
Normal file
17
internal/command/agent/root.go
Normal file
@ -0,0 +1,17 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/command/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Root() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "agent",
|
||||
Usage: "Agent related commands",
|
||||
Subcommands: []*cli.Command{
|
||||
RunCommand(),
|
||||
config.Root(),
|
||||
},
|
||||
}
|
||||
}
|
68
internal/command/agent/run.go
Normal file
68
internal/command/agent/run.go
Normal file
@ -0,0 +1,68 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/gateway"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/openwrt"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/persistence"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/controller/spec"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/command/common"
|
||||
"github.com/pkg/errors"
|
||||
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
)
|
||||
|
||||
func RunCommand() *cli.Command {
|
||||
flags := common.Flags()
|
||||
|
||||
return &cli.Command{
|
||||
Name: "run",
|
||||
Usage: "Run the emissary node",
|
||||
Flags: flags,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
conf, err := common.LoadConfig(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could not load configuration")
|
||||
}
|
||||
|
||||
logger.SetFormat(logger.Format(conf.Logger.Format))
|
||||
logger.SetLevel(logger.Level(conf.Logger.Level))
|
||||
|
||||
controllers := make([]agent.Controller, 0)
|
||||
|
||||
ctrlConf := conf.Agent.Controllers
|
||||
|
||||
if ctrlConf.Persistence.Enabled {
|
||||
controllers = append(controllers, persistence.NewController(string(ctrlConf.Persistence.StateFile)))
|
||||
}
|
||||
|
||||
if ctrlConf.Spec.Enabled {
|
||||
controllers = append(controllers, spec.NewController(string(ctrlConf.Spec.ServerURL)))
|
||||
}
|
||||
|
||||
if ctrlConf.Gateway.Enabled {
|
||||
controllers = append(controllers, gateway.NewController())
|
||||
}
|
||||
|
||||
if ctrlConf.UCI.Enabled {
|
||||
controllers = append(controllers, openwrt.NewUCIController(
|
||||
string(ctrlConf.UCI.BinPath),
|
||||
))
|
||||
}
|
||||
|
||||
agent := agent.New(
|
||||
agent.WithInterval(time.Duration(conf.Agent.ReconciliationInterval)*time.Second),
|
||||
agent.WithControllers(controllers...),
|
||||
)
|
||||
|
||||
if err := agent.Run(ctx.Context); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user