refactor: initial commit for major rewrite

This commit is contained in:
David Allen 2025-08-03 20:25:18 -06:00
parent 3253cb8bbb
commit bfd83f35a3
Signed by: towk
GPG key ID: 0430CDBE22619155
45 changed files with 439 additions and 1733 deletions

View file

@ -4,35 +4,20 @@ import (
"fmt"
"os"
"github.com/OpenCHAMI/configurator/pkg/config"
"github.com/OpenCHAMI/configurator/pkg/util"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
var (
conf config.Config
configPath string
cacertPath string
verbose bool
targets []string
outputPath string
accessToken string
remoteHost string
)
var rootCmd = &cobra.Command{
Use: "configurator",
Short: "Dynamically generate files defined by generators",
var rootCmd = cobra.Command{
Use: "configurator",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
os.Exit(0)
}
},
}
func Execute() {
// run initialization code first
initEnv()
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
@ -40,39 +25,13 @@ func Execute() {
}
func init() {
cobra.OnInitialize(InitConfig)
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "set the config path")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "set to enable verbose output")
rootCmd.PersistentFlags().StringVar(&cacertPath, "cacert", "", "path to CA cert. (defaults to system CAs)")
// initialize the config a single time
}
func InitConfig() {
// empty from not being set
if configPath != "" {
exists, err := util.PathExists(configPath)
if err != nil {
log.Error().Err(err).Str("path", configPath).Msg("failed to load config")
os.Exit(1)
} else if exists {
conf = config.Load(configPath)
} else {
// show error and exit since a path was specified
log.Error().Str("path", configPath).Msg("config file not found")
os.Exit(1)
}
} else {
// set to the default value and create a new one
configPath = "./config.yaml"
conf = config.New()
}
func initConfigFromFile(path string) {
}
func initEnv() {
//
// set environment variables to override config values
//
// set the JWKS url if we find the CONFIGURATOR_JWKS_URL environment variable
jwksUrl := os.Getenv("CONFIGURATOR_JWKS_URL")
if jwksUrl != "" {
conf.Server.Jwks.Uri = jwksUrl
}
}