fix token

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-06-06 15:43:12 -04:00
parent 307f7c8400
commit 294bae7b50
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
5 changed files with 28 additions and 3 deletions

View file

@ -34,6 +34,8 @@ func (c *Clair) PostLayer(layer *Layer) (*Layer, error) {
return nil, err
}
c.Logf("clair.clair req.Body=%s", string(b))
resp, err := c.Client.Post(url, "application/json", bytes.NewReader(b))
if err != nil {
return nil, err

View file

@ -138,7 +138,7 @@ func (c *Clair) NewClairLayerV2(r *registry.Registry, image string, fsLayers []d
if err != nil {
// If we get an error here of type: malformed auth challenge header: 'Basic realm="Registry Realm"'
// We need to use basic auth for the registry.
if !strings.Contains(err.Error(), `malformed auth challenge header: 'Basic realm="Registry Realm"'`) {
if !strings.Contains(err.Error(), `malformed auth challenge header: 'Basic realm="Registry Realm"'`) && !strings.Contains(err.Error(), "basic auth required") {
return nil, err
}
useBasicAuth = true

View file

@ -42,6 +42,14 @@ func TestParseChallenge(t *testing.T) {
realm: "https://foobar.com/api/v1/token",
},
},
{
header: `Bearer realm="https://r.j3ss.co/auth",service="Docker registry",scope="repository:chrome:pull"`,
value: authServiceMock{
service: "Docker registry",
realm: "https://r.j3ss.co/auth",
scope: []string{"repository:chrome:pull"},
},
},
}
for _, tc := range challengeHeaderCases {

View file

@ -23,6 +23,7 @@ type Registry struct {
Password string
Client *http.Client
Logf LogfCallback
Opt Opt
}
var reProtocol = regexp.MustCompile("^https?://")
@ -99,6 +100,7 @@ func newFromTransport(auth types.AuthConfig, transport http.RoundTripper, opt Op
Username: auth.Username,
Password: auth.Password,
Logf: logf,
Opt: opt,
}
if !opt.SkipPing {

View file

@ -1,6 +1,7 @@
package registry
import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
@ -123,7 +124,19 @@ func (r *Registry) Token(url string) (string, error) {
return "", err
}
resp, err := r.Client.Do(req)
client := http.DefaultClient
if r.Opt.Insecure {
client = &http.Client{
Timeout: r.Opt.Timeout,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
}
resp, err := client.Do(req)
if err != nil {
return "", err
}
@ -143,7 +156,7 @@ func (r *Registry) Token(url string) (string, error) {
if err != nil {
return "", err
}
resp, err = r.Client.Do(authReq)
resp, err = http.DefaultClient.Do(authReq)
if err != nil {
return "", err
}