working commit
This commit is contained in:
+38
-9
@@ -23,14 +23,23 @@ import (
|
||||
ocidigest "github.com/opencontainers/go-digest"
|
||||
)
|
||||
|
||||
func (cli *Client) GetRawManifest(ctx context.Context, rawrepo string) (bool, string, []byte, string, error) {
|
||||
const (
|
||||
ddmMediaType = "application/vnd.docker.distribution.manifest.v2+json"
|
||||
oimMediaType = "application/vnd.oci.image.manifest.v1+json"
|
||||
ddmlMediaType = "application/vnd.docker.distribution.manifest.list.v2+json"
|
||||
oiiMeiaType = "application/vnd.oci.image.index.v1+json"
|
||||
|
||||
//application/vnd.docker.distribution.manifest.v1+json
|
||||
//application/vnd.docker.distribution.manifest.v1+prettyjws
|
||||
)
|
||||
|
||||
func (cli *Client) GetRawManifest(ctx context.Context, rawrepo string, accepts []string) (bool, string, []byte, string, error) {
|
||||
var err error
|
||||
var exist bool
|
||||
var mime string
|
||||
var man []byte
|
||||
var digstr string
|
||||
|
||||
fmt.Printf("=== %s\n", rawrepo)
|
||||
ref, err := NewReferer(rawrepo)
|
||||
if err != nil {
|
||||
return exist, mime, man, digstr, err
|
||||
@@ -42,7 +51,16 @@ func (cli *Client) GetRawManifest(ctx context.Context, rawrepo string) (bool, st
|
||||
return exist, mime, man, digstr, err
|
||||
}
|
||||
req.Header.Set("User-Agent", cli.userAgent)
|
||||
req.Header.Set("Accept", "*/*")
|
||||
if len(accepts) == 0 {
|
||||
accepts = []string{
|
||||
MediaTypeDDMLv2,
|
||||
MediaTypeDDMv2,
|
||||
MediaTypeOIMv1,
|
||||
MediaTypeOIIv1,
|
||||
}
|
||||
}
|
||||
req.Header.Set("Accept", strings.Join(accepts, ","))
|
||||
|
||||
resp, err := cli.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return exist, mime, man, digstr, err
|
||||
@@ -56,9 +74,25 @@ func (cli *Client) GetRawManifest(ctx context.Context, rawrepo string) (bool, st
|
||||
err := fmt.Errorf("Unxected response code %s", resp.Status)
|
||||
return exist, mime, man, digstr, err
|
||||
}
|
||||
mime = resp.Header.Get("Content-Type")
|
||||
if mime == "" {
|
||||
err := fmt.Errorf("Empty MIME type declaration")
|
||||
return exist, mime, man, digstr, err
|
||||
}
|
||||
accepted := false
|
||||
for _, accept := range accepts {
|
||||
if mime == accept {
|
||||
accepted = true
|
||||
}
|
||||
}
|
||||
if !accepted {
|
||||
err := fmt.Errorf("Unknown content type: %s", mime)
|
||||
return exist, mime, man, digstr, err
|
||||
|
||||
}
|
||||
digstr = resp.Header.Get("Docker-Content-Digest")
|
||||
if digstr == "" {
|
||||
err := fmt.Errorf("Empty digest declaration")
|
||||
err := fmt.Errorf("Empty manifest digest declaration")
|
||||
return exist, mime, man, digstr, err
|
||||
}
|
||||
contentLength := resp.Header.Get("Content-Length")
|
||||
@@ -70,11 +104,6 @@ func (cli *Client) GetRawManifest(ctx context.Context, rawrepo string) (bool, st
|
||||
if err != nil {
|
||||
return exist, mime, man, digstr, err
|
||||
}
|
||||
mime = resp.Header.Get("Content-Type")
|
||||
if mime == "" {
|
||||
err := fmt.Errorf("Empty MIME type declaration")
|
||||
return exist, mime, man, digstr, err
|
||||
}
|
||||
digstr = strings.ToLower(digstr)
|
||||
digobj, err := ocidigest.Parse(digstr)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user