Skip to content

Commit df606ef

Browse files
committed
ocimem: better Referrers implementation
We support filtering by artifact type as mentioned in the TODO, but also we provide information on artifact type and annotations to the client, as specified in the spec. Also update to a new version of the conformance tests, which actually adds some testing of the Referrers API, thus potentially making our existing tests of that API redundant but we'll leave them there anyway as they're doing no harm for now. Fixes #39 Signed-off-by: Roger Peppe <[email protected]> Change-Id: I8a1ed01608cfbb40ebe3d890deea2fdc031c8027 Reviewed-on: https://review.gerrithub.io/c/cue-labs/oci/+/1218299 TryBot-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent d0efc28 commit df606ef

File tree

12 files changed

+139
-90
lines changed

12 files changed

+139
-90
lines changed

cmd/ocisrv/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ require (
2121
github.com/opencontainers/image-spec v1.1.1 // indirect
2222
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 // indirect
2323
golang.org/x/mod v0.21.0 // indirect
24-
golang.org/x/net v0.30.0 // indirect
25-
golang.org/x/sys v0.26.0 // indirect
26-
golang.org/x/text v0.19.0 // indirect
24+
golang.org/x/net v0.33.0 // indirect
25+
golang.org/x/sys v0.28.0 // indirect
26+
golang.org/x/text v0.21.0 // indirect
2727
golang.org/x/tools v0.26.0 // indirect
2828
gopkg.in/yaml.v3 v3.0.1 // indirect
2929
)

cmd/ocisrv/go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ github.com/rogpeppe/retry v0.1.0 h1:6km4oqeZcFrnhx+PCPg/YxV3fnTdROBNVlSl8Pe/ztU=
4242
github.com/rogpeppe/retry v0.1.0/go.mod h1:/PtRtl9qXn+Pv5S4wN+Y5nusihQeI1PJ9U7KDcKzuvI=
4343
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
4444
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
45-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
46-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
47-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
48-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
49-
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
50-
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
51-
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
52-
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
45+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
46+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
47+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
48+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
49+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
50+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
51+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
52+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
5353
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
5454
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
5555
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

go.work.sum

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
4949
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
5050
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
5151
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
52+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
5253
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
5354
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
5455
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -74,25 +75,27 @@ golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45
7475
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
7576
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
7677
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
78+
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
79+
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
7780
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
7881
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
7982
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
83+
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
8084
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
81-
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
8285
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
8386
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
8487
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8588
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
8689
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
8790
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
88-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
8991
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9092
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9193
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9294
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9395
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9496
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
95-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
97+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
98+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
9699
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
97100
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
98101
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -104,20 +107,23 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
104107
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
105108
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
106109
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
110+
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
107111
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
108112
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
109113
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
110114
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
111115
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
116+
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
117+
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
112118
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
113119
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
114120
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
115-
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
116121
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
117122
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
118123
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
119124
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
120125
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
126+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
121127
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
122128
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
123129
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=

ociregistry/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ require (
1313
github.com/google/go-cmp v0.6.0 // indirect
1414
github.com/kr/pretty v0.3.1 // indirect
1515
github.com/kr/text v0.2.0 // indirect
16-
golang.org/x/sys v0.26.0 // indirect
16+
golang.org/x/sys v0.28.0 // indirect
1717
golang.org/x/tools v0.26.0 // indirect
1818
)

ociregistry/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
1515
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
1616
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
1717
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
18-
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
19-
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
18+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
19+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2020
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
2121
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=

ociregistry/internal/conformance/conformance_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,30 @@ func testReferrers(t *testing.T, client *remote.Registry) {
319319
Config: withMediaType(configDesc, "artifact1"),
320320
Layers: []ociregistry.Descriptor{layer0Desc},
321321
})
322+
annotations0 := map[string]string{
323+
"foo": "bar",
324+
"baz": "khroomph",
325+
}
322326
referrer0 := pushJSON(t, repo.Manifests(), ocispec.MediaTypeImageManifest, ociregistry.Manifest{
323-
MediaType: ocispec.MediaTypeImageManifest,
324-
Config: withMediaType(configDesc, "referrer0"),
325-
Subject: &manifestDesc,
327+
MediaType: ocispec.MediaTypeImageManifest,
328+
Config: withMediaType(configDesc, "referrer0"),
329+
Subject: &manifestDesc,
330+
Annotations: annotations0,
326331
})
332+
referrer0.ArtifactType = "referrer0"
333+
referrer0.Annotations = annotations0
327334
referrer1 := pushJSON(t, repo.Manifests(), ocispec.MediaTypeImageManifest, ociregistry.Manifest{
328335
MediaType: ocispec.MediaTypeImageManifest,
329336
Config: withMediaType(configDesc, "referrer1"),
330337
Subject: &manifestDesc,
331338
})
339+
referrer1.ArtifactType = "referrer1"
332340
referrer2 := pushJSON(t, repo.Manifests(), ocispec.MediaTypeImageManifest, ociregistry.Manifest{
333341
MediaType: ocispec.MediaTypeImageManifest,
334342
Config: withMediaType(configDesc, "referrer2"),
335343
Subject: &referrer1,
336344
})
345+
referrer2.ArtifactType = "referrer2"
337346
var gotReferrers []ocispec.Descriptor
338347
err = repo.Referrers(ctx, manifestDesc, "", func(referrers []ocispec.Descriptor) error {
339348
gotReferrers = append(gotReferrers, referrers...)

ociregistry/internal/conformance/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ replace cuelabs.dev/go/oci/ociregistry => ../..
1414
require (
1515
cuelabs.dev/go/oci/ociregistry v0.0.0-00010101000000-000000000000
1616
github.com/go-quicktest/qt v1.101.0
17-
github.com/opencontainers/distribution-spec/conformance v0.0.0-20231101194043-f2182352d4cc
17+
github.com/opencontainers/distribution-spec/conformance v0.0.0-20250220192232-583e014d1541
1818
github.com/opencontainers/go-digest v1.0.0
1919
github.com/opencontainers/image-spec v1.1.1
2020
oras.land/oras-go/v2 v2.5.0
@@ -35,8 +35,8 @@ require (
3535
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
3636
github.com/rogpeppe/go-internal v1.14.1 // indirect
3737
github.com/stretchr/testify v1.7.0 // indirect
38-
golang.org/x/net v0.30.0 // indirect
39-
golang.org/x/sync v0.8.0 // indirect
40-
golang.org/x/sys v0.26.0 // indirect
38+
golang.org/x/net v0.33.0 // indirect
39+
golang.org/x/sync v0.10.0 // indirect
40+
golang.org/x/sys v0.28.0 // indirect
4141
golang.org/x/tools v0.26.0 // indirect
4242
)

ociregistry/internal/conformance/go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU
3232
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
3333
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
3434
github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ=
35-
github.com/opencontainers/distribution-spec/conformance v0.0.0-20231101194043-f2182352d4cc h1:jL+CgYEEZluGb08ZcLpEyhn389kNMlwrWOHaIqXazq0=
36-
github.com/opencontainers/distribution-spec/conformance v0.0.0-20231101194043-f2182352d4cc/go.mod h1:odnkI+gfnNSdq8NaG/nKvENDEWkXAjjbgp8GKMllVSI=
35+
github.com/opencontainers/distribution-spec/conformance v0.0.0-20250220192232-583e014d1541 h1:hR3QfebIYiUVKERH00V10eKn2s6mOiE4FvX9ZpEkjp0=
36+
github.com/opencontainers/distribution-spec/conformance v0.0.0-20250220192232-583e014d1541/go.mod h1:DOO4RzIigGVoAksLURsDbKHpJ8zX5eEQfsmkqY39yyE=
3737
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
3838
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
3939
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
@@ -49,18 +49,18 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
4949
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
5050
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5151
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
52-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
53-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
54-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
55-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
52+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
53+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
54+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
55+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
5656
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5757
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
58-
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
59-
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
58+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
59+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
6060
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
6161
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
62-
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
63-
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
62+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
63+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
6464
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6565
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
6666
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=

ociregistry/ocimem/desciter.go

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package ocimem
22

33
import (
4+
"cmp"
45
"encoding/json"
56
"fmt"
7+
"iter"
68

79
"cuelabs.dev/go/oci/ociregistry"
810
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -22,25 +24,37 @@ type descInfo struct {
2224
desc ociregistry.Descriptor
2325
}
2426

25-
type descIter func(yield func(descInfo) bool)
27+
type manifestInfo struct {
28+
// descriptors iterates over all direct references inside the manifest
29+
descriptors descIter
30+
// subject holds the subject (referred-to manifest) of the manifest
31+
subject ociregistry.Digest
32+
// artifactType holds the artifact type of the manifest
33+
artifactType string
34+
// annotations holds any annotations from the manifest.
35+
annotations map[string]string
36+
}
37+
38+
type descIter = iter.Seq[descInfo]
2639

2740
// TODO support other manifest types.
28-
var manifestIterators = map[string]func(data []byte) (descIter, error){
29-
ocispec.MediaTypeImageManifest: descIterForType(imageDescIter),
30-
ocispec.MediaTypeImageIndex: descIterForType(indexDescIter),
41+
var manifestInfoByMediaType = map[string]func(data []byte) (manifestInfo, error){
42+
ocispec.MediaTypeImageManifest: manifestInfoForType(imageInfo),
43+
ocispec.MediaTypeImageIndex: manifestInfoForType(indexInfo),
3144
}
3245

33-
// manifestReferences returns an iterator that iterates over all
34-
// direct references inside the given manifest described byx the
35-
// given descriptor that holds the given data.
36-
func manifestReferences(mediaType string, data []byte) (descIter, error) {
37-
dataIter := manifestIterators[mediaType]
38-
if dataIter == nil {
46+
// getManifestInfo returns information on the manifest
47+
// described by the given media type and data.
48+
func getManifestInfo(mediaType string, data []byte) (manifestInfo, error) {
49+
getInfo := manifestInfoByMediaType[mediaType]
50+
if getInfo == nil {
3951
// TODO provide a configuration option to disallow unknown manifest types.
4052
//return nil, fmt.Errorf("media type %q: %w", mediaType, errUnknownManifestMediaTypeForIteration)
41-
return func(func(descInfo) bool) {}, nil
53+
return manifestInfo{
54+
descriptors: func(func(descInfo) bool) {},
55+
}, nil
4256
}
43-
return dataIter(data)
57+
return getInfo(data)
4458
}
4559

4660
// repoTagIter returns an iterator that iterates through
@@ -59,18 +73,19 @@ func repoTagIter(r *repository) descIter {
5973
}
6074
}
6175

62-
func descIterForType[T any](newIter func(T) descIter) func(data []byte) (descIter, error) {
63-
return func(data []byte) (descIter, error) {
76+
func manifestInfoForType[T any](getInfo func(T) manifestInfo) func(data []byte) (manifestInfo, error) {
77+
return func(data []byte) (manifestInfo, error) {
6478
var x T
6579
if err := json.Unmarshal(data, &x); err != nil {
66-
return nil, fmt.Errorf("cannot unmarshal into %T: %v", &x, err)
80+
return manifestInfo{}, fmt.Errorf("cannot unmarshal into %T: %v", &x, err)
6781
}
68-
return newIter(x), nil
82+
return getInfo(x), nil
6983
}
7084
}
7185

72-
func imageDescIter(m ociregistry.Manifest) descIter {
73-
return func(yield func(descInfo) bool) {
86+
func imageInfo(m ociregistry.Manifest) manifestInfo {
87+
var info manifestInfo
88+
info.descriptors = func(yield func(descInfo) bool) {
7489
for i, layer := range m.Layers {
7590
if !yield(descInfo{
7691
name: fmt.Sprintf("layers[%d]", i),
@@ -97,10 +112,27 @@ func imageDescIter(m ociregistry.Manifest) descIter {
97112
}
98113
}
99114
}
115+
// From https://github.com/opencontainers/distribution-spec/blob/main/spec.md#listing-referrers
116+
//
117+
// The descriptors MUST include an artifactType field that is set to
118+
// the value of the artifactType in the image manifest or index, if
119+
// present. If the artifactType is empty or missing in the image
120+
// manifest, the value of artifactType MUST be set to the config
121+
// descriptor mediaType value. If the artifactType is empty or
122+
// missing in an index, the artifactType MUST be omitted. The
123+
// descriptors MUST include annotations from the image manifest or
124+
// index.
125+
info.artifactType = cmp.Or(m.ArtifactType, m.Config.MediaType)
126+
info.annotations = m.Annotations
127+
if m.Subject != nil {
128+
info.subject = m.Subject.Digest
129+
}
130+
return info
100131
}
101132

102-
func indexDescIter(m ocispec.Index) descIter {
103-
return func(yield func(descInfo) bool) {
133+
func indexInfo(m ocispec.Index) manifestInfo {
134+
var info manifestInfo
135+
info.descriptors = func(yield func(descInfo) bool) {
104136
for i, manifest := range m.Manifests {
105137
if !yield(descInfo{
106138
name: fmt.Sprintf("manifests[%d]", i),
@@ -120,4 +152,10 @@ func indexDescIter(m ocispec.Index) descIter {
120152
}
121153
}
122154
}
155+
info.artifactType = m.ArtifactType // Note: no config descriptor to fall back to.
156+
info.annotations = m.Annotations
157+
if m.Subject != nil {
158+
info.subject = m.Subject.Digest
159+
}
160+
return info
123161
}

ociregistry/ocimem/lister.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ func (r *Registry) Referrers(ctx context.Context, repoName string, digest ocireg
4747
}
4848
var referrers []ociregistry.Descriptor
4949
for _, b := range repo.manifests {
50-
if b.subject != digest {
50+
if b.info.subject != digest {
51+
continue
52+
}
53+
if artifactType != "" && b.info.artifactType != artifactType {
5154
continue
5255
}
53-
// TODO filter by artifact type
5456
referrers = append(referrers, b.descriptor())
5557
}
5658
slices.SortFunc(referrers, compareDescriptor)

0 commit comments

Comments
 (0)