Updated config and generator

This commit is contained in:
David J. Allen 2024-04-11 10:20:27 -06:00
parent 9678c3cddb
commit 92ef56a7fa
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
2 changed files with 28 additions and 8 deletions

View file

@ -8,16 +8,27 @@ import (
"gopkg.in/yaml.v2" "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 { type Config struct {
Version string `yaml:"version"` Version string `yaml:"version"`
SmdHost string `yaml:"smd-host"` SmdHost string `yaml:"smd-host"`
SmdPort int `yaml:"smd-port"` SmdPort int `yaml:"smd-port"`
AccessToken string `yaml:"access-token"` AccessToken string `yaml:"access-token"`
TemplatePaths map[string]string `yaml:"templates"` TemplatePaths map[string]string `yaml:"templates"`
Server Server `yaml:"server"`
Options Options `yaml:"options"`
} }
func NewConfig() *Config { func NewConfig() Config {
return &Config{ return Config{
Version: "", Version: "",
SmdHost: "http://127.0.0.1", SmdHost: "http://127.0.0.1",
SmdPort: 27779, SmdPort: 27779,
@ -28,11 +39,19 @@ func NewConfig() *Config {
"powerman": "templates/powerman", "powerman": "templates/powerman",
"conman": "templates/conman", "conman": "templates/conman",
}, },
Server: Server{
Host: "127.0.0.1",
Port: 3334,
},
Options: Options{
JwksUri: "",
JwksRetries: 5,
},
} }
} }
func LoadConfig(path string) *Config { func LoadConfig(path string) Config {
var c *Config = NewConfig() var c Config = NewConfig()
file, err := os.ReadFile(path) file, err := os.ReadFile(path)
if err != nil { if err != nil {
log.Printf("failed to read config file: %v\n", err) log.Printf("failed to read config file: %v\n", err)

View file

@ -11,6 +11,8 @@ import (
) )
type Generator struct { type Generator struct {
Type string
Template string
} }
func New() *Generator { func New() *Generator {
@ -24,12 +26,11 @@ func (g *Generator) GenerateDNS(config *configurator.Config) {
// TODO: print generated config file to STDOUT // 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 // generate file using gonja template
// TODO: load template file for DHCP path := config.TemplatePaths[g.Template]
path := config.TemplatePaths[target]
fmt.Printf("path: %s\neth count: %v\n", path, len(eths)) 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 { if err != nil {
return fmt.Errorf("failed to read template from file: %v", err) return fmt.Errorf("failed to read template from file: %v", err)
} }