From 92ef56a7fae6c3444afea286eb6395acb44d8708 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Thu, 11 Apr 2024 10:20:27 -0600 Subject: [PATCH] Updated config and generator --- internal/config.go | 27 +++++++++++++++++++++++---- internal/generator/generator.go | 9 +++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/internal/config.go b/internal/config.go index d817677..c674290 100644 --- a/internal/config.go +++ b/internal/config.go @@ -8,16 +8,27 @@ import ( "gopkg.in/yaml.v2" ) +type Options struct { + JwksUri string `yaml:"jwks-uri"` + JwksRetries int `yaml:"jwks-retries"` +} + +type Server struct { + Host string `yaml:"host"` + Port int `yaml:"port"` +} type Config struct { Version string `yaml:"version"` SmdHost string `yaml:"smd-host"` SmdPort int `yaml:"smd-port"` AccessToken string `yaml:"access-token"` TemplatePaths map[string]string `yaml:"templates"` + Server Server `yaml:"server"` + Options Options `yaml:"options"` } -func NewConfig() *Config { - return &Config{ +func NewConfig() Config { + return Config{ Version: "", SmdHost: "http://127.0.0.1", SmdPort: 27779, @@ -28,11 +39,19 @@ func NewConfig() *Config { "powerman": "templates/powerman", "conman": "templates/conman", }, + Server: Server{ + Host: "127.0.0.1", + Port: 3334, + }, + Options: Options{ + JwksUri: "", + JwksRetries: 5, + }, } } -func LoadConfig(path string) *Config { - var c *Config = NewConfig() +func LoadConfig(path string) Config { + var c Config = NewConfig() file, err := os.ReadFile(path) if err != nil { log.Printf("failed to read config file: %v\n", err) diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 6fbb849..589adb6 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -11,6 +11,8 @@ import ( ) type Generator struct { + Type string + Template string } func New() *Generator { @@ -24,12 +26,11 @@ func (g *Generator) GenerateDNS(config *configurator.Config) { // TODO: print generated config file to STDOUT } -func (g *Generator) GenerateDHCP(config *configurator.Config, target string, eths []configurator.EthernetInterface) error { +func (g *Generator) GenerateDHCP(config *configurator.Config, eths []configurator.EthernetInterface) error { // generate file using gonja template - // TODO: load template file for DHCP - path := config.TemplatePaths[target] + path := config.TemplatePaths[g.Template] fmt.Printf("path: %s\neth count: %v\n", path, len(eths)) - t, err := gonja.FromFile(config.TemplatePaths[target]) + t, err := gonja.FromFile(path) if err != nil { return fmt.Errorf("failed to read template from file: %v", err) }