Fix docker style cert loading.

The certs dir parsing was skipping over files instead of reading them,
as such the certs would never load.

It was also stating the file name rather than the full path for cert
pairs.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2021-01-28 23:50:10 +00:00
parent 9d5c1165a6
commit 1fd99e24a2
2 changed files with 118 additions and 4 deletions

View File

@@ -82,7 +82,6 @@ func ConfigureHosts(ctx context.Context, options HostOptions) docker.RegistryHos
return nil, err
}
}
}
// If hosts was not set, add a default host
@@ -490,7 +489,7 @@ func loadCertFiles(ctx context.Context, certsDir string) ([]hostConfig, error) {
}
hosts := make([]hostConfig, 1)
for _, f := range fs {
if !f.IsDir() {
if f.IsDir() {
continue
}
if strings.HasSuffix(f.Name(), ".crt") {
@@ -501,9 +500,9 @@ func loadCertFiles(ctx context.Context, certsDir string) ([]hostConfig, error) {
certFile := f.Name()
pair[0] = filepath.Join(certsDir, certFile)
// Check if key also exists
keyFile := certFile[:len(certFile)-5] + ".key"
keyFile := filepath.Join(certsDir, certFile[:len(certFile)-5]+".key")
if _, err := os.Stat(keyFile); err == nil {
pair[1] = filepath.Join(certsDir, keyFile)
pair[1] = keyFile
} else if !os.IsNotExist(err) {
return nil, err
}