fix(configuration): resolve the default config path in one place
Four binaries derived the default with os.UserConfigDir while the daemon resolved it from its own config home. The two agree on Linux with an absolute XDG_CONFIG_HOME and diverge everywhere else, so one deployment booted from a different config file depending on which binary started. Move the rule into the package that owns configuration resolution (internal/infrastructure/configuration, which already owns xdgDataHome and DefaultWorkDir) as DefaultConfigDir/DefaultConfigPath, and have every -config default take it from there: archie-gateway, archie-messaging, archie-state-store (serve and recovery) and archie-ui, plus the daemon's own parseArgs, setup generator and drain-marker path. Fence the claim at the source, since the resolved value is only observable by starting a process: no source under cmd/ or internal/app/archied may call os.UserConfigDir, and every -config registration must default to the helper.
This commit is contained in:
1 parent
51feab85e5
commit
856e2eef71
12 files changed
+369
-75
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/drain"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
drainio "github.com/samcharles93/archie-core/internal/infrastructure/drain"
|
||||
)
|
||||
|
||||
@@ -17,14 +18,14 @@ import (
|
||||
const defaultDrainPollInterval = 5 * time.Second
|
||||
|
||||
// DefaultDrainRequestPath returns the marker file path the daemon watches. It
|
||||
// lives under the repo's config home (${XDG_CONFIG_HOME:-~/.config}/archie) --
|
||||
// the established convention for archied's per-user paths -- rather than the
|
||||
// lives under the config home (${XDG_CONFIG_HOME:-~/.config}/archie) -- the
|
||||
// established convention for archied's per-user paths -- rather than the
|
||||
// epic's literal ~/.archie, which is not a path this daemon ever uses. The
|
||||
// discrepancy is intentional: every other archied path reads from the XDG
|
||||
// config home, so the drain marker must too, or an operator pointing at the
|
||||
// documented location would miss it.
|
||||
func DefaultDrainRequestPath() string {
|
||||
return filepath.Join(configHome(), "archie", drainio.DefaultMarkerFilename)
|
||||
return filepath.Join(configuration.DefaultConfigDir(), drainio.DefaultMarkerFilename)
|
||||
}
|
||||
|
||||
// monitorDrainRequests polls check for a live drain request and invokes
|
||||
|
||||
@@ -315,9 +315,8 @@ type runArgs struct {
|
||||
}
|
||||
|
||||
func parseArgs() (runArgs, bool) {
|
||||
defaultCfg := DefaultConfigPath()
|
||||
var args runArgs
|
||||
flag.StringVar(&args.cfgPath, "config", defaultCfg, "path to a TOML/YAML config file or configuration directory")
|
||||
flag.StringVar(&args.cfgPath, "config", configuration.DefaultConfigPath(), "path to a TOML/YAML config file or configuration directory")
|
||||
flag.StringVar(&args.overlayPath, "config-overlay", "", "path to a TOML/YAML overlay file or configuration directory applied on top of -config")
|
||||
flag.BoolVar(&args.once, "once", false, "run a single poll+process cycle and exit (systemd timer / testing)")
|
||||
flag.Int64Var(&args.requeue, "requeue", 0, "requeue a parked/waiting task by id (keeps its workflow), then exit unless -once is also set")
|
||||
@@ -910,23 +909,6 @@ func configuredNATSToken(cfg config.NATSConfig, getenv func(string) string) (str
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func configHome() string {
|
||||
if x := os.Getenv("XDG_CONFIG_HOME"); x != "" {
|
||||
return x
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
return filepath.Join(home, ".config")
|
||||
}
|
||||
|
||||
// DefaultConfigPath is the configuration the daemon reads when -config is not
|
||||
// given, and the one every command that asks a question about the daemon has to
|
||||
// read to be answering about the same deployment: it is the daemon's rule, not
|
||||
// a second one. It is exported for exactly that reason -- an offline command
|
||||
// resolving the default any other way answers about a different config file
|
||||
// (os.UserConfigDir, notably, rejects a relative XDG_CONFIG_HOME outright and
|
||||
// leaves the caller with no path at all).
|
||||
func DefaultConfigPath() string { return filepath.Join(configHome(), "archie", "config.toml") }
|
||||
|
||||
// updateReportPath is where the update watchdog leaves the phase-2 outcome
|
||||
// of an update for this identity to relay on its next launch. The identity is
|
||||
// hashed so multiple identities sharing one daemon (see
|
||||
|
||||
@@ -67,7 +67,7 @@ type setupFlags struct {
|
||||
|
||||
func bindSetupFlags(fs *flag.FlagSet) *setupFlags {
|
||||
f := &setupFlags{}
|
||||
fs.StringVar(&f.cfgPath, "config", filepath.Join(configHome(), "archie", "config.toml"), "path to write config.toml")
|
||||
fs.StringVar(&f.cfgPath, "config", configuration.DefaultConfigPath(), "path to write config.toml")
|
||||
fs.BoolVar(&f.defaults, "defaults", false, "write a known-valid unattended baseline config without prompting")
|
||||
fs.StringVar(&f.botUser, "bot-user", "", "forge username for archied's commits and API calls")
|
||||
fs.StringVar(&f.operator, "operator", "", "operator display name (optional)")
|
||||
|
||||
Reference in new issue
Block a user