config file search and application precedent doesn't follow the XDG spec
Summary
The documentation for glab cli say the following:
By default,
glab
follows the XDG Base Directory Spec. Configure it globally, locally, or per host
The linked documentation clearly states that there should be a search order applied when locating the configuration:
- Default configuration files should be installed to $sysconfdir/xdg/subdir/filename with $sysconfdir defaulting to /etc.
- A user-specific version of the configuration file may be created in $XDG_CONFIG_HOME/subdir/filename, taking into account the default value for $XDG_CONFIG_HOME if $XDG_CONFIG_HOME is not set.
- Lookups of the configuration file should search for ./subdir/filename relative to all base directories indicated by $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS . If an environment variable is either not set or empty, its default value as defined by this specification should be used instead.
As such I would expect that host-wide default configs would be applied from /etc/xdg/glab-cli/config.yaml
if present and no other more specific config is available at a higher precedence such as ~/.config/glab-cli/config.yaml
. However I have observed that no attempt seems to be made to apply the the config file search strategy as documented in the XDG specifications.
This is problematic as it is typical for both distro vendors and site operators to use host/site specific default configs to provide configuration defaults which comply with various expectations ranging from managed security policy to appropriate defaults such as pre-configuration for a hosted gitlab instance.
Steps to reproduce
-
On an arbitrary supported linux platform install the latest release package
$ sudo dnf install -y '``https://gitlab.com/gitlab-org/cli/-/releases/v1.73.0/downloads/glab_1.73.0_linux_amd64.rpm``'
-
Run glab once to bootstrap a default configuration
$ glab
$ ls -alFsh $HOME/.config/glab-cli
-
Install the configuration to the expected site/system wide default path per the XDG specification
$ sudo install -m 0644 $HOME/.config/glab-cli/config.yml /etc/xdg/glab-cli/
-
Delete the user configuration from our home directory
$ rm -rf $HOME/.config/glab-cli
-
Run glab and observe it doesn't do anything with the sitewide configuration and instead creates a new default configuration in the our home directory
$ glab
$ ls -alFsh $HOME/.config/glab-cli
What is the current bug behavior?
glab
doesn't follow the XDG specification for locating its configuration from the expected array of default paths.
What is the expected correct behavior?
Configuration files should be located and loaded according to the documented specification. Namely, all paths should be search in the order/precedence as defined in the spec and optionally glab should merge duplicated configuration in a sensible manner.
Relevant logs and/or screenshots
Possible fixes
- Replace the stubbed out configuration loading/parsing routines in
config/config_file.go
with a robust and compliant library implementation such as https://github.com/adrg/xdg
OR
- Do not claim compliance with a specification in the documentation
AND
- Provide documentation guidance for site operators and distro maintainers detailing the expected method for applying site/distro default configurations which may differ from the project's own default configuration.