1
0
mirror of synced 2026-05-03 02:03:31 +00:00

feat: adding support digest pinning for flux plugin install

Signed-off-by: iam-karan-suresh <karansuresh.info@gmail.com>
This commit is contained in:
iam-karan-suresh
2026-04-26 12:20:14 +05:30
parent 4e78a9d7e0
commit df3878d36a
5 changed files with 151 additions and 10 deletions

View File

@@ -165,3 +165,33 @@ func ResolvePlatform(pv *plugintypes.Version, goos, goarch string) (*plugintypes
return nil, fmt.Errorf("no binary for %s/%s", goos, goarch)
}
// DigestMatch holds the version and platform resolved from a digest lookup.
type DigestMatch struct {
Version *plugintypes.Version
Platform *plugintypes.Platform
}
// ResolveByDigest scans all versions and platforms for a checksum matching
// digest. The digest must be in "algorithm:hex" format (e.g.
// "sha256:06e0a38..."). Only platforms matching goos/goarch are considered.
// Returns the first match (versions are ordered newest-first in the manifest).
func ResolveByDigest(manifest *plugintypes.Manifest, digest, goos, goarch string) (*DigestMatch, error) {
if len(manifest.Versions) == 0 {
return nil, fmt.Errorf("plugin %q has no versions", manifest.Name)
}
for i := range manifest.Versions {
for j := range manifest.Versions[i].Platforms {
p := &manifest.Versions[i].Platforms[j]
if p.OS == goos && p.Arch == goarch && p.Checksum == digest {
return &DigestMatch{
Version: &manifest.Versions[i],
Platform: p,
}, nil
}
}
}
return nil, fmt.Errorf("digest %q not found for plugin %q on %s/%s", digest, manifest.Name, goos, goarch)
}