fix: support different type of registry response

This commit is contained in:
decentral1se 2021-08-10 13:16:41 +02:00
parent 83671f42a2
commit cbe74b24c4
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 25 additions and 3 deletions

View File

@ -116,7 +116,7 @@ func GetTagDigest(image reference.Named) (string, error) {
return "", err
}
registryRes := struct {
registryResT1 := struct {
SchemaVersion int
MediaType string
Manifests []struct {
@ -130,17 +130,39 @@ func GetTagDigest(image reference.Named) (string, error) {
}
}{}
if err := json.Unmarshal(body, &registryRes); err != nil {
registryResT2 := struct {
SchemaVersion int
MediaType string
Config struct {
MediaType string
Size int
Digest string
}
Layers []struct {
MediaType string
Size int
Digest string
}
}{}
if err := json.Unmarshal(body, &registryResT1); err != nil {
return "", err
}
var digest string
for _, manifest := range registryRes.Manifests {
for _, manifest := range registryResT1.Manifests {
if string(manifest.Platform.Architecture) == "amd64" {
digest = strings.Split(manifest.Digest, ":")[1][:7]
}
}
if digest == "" {
if err := json.Unmarshal(body, &registryResT2); err != nil {
return "", err
}
digest = strings.Split(registryResT2.Config.Digest, ":")[1][:7]
}
if digest == "" {
return "", fmt.Errorf("Unable to retrieve amd64 digest for '%s'", image)
}