distribution serves name-of: the reference it keeps an upstream copy under

The node-engine composes an upstream artifact's image from the holder's own
name for the copy; distribution owns that naming (ParseSource, Source.Name), so
it answers it on the image seat rather than another module repeating the rule.

Builds: design 47 H2 H-A-513 second addendum
This commit is contained in:
2026-11-23 02:02:10 +01:00
parent c9554e4b91
commit 69d2b0d278
6 changed files with 51 additions and 5 deletions
@@ -823,6 +823,18 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
if strings.ContainsAny(key, ":@") {
t.Errorf("the ask's key %q holds characters a key may not", key)
}
// name-of answers the same reference for a manifest's pinned from, asking no copy (H-A-513); a from with no digest,
// and the artifact seat, are refused.
for _, from := range []string{"nats:2.11.17-alpine@" + d, "docker.io/library/nats@" + d} {
if named, err := b.v.NameOf(ImageSeat, from); err != nil || named != want || len(asked) != 1 {
t.Errorf("name-of %s = %q, %v, asks %d: want %s and no copy asked", from, named, err, len(asked), want)
}
}
for seat, from := range map[string]string{ImageSeat: "nats:2.11.17-alpine", ArtifactSeat: "nats@" + d} {
if named, err := b.v.NameOf(seat, from); err == nil {
t.Errorf("name-of %s on %s = %q: want a refusal", from, seat, named)
}
}
if err := b.v.Mirrored(asked[key]); err != nil || len(b.said) != 1 || b.said[0].event != EventPublished ||
b.said[0].body.Reference != want || b.said[0].body.Kind != KindUpstream || len(asked) != 0 {
t.Fatalf("the copy's end = %v, said %+v, asks %v: want published with the reference and the ask gone", err, b.said, asked)
@@ -26,6 +26,7 @@ const (
VerbVersions = "versions"
VerbRemove = "remove"
VerbMirror = "mirror"
VerbNameOf = "name-of"
VerbTags = "tags"
VerbHold = "hold"
VerbRelease = "release"
@@ -34,11 +35,11 @@ const (
// Seats are the seats distribution answers verbs on.
var Seats = []string{ImageSeat, ArtifactSeat}
// VerbsOf are a seat's verbs: mirror and tags on the image seat alone; hold, release and list on both of distribution's.
// VerbsOf are a seat's verbs: mirror, name-of and tags on the image seat alone; hold, release and list on both of distribution's.
func VerbsOf(seat string) []string {
v := []string{VerbPublish, VerbPublishPart, VerbVersions, VerbRemove, VerbHold, VerbRelease, VerbList}
if seat == ImageSeat {
v = append(v, VerbMirror, VerbTags)
v = append(v, VerbMirror, VerbNameOf, VerbTags)
}
sort.Strings(v)
return v
@@ -333,6 +333,25 @@ func (v *Verbs) Mirror(seat, caller string, r MirrorRequest) (string, error) {
return SeatReference(seat, v.Catalog.Reference(src.Name(), r.Digest)), nil
}
// NameOf is `name-of` on the image seat (design 47 H2 H-A-513): the reference mirror answers, and keeps the copy under, for an
// outside image as a manifest's from names it, pinned (<name>[:<tag>]@sha256:<digest>): the holder's own name for the copy,
// upstream/<host>/<path>, with that digest, in the seat's form. It reads only and asks no copy; a from that pins no digest is
// refused, as mirror refuses it.
func (v *Verbs) NameOf(seat, from string) (string, error) {
if seat != ImageSeat {
return "", fmt.Errorf("name-of: %s serves no name-of", seat)
}
_, digest, pinned := strings.Cut(strings.TrimSpace(from), "@")
if !pinned || !strings.HasPrefix(digest, "sha256:") || len(digest) != len("sha256:")+64 {
return "", fmt.Errorf("name-of: refused: %q pins no digest, and an upstream image is named only by its pinned digest", from)
}
src, err := ParseSource(from)
if err != nil {
return "", err
}
return SeatReference(seat, v.Catalog.Reference(src.Name(), digest)), nil
}
// Mirrored runs one asked copy and says its outcome on the image seat's events: published with the reference, or
// refused with the reason; the ask leaves the state either way. An outcome that cannot be said keeps the ask, so the
// next watch takes it on again.