working commit
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (cli *Client) GetManifest(ctx context.Context, rawref string) (bool, string, []byte, error) {
|
||||
@@ -20,13 +20,23 @@ func (cli *Client) GetManifest(ctx context.Context, rawref string) (bool, string
|
||||
return exist, mime, man, err
|
||||
}
|
||||
uri := ref.Manifest()
|
||||
user, pass := ref.Userinfo()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
|
||||
if err != nil {
|
||||
return exist, mime, man, err
|
||||
}
|
||||
req.Header.Set("User-Agent", cli.userAgent)
|
||||
req.Header.Set("Accept", "*/*")
|
||||
req.Header.Set("Accept", "*/*")
|
||||
|
||||
if cli.authenticator != nil {
|
||||
authHeader, authKey, err := cli.authenticator.MakeHeader(user, pass)
|
||||
if err != nil {
|
||||
return exist, mime, man, err
|
||||
}
|
||||
req.Header.Set(authHeader, authKey)
|
||||
}
|
||||
|
||||
resp, err := cli.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return exist, mime, man, err
|
||||
@@ -51,12 +61,35 @@ func (cli *Client) GetManifest(ctx context.Context, rawref string) (bool, string
|
||||
return exist, mime, man, err
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
recSize, err := io.Copy(buffer, resp.Body)
|
||||
recSize, err := Copy(ctx, buffer, resp.Body)
|
||||
if manSize != recSize {
|
||||
err := fmt.Errorf("Mismatch declared and actual body size")
|
||||
err := fmt.Errorf("Mismatch declared and actual body size, %d and %d", manSize, recSize)
|
||||
return exist, mime, man, err
|
||||
}
|
||||
man = buffer.Bytes()
|
||||
man = buffer.Bytes()
|
||||
|
||||
csum := resp.Header.Get("Docker-Content-Digest")
|
||||
if csum == "" {
|
||||
err := fmt.Errorf("Empty digest declaration")
|
||||
return exist, mime, man, err
|
||||
}
|
||||
csum = strings.ToLower(csum)
|
||||
switch DigestType(csum) {
|
||||
case SHA256:
|
||||
if csum != SHA256Digest(man) {
|
||||
err := fmt.Errorf("Mismatch digest and actual declaration")
|
||||
return exist, mime, man, err
|
||||
}
|
||||
case SHA512:
|
||||
if csum != SHA256Digest(man) {
|
||||
err := fmt.Errorf("Mismatch digest and actual declaration")
|
||||
return exist, mime, man, err
|
||||
}
|
||||
default:
|
||||
err := fmt.Errorf("Unknown digest type: %s", csum)
|
||||
return exist, mime, man, err
|
||||
}
|
||||
|
||||
exist = true
|
||||
return exist, mime, man, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user