mirror of
https://github.com/containers/podman.git
synced 2025-08-06 11:32:07 +08:00
Factor out the registries.conf location code in pkg/registries
The newly introduced SystemRegistriesConfPath somewhat decreases duplication, but more importantly will allow future callers to set just a types.SystemContext.SystemRegistriesConfPath and not call GetRegistries / GetInsecureRegistries at all. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
@ -13,21 +13,28 @@ import (
|
|||||||
// userRegistriesFile is the path to the per user registry configuration file.
|
// userRegistriesFile is the path to the per user registry configuration file.
|
||||||
var userRegistriesFile = filepath.Join(os.Getenv("HOME"), ".config/containers/registries.conf")
|
var userRegistriesFile = filepath.Join(os.Getenv("HOME"), ".config/containers/registries.conf")
|
||||||
|
|
||||||
// GetRegistries obtains the list of registries defined in the global registries file.
|
// SystemRegistriesConfPath returns an appropriate value for types.SystemContext.SystemRegistriesConfPath
|
||||||
func GetRegistries() ([]string, error) {
|
// (possibly "", which is not an error), taking into account rootless mode and environment variable overrides.
|
||||||
registryConfigPath := ""
|
//
|
||||||
|
// FIXME: This should be centralized in a global SystemContext initializer inherited throughout the code,
|
||||||
|
// not haphazardly called throughout the way it is being called now.
|
||||||
|
func SystemRegistriesConfPath() string {
|
||||||
|
if envOverride := os.Getenv("REGISTRIES_CONFIG_PATH"); len(envOverride) > 0 {
|
||||||
|
return envOverride
|
||||||
|
}
|
||||||
|
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
if _, err := os.Stat(userRegistriesFile); err == nil {
|
if _, err := os.Stat(userRegistriesFile); err == nil {
|
||||||
registryConfigPath = userRegistriesFile
|
return userRegistriesFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
envOverride := os.Getenv("REGISTRIES_CONFIG_PATH")
|
return ""
|
||||||
if len(envOverride) > 0 {
|
}
|
||||||
registryConfigPath = envOverride
|
|
||||||
}
|
// GetRegistries obtains the list of registries defined in the global registries file.
|
||||||
searchRegistries, err := sysregistries.GetRegistries(&types.SystemContext{SystemRegistriesConfPath: registryConfigPath})
|
func GetRegistries() ([]string, error) {
|
||||||
|
searchRegistries, err := sysregistries.GetRegistries(&types.SystemContext{SystemRegistriesConfPath: SystemRegistriesConfPath()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "unable to parse the registries.conf file")
|
return nil, errors.Wrapf(err, "unable to parse the registries.conf file")
|
||||||
}
|
}
|
||||||
@ -36,19 +43,7 @@ func GetRegistries() ([]string, error) {
|
|||||||
|
|
||||||
// GetInsecureRegistries obtains the list of insecure registries from the global registration file.
|
// GetInsecureRegistries obtains the list of insecure registries from the global registration file.
|
||||||
func GetInsecureRegistries() ([]string, error) {
|
func GetInsecureRegistries() ([]string, error) {
|
||||||
registryConfigPath := ""
|
registries, err := sysregistries.GetInsecureRegistries(&types.SystemContext{SystemRegistriesConfPath: SystemRegistriesConfPath()})
|
||||||
|
|
||||||
if rootless.IsRootless() {
|
|
||||||
if _, err := os.Stat(userRegistriesFile); err == nil {
|
|
||||||
registryConfigPath = userRegistriesFile
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
envOverride := os.Getenv("REGISTRIES_CONFIG_PATH")
|
|
||||||
if len(envOverride) > 0 {
|
|
||||||
registryConfigPath = envOverride
|
|
||||||
}
|
|
||||||
registries, err := sysregistries.GetInsecureRegistries(&types.SystemContext{SystemRegistriesConfPath: registryConfigPath})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "unable to parse the registries.conf file")
|
return nil, errors.Wrapf(err, "unable to parse the registries.conf file")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user