pkg/plugins: split exported from implementation
Split the exported SpecsPaths from the platform-specific implementations, so that documentation can be maintained in a single location. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
954d50b88a
commit
a44c25c2f1
3 changed files with 26 additions and 20 deletions
|
@ -26,7 +26,7 @@ type LocalRegistry struct {
|
|||
|
||||
func NewLocalRegistry() LocalRegistry {
|
||||
return LocalRegistry{
|
||||
SpecsPaths,
|
||||
SpecsPaths: specsPaths,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,25 @@ func (l *LocalRegistry) Plugin(name string) (*Plugin, error) {
|
|||
return nil, errors.Wrapf(ErrNotFound, "could not find plugin %s in v1 plugin registry", name)
|
||||
}
|
||||
|
||||
// SpecsPaths returns paths in which to look for plugins, in order of priority.
|
||||
//
|
||||
// On Windows:
|
||||
//
|
||||
// - "%programdata%\docker\plugins"
|
||||
//
|
||||
// On Unix in non-rootless mode:
|
||||
//
|
||||
// - "/etc/docker/plugins"
|
||||
// - "/usr/lib/docker/plugins"
|
||||
//
|
||||
// On Unix in rootless-mode:
|
||||
//
|
||||
// - "$XDG_CONFIG_HOME/docker/plugins" (or "/etc/docker/plugins" if $XDG_CONFIG_HOME is not set)
|
||||
// - "$HOME/.local/lib/docker/plugins" (pr "/usr/lib/docker/plugins" if $HOME is set)
|
||||
func SpecsPaths() []string {
|
||||
return specsPaths()
|
||||
}
|
||||
|
||||
func readPluginInfo(name, path string) (*Plugin, error) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,32 +9,23 @@ import (
|
|||
)
|
||||
|
||||
func rootlessConfigPluginsPath() string {
|
||||
configHome, err := homedir.GetConfigHome()
|
||||
if err == nil {
|
||||
if configHome, err := homedir.GetConfigHome(); err != nil {
|
||||
return filepath.Join(configHome, "docker/plugins")
|
||||
}
|
||||
|
||||
return "/etc/docker/plugins"
|
||||
}
|
||||
|
||||
func rootlessLibPluginsPath() string {
|
||||
libHome, err := homedir.GetLibHome()
|
||||
if err == nil {
|
||||
if libHome, err := homedir.GetLibHome(); err == nil {
|
||||
return filepath.Join(libHome, "docker/plugins")
|
||||
}
|
||||
|
||||
return "/usr/lib/docker/plugins"
|
||||
}
|
||||
|
||||
// SpecsPaths returns
|
||||
// { "%programdata%\docker\plugins" } on Windows,
|
||||
// { "/etc/docker/plugins", "/usr/lib/docker/plugins" } on Unix in non-rootless mode,
|
||||
// { "$XDG_CONFIG_HOME/docker/plugins", "$HOME/.local/lib/docker/plugins" } on Unix in rootless mode
|
||||
// with fallback to the corresponding path in non-rootless mode if $XDG_CONFIG_HOME or $HOME is not set.
|
||||
func SpecsPaths() []string {
|
||||
// specsPaths is the non-Windows implementation of [SpecsPaths].
|
||||
func specsPaths() []string {
|
||||
if rootless.RunningWithRootlessKit() {
|
||||
return []string{rootlessConfigPluginsPath(), rootlessLibPluginsPath()}
|
||||
}
|
||||
|
||||
return []string{"/etc/docker/plugins", "/usr/lib/docker/plugins"}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,7 @@ import (
|
|||
"path/filepath"
|
||||
)
|
||||
|
||||
// SpecsPaths returns
|
||||
// { "%programdata%\docker\plugins" } on Windows,
|
||||
// { "/etc/docker/plugins", "/usr/lib/docker/plugins" } on Unix in non-rootless mode,
|
||||
// { "$XDG_CONFIG_HOME/docker/plugins", "$HOME/.local/lib/docker/plugins" } on Unix in rootless mode
|
||||
// with fallback to the corresponding path in non-rootless mode if $XDG_CONFIG_HOME or $HOME is not set.
|
||||
func SpecsPaths() []string {
|
||||
// specsPaths is the Windows implementation of [SpecsPaths].
|
||||
func specsPaths() []string {
|
||||
return []string{filepath.Join(os.Getenv("programdata"), "docker", "plugins")}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue