getPlatformDigest resolves a manifest list to a specific platform's digest This uses the above cache to only call ManifestGet when a new manifest list digest is seen
(ctx context.Context, r ref.Ref, platStr string, origMan manifest.Manifest)
| 1047 | // getPlatformDigest resolves a manifest list to a specific platform's digest |
| 1048 | // This uses the above cache to only call ManifestGet when a new manifest list digest is seen |
| 1049 | func (opts *rootOpts) getPlatformDigest(ctx context.Context, r ref.Ref, platStr string, origMan manifest.Manifest) (digest.Digest, error) { |
| 1050 | plat, err := platform.Parse(platStr) |
| 1051 | if err != nil { |
| 1052 | opts.log.Warn("Could not parse platform", |
| 1053 | slog.String("platform", platStr), |
| 1054 | slog.String("err", err.Error())) |
| 1055 | return "", err |
| 1056 | } |
| 1057 | // cache manifestGet response |
| 1058 | manifestCache.mu.Lock() |
| 1059 | getMan, ok := manifestCache.manifests[manifest.GetDigest(origMan).String()] |
| 1060 | if !ok { |
| 1061 | getMan, err = opts.rc.ManifestGet(ctx, r) |
| 1062 | if err != nil { |
| 1063 | opts.log.Error("Failed to get source manifest", |
| 1064 | slog.String("source", r.CommonName()), |
| 1065 | slog.String("error", err.Error())) |
| 1066 | manifestCache.mu.Unlock() |
| 1067 | return "", err |
| 1068 | } |
| 1069 | manifestCache.manifests[manifest.GetDigest(origMan).String()] = getMan |
| 1070 | } |
| 1071 | manifestCache.mu.Unlock() |
| 1072 | descPlat, err := manifest.GetPlatformDesc(getMan, &plat) |
| 1073 | if err != nil { |
| 1074 | pl, _ := manifest.GetPlatformList(getMan) |
| 1075 | var ps []string |
| 1076 | for _, p := range pl { |
| 1077 | ps = append(ps, p.String()) |
| 1078 | } |
| 1079 | opts.log.Warn("Platform could not be found in source manifest list", |
| 1080 | slog.String("platform", plat.String()), |
| 1081 | slog.String("err", err.Error()), |
| 1082 | slog.String("platforms", strings.Join(ps, ", "))) |
| 1083 | return "", ErrNotFound |
| 1084 | } |
| 1085 | return descPlat.Digest, nil |
| 1086 | } |
no test coverage detected