Add host specific headers

Allows configuring headers per registry host

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2020-05-18 16:38:45 -07:00
parent 84619ee998
commit 3dd8242a67
4 changed files with 56 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"
"net/http"
"path/filepath"
"testing"
@@ -76,11 +77,15 @@ func TestParseHostFile(t *testing.T) {
const testtoml = `
server = "https://test-default.registry"
ca = "/etc/path/default"
[header]
x-custom-1 = "custom header"
[host."https://mirror.registry"]
capabilities = ["pull"]
ca = "/etc/certs/mirror.pem"
skip_verify = false
[host."https://mirror.registry".header]
x-custom-2 = ["value1", "value2"]
[host."https://mirror-bak.registry/us"]
capabilities = ["pull"]
@@ -109,6 +114,7 @@ ca = "/etc/path/default"
capabilities: docker.HostCapabilityPull,
caCerts: []string{filepath.FromSlash("/etc/certs/mirror.pem")},
skipVerify: &fb,
header: http.Header{"x-custom-2": {"value1", "value2"}},
},
{
scheme: "https",
@@ -159,6 +165,7 @@ ca = "/etc/path/default"
path: "/v2",
capabilities: allCaps,
caCerts: []string{filepath.FromSlash("/etc/path/default")},
header: http.Header{"x-custom-1": {"custom header"}},
},
}
hosts, err := parseHostsFile(ctx, "", []byte(testtoml))
@@ -241,6 +248,20 @@ func compareHostConfig(j, k hostConfig) bool {
return false
}
if len(j.header) != len(k.header) {
return false
}
for key := range j.header {
if len(j.header[key]) != len(k.header[key]) {
return false
}
for i := range j.header[key] {
if j.header[key][i] != k.header[key][i] {
return false
}
}
}
return true
}
@@ -258,6 +279,7 @@ func printHostConfig(hc []hostConfig) string {
} else {
fmt.Fprintf(b, "\t\tskip-verify: %t\n", *hc[i].skipVerify)
}
fmt.Fprintf(b, "\t\theader: %#v\n", hc[i].header)
}
return b.String()
}