update c/image

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-12-22 17:43:37 +01:00
parent 686c3fcd7a
commit cf5d9ffa49
No known key found for this signature in database
GPG Key ID: B2BEAD150DE936B9
2 changed files with 19 additions and 3 deletions

View File

@ -265,8 +265,21 @@ func (c *dockerClient) setupRequestAuth(req *http.Request) error {
}
chs := parseAuthHeader(res.Header)
if res.StatusCode != http.StatusUnauthorized || chs == nil || len(chs) == 0 {
// no need for bearer? wtf?
return nil
// try again one last time with Basic Auth (gcr.io for instance)
testReq2 := *req
// Do not use the body stream, or we couldn't reuse it for the "real" call later.
testReq2.Body = nil
testReq2.ContentLength = 0
testReq2.SetBasicAuth(c.username, c.password)
res, err := c.client.Do(&testReq2)
if err != nil {
return err
}
chs = parseAuthHeader(res.Header)
if res.StatusCode != http.StatusUnauthorized || chs == nil || len(chs) == 0 {
// no need for bearer? wtf?
return nil
}
}
// Arbitrarily use the first challenge, there is no reason to expect more than one.
challenge := chs[0]

View File

@ -6,6 +6,9 @@ import (
"github.com/pkg/errors"
// "docker/distribution/digest" requires us to load the algorithms that we
// want to use into the binary (it calls .Available).
_ "crypto/sha256"
"github.com/docker/distribution/digest"
distreference "github.com/docker/distribution/reference"
)
@ -55,7 +58,7 @@ type Canonical interface {
func ParseNamed(s string) (Named, error) {
named, err := distreference.ParseNamed(s)
if err != nil {
return nil, errors.Errorf("Error parsing reference: %q is not a valid repository/tag", s)
return nil, errors.Wrapf(err, "Error parsing reference: %q is not a valid repository/tag", s)
}
r, err := WithName(named.Name())
if err != nil {