Merge pull request #7740 from LK4D4/registry_style
Style fixes for registry/registry.go
This commit is contained in:
commit
48096dad19
1 changed files with 20 additions and 31 deletions
|
@ -105,23 +105,21 @@ func doRequest(req *http.Request, jar http.CookieJar, timeout TimeoutType) (*htt
|
||||||
data, err := ioutil.ReadFile(path.Join(hostDir, f.Name()))
|
data, err := ioutil.ReadFile(path.Join(hostDir, f.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
} else {
|
|
||||||
pool.AppendCertsFromPEM(data)
|
|
||||||
}
|
}
|
||||||
|
pool.AppendCertsFromPEM(data)
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(f.Name(), ".cert") {
|
if strings.HasSuffix(f.Name(), ".cert") {
|
||||||
certName := f.Name()
|
certName := f.Name()
|
||||||
keyName := certName[:len(certName)-5] + ".key"
|
keyName := certName[:len(certName)-5] + ".key"
|
||||||
if !hasFile(fs, keyName) {
|
if !hasFile(fs, keyName) {
|
||||||
return nil, nil, fmt.Errorf("Missing key %s for certificate %s", keyName, certName)
|
return nil, nil, fmt.Errorf("Missing key %s for certificate %s", keyName, certName)
|
||||||
} else {
|
}
|
||||||
cert, err := tls.LoadX509KeyPair(path.Join(hostDir, certName), path.Join(hostDir, keyName))
|
cert, err := tls.LoadX509KeyPair(path.Join(hostDir, certName), path.Join(hostDir, keyName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
certs = append(certs, &cert)
|
certs = append(certs, &cert)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if strings.HasSuffix(f.Name(), ".key") {
|
if strings.HasSuffix(f.Name(), ".key") {
|
||||||
keyName := f.Name()
|
keyName := f.Name()
|
||||||
certName := keyName[:len(keyName)-4] + ".cert"
|
certName := keyName[:len(keyName)-4] + ".cert"
|
||||||
|
@ -138,19 +136,13 @@ func doRequest(req *http.Request, jar http.CookieJar, timeout TimeoutType) (*htt
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return res, client, nil
|
return res, client, nil
|
||||||
} else {
|
}
|
||||||
for i, cert := range certs {
|
for i, cert := range certs {
|
||||||
client := newClient(jar, pool, cert, timeout)
|
client := newClient(jar, pool, cert, timeout)
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if i == len(certs)-1 {
|
// If this is the last cert, otherwise, continue to next cert if 403 or 5xx
|
||||||
// If this is the last cert, always return the result
|
if i == len(certs)-1 || err == nil && res.StatusCode != 403 && res.StatusCode < 500 {
|
||||||
return res, client, err
|
return res, client, err
|
||||||
} else {
|
|
||||||
// Otherwise, continue to next cert if 403 or 5xx
|
|
||||||
if err == nil && res.StatusCode != 403 && !(res.StatusCode >= 500 && res.StatusCode < 600) {
|
|
||||||
return res, client, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,10 +190,7 @@ func pingRegistryEndpoint(endpoint string) (RegistryInfo, error) {
|
||||||
|
|
||||||
standalone := resp.Header.Get("X-Docker-Registry-Standalone")
|
standalone := resp.Header.Get("X-Docker-Registry-Standalone")
|
||||||
log.Debugf("Registry standalone header: '%s'", standalone)
|
log.Debugf("Registry standalone header: '%s'", standalone)
|
||||||
// Accepted values are "true" (case-insensitive) and "1".
|
if !strings.EqualFold(standalone, "true") && standalone != "1" && len(standalone) > 0 {
|
||||||
if strings.EqualFold(standalone, "true") || standalone == "1" {
|
|
||||||
info.Standalone = true
|
|
||||||
} else if len(standalone) > 0 {
|
|
||||||
// there is a header set, and it is not "true" or "1", so assume fails
|
// there is a header set, and it is not "true" or "1", so assume fails
|
||||||
info.Standalone = false
|
info.Standalone = false
|
||||||
}
|
}
|
||||||
|
@ -306,7 +295,8 @@ func AddRequiredHeadersToRedirectedRequests(req *http.Request, via []*http.Reque
|
||||||
if via != nil && via[0] != nil {
|
if via != nil && via[0] != nil {
|
||||||
if trustedLocation(req) && trustedLocation(via[0]) {
|
if trustedLocation(req) && trustedLocation(via[0]) {
|
||||||
req.Header = via[0].Header
|
req.Header = via[0].Header
|
||||||
} else {
|
return nil
|
||||||
|
}
|
||||||
for k, v := range via[0].Header {
|
for k, v := range via[0].Header {
|
||||||
if k != "Authorization" {
|
if k != "Authorization" {
|
||||||
for _, vv := range v {
|
for _, vv := range v {
|
||||||
|
@ -315,6 +305,5 @@ func AddRequiredHeadersToRedirectedRequests(req *http.Request, via []*http.Reque
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue