Merge pull request #491 from Foxboron/morten/fix-docker-env
pkg/auth: Ensure DOCKER_CONFIG refers to config.json
This commit is contained in:
commit
b30f2cad04
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/image/v5/docker"
|
"github.com/containers/image/v5/docker"
|
||||||
|
|
@ -20,11 +21,13 @@ import (
|
||||||
// --authfile path used in multiple --authfile flag definitions
|
// --authfile path used in multiple --authfile flag definitions
|
||||||
// Will fail over to DOCKER_CONFIG if REGISTRY_AUTH_FILE environment is not set
|
// Will fail over to DOCKER_CONFIG if REGISTRY_AUTH_FILE environment is not set
|
||||||
func GetDefaultAuthFile() string {
|
func GetDefaultAuthFile() string {
|
||||||
authfile := os.Getenv("REGISTRY_AUTH_FILE")
|
if authfile := os.Getenv("REGISTRY_AUTH_FILE"); authfile != "" {
|
||||||
if authfile == "" {
|
|
||||||
authfile = os.Getenv("DOCKER_CONFIG")
|
|
||||||
}
|
|
||||||
return authfile
|
return authfile
|
||||||
|
}
|
||||||
|
if auth_env := os.Getenv("DOCKER_CONFIG"); auth_env != "" {
|
||||||
|
return filepath.Join(auth_env, "config.json")
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckAuthFile validates filepath given by --authfile
|
// CheckAuthFile validates filepath given by --authfile
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ var _ = Describe("Config", func() {
|
||||||
It("validate GetDefaultAuthFile", func() {
|
It("validate GetDefaultAuthFile", func() {
|
||||||
// Given
|
// Given
|
||||||
oldDockerConf, envDockerSet := os.LookupEnv("DOCKER_CONFIG")
|
oldDockerConf, envDockerSet := os.LookupEnv("DOCKER_CONFIG")
|
||||||
os.Setenv("DOCKER_CONFIG", "/tmp/docker.file")
|
os.Setenv("DOCKER_CONFIG", "/tmp")
|
||||||
oldConf, envSet := os.LookupEnv("REGISTRY_AUTH_FILE")
|
oldConf, envSet := os.LookupEnv("REGISTRY_AUTH_FILE")
|
||||||
os.Setenv("REGISTRY_AUTH_FILE", "/tmp/registry.file")
|
os.Setenv("REGISTRY_AUTH_FILE", "/tmp/registry.file")
|
||||||
// When // When
|
// When // When
|
||||||
|
|
@ -26,7 +26,7 @@ var _ = Describe("Config", func() {
|
||||||
// Fall back to DOCKER_CONFIG
|
// Fall back to DOCKER_CONFIG
|
||||||
authFile = GetDefaultAuthFile()
|
authFile = GetDefaultAuthFile()
|
||||||
// Then
|
// Then
|
||||||
gomega.Expect(authFile).To(gomega.BeEquivalentTo("/tmp/docker.file"))
|
gomega.Expect(authFile).To(gomega.BeEquivalentTo("/tmp/config.json"))
|
||||||
os.Unsetenv("DOCKER_CONFIG")
|
os.Unsetenv("DOCKER_CONFIG")
|
||||||
|
|
||||||
// Fall back to DOCKER_CONFIG
|
// Fall back to DOCKER_CONFIG
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue