Files
zeekay 68a9e372a8 rebrand: fork paerser → ingress-parser, eliminate all traefik strings
- Fork github.com/traefik/paerser to github.com/hanzoai/ingress-parser
  with rebranded prefixes (TRAEFIK_ → INGRESS_, traefik. → ingress.)
- Update all 71 Go files importing paerser to use ingress-parser
- CLI flags: traefik.configfile → ingress.configfile
- Env prefix: TRAEFIK_* → INGRESS_*
- Deprecation loader: traefik. label prefix → ingress.
- Recompute digest auth test hashes for realm "ingress"
- Rename traefiker test realm → ingresser
- Fix remaining comment URLs to hanzoai/ingress

7 remaining "traefik" refs are Go import paths for external
packages (traefik/yaegi, traefik/grpc-web) — these are the
packages' module identity, cannot be renamed without forking
the entire Go interpreter and gRPC-Web proxy.
2026-03-19 03:31:43 -07:00

85 lines
2.1 KiB
Go

package cli
import (
"os"
"strings"
"github.com/rs/zerolog/log"
"github.com/hanzoai/ingress-parser/cli"
"github.com/hanzoai/ingress-parser/file"
"github.com/hanzoai/ingress-parser/flag"
)
// FileLoader loads a configuration from a file.
type FileLoader struct {
ConfigFileFlag string
filename string
}
// GetFilename returns the configuration file if any.
func (f *FileLoader) GetFilename() string {
return f.filename
}
// Load loads the command's configuration from a file either specified with the -ingress.configfile flag, or from default locations.
func (f *FileLoader) Load(args []string, cmd *cli.Command) (bool, error) {
ref, err := flag.Parse(args, cmd.Configuration)
if err != nil {
_ = cmd.PrintHelp(os.Stdout)
return false, err
}
configFileFlag := "ingress.configfile"
if _, ok := ref["ingress.configFile"]; ok {
configFileFlag = "ingress.configFile"
}
if f.ConfigFileFlag != "" {
configFileFlag = "ingress." + f.ConfigFileFlag
if _, ok := ref[strings.ToLower(configFileFlag)]; ok {
configFileFlag = "ingress." + strings.ToLower(f.ConfigFileFlag)
}
}
configFile, err := loadConfigFiles(ref[configFileFlag], cmd.Configuration)
if err != nil {
return false, err
}
f.filename = configFile
if configFile == "" {
return false, nil
}
log.Printf("Configuration loaded from file: %s", configFile)
content, _ := os.ReadFile(configFile)
log.Debug().Str("configFile", configFile).Bytes("content", content).Send()
return true, nil
}
// loadConfigFiles tries to decode the given configuration file and all default locations for the configuration file.
// It stops as soon as decoding one of them is successful.
func loadConfigFiles(configFile string, element any) (string, error) {
finder := cli.Finder{
BasePaths: []string{"/etc/ingress/ingress", "$XDG_CONFIG_HOME/ingress", "$HOME/.config/ingress", "./ingress"},
Extensions: []string{"toml", "yaml", "yml"},
}
filePath, err := finder.Find(configFile)
if err != nil {
return "", err
}
if len(filePath) == 0 {
return "", nil
}
if err := file.Decode(filePath, element); err != nil {
return "", err
}
return filePath, nil
}