expand the path to support working in systemd service
This commit is contained in:
parent
ba34ac0d67
commit
29fe7f76c1
3 changed files with 27 additions and 3 deletions
|
|
@ -37,8 +37,8 @@ func Load(path string) (*Config, error) {
|
|||
return nil, fmt.Errorf("parsing config file: %w", err)
|
||||
}
|
||||
|
||||
cfg.NetrcPath = os.ExpandEnv(cfg.NetrcPath)
|
||||
cfg.ClientSecretFile = os.ExpandEnv(cfg.ClientSecretFile)
|
||||
cfg.NetrcPath = expandPath(cfg.NetrcPath)
|
||||
cfg.ClientSecretFile = expandPath(cfg.ClientSecretFile)
|
||||
|
||||
if cfg.ClientSecretFile != "" {
|
||||
secret, err := os.ReadFile(cfg.ClientSecretFile)
|
||||
|
|
@ -71,6 +71,29 @@ func (c *Config) validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// expandPath expands environment variables in a path. XDG base directory
|
||||
// variables are resolved using the xdg library, which applies the XDG spec
|
||||
// fallbacks (e.g. $HOME/.config when $XDG_CONFIG_HOME is unset). This ensures
|
||||
// correct behaviour in systemd user services, which do not set XDG variables.
|
||||
func expandPath(s string) string {
|
||||
return os.Expand(s, func(key string) string {
|
||||
switch key {
|
||||
case "XDG_CONFIG_HOME":
|
||||
return xdg.ConfigHome
|
||||
case "XDG_DATA_HOME":
|
||||
return xdg.DataHome
|
||||
case "XDG_CACHE_HOME":
|
||||
return xdg.CacheHome
|
||||
case "XDG_STATE_HOME":
|
||||
return xdg.StateHome
|
||||
case "XDG_RUNTIME_DIR":
|
||||
return xdg.RuntimeDir
|
||||
default:
|
||||
return os.Getenv(key)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// RefreshTokenPath returns the path to the stored refresh token.
|
||||
func RefreshTokenPath() string {
|
||||
return filepath.Join(xdg.ConfigHome, "nix-cache-login", "refresh-token")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue