Skip to content

Commit 5efa642

Browse files
refactor(artifact): remove oci artifact support
- add header to referrers call to indicated applied artifact type filters Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
1 parent 5fcf01d commit 5efa642

54 files changed

Lines changed: 587 additions & 1586 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ ignore:
66
- "./cmd/zb/*.go"
77
- "./pkg/test/mocks/*.go"
88
- "./swagger/*.go"
9+
- "./pkg/test/test_http_server.go"

errors/errors.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ var (
6363
ErrManifestConflict = errors.New("manifest: multiple manifests found")
6464
ErrManifestMetaNotFound = errors.New("repodb: image metadata not found for given manifest reference")
6565
ErrManifestDataNotFound = errors.New("repodb: image data not found for given manifest digest")
66-
ErrArtifactDataNotFound = errors.New("repodb: artifact data not found for given digest")
6766
ErrIndexDataNotFount = errors.New("repodb: index data not found for given digest")
6867
ErrRepoMetaNotFound = errors.New("repodb: repo metadata not found for given repo name")
6968
ErrTagMetaNotFound = errors.New("repodb: tag metadata not found for given repo and tag names")

examples/config-dynamodb.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"cacheTablename": "ZotBlobTable",
2121
"repoMetaTablename": "ZotRepoMetadataTable",
2222
"manifestDataTablename": "ZotManifestDataTable",
23-
"artifactDataTablename": "ZotArtifactDataTable",
2423
"userDataTablename": "ZotUserDataTable",
2524
"versionTablename": "ZotVersion"
2625
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ require (
462462
)
463463

464464
replace (
465-
github.com/opencontainers/umoci => github.com/project-stacker/umoci v0.0.0-20230228184813-24efbd35e8ef
465+
github.com/opencontainers/image-spec => github.com/project-zot/image-spec v0.0.0-20230428141304-a263befc67ea
466466
// v0.3.1-0.20230104082527-d6f58551be3f is taken from github.com/moby/buildkit v0.11.0
467467
// spdx logic write on v0.3.0 and incompatible with v0.3.1-0.20230104082527-d6f58551be3f
468468
// see https://github.com/aquasecurity/trivy/commit/2033e05b6b563aa4bc46d6234b3657a54e71ee46

go.sum

Lines changed: 22 additions & 11 deletions
Large diffs are not rendered by default.

golangcilint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ linters-settings:
5252
gomoddirectives:
5353
replace-allow-list:
5454
- helm.sh/helm/v3
55-
- github.com/opencontainers/umoci
5655
- github.com/spdx/tools-golang
56+
- github.com/opencontainers/image-spec
5757
issues:
5858
exclude-rules:
5959
- path: pkg/extensions/search/schema.resolvers.go

pkg/api/controller_test.go

Lines changed: 5 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
"zotregistry.io/zot/pkg/log"
5252
"zotregistry.io/zot/pkg/meta/repodb/repodbfactory"
5353
"zotregistry.io/zot/pkg/storage"
54-
storageConstants "zotregistry.io/zot/pkg/storage/constants"
5554
"zotregistry.io/zot/pkg/storage/local"
5655
"zotregistry.io/zot/pkg/test"
5756
)
@@ -157,7 +156,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
157156
"cacheTablename": "BlobTable",
158157
"repoMetaTablename": "RepoMetadataTable",
159158
"manifestDataTablename": "ManifestDataTable",
160-
"artifactDataTablename": "ArtifactDataTable",
161159
"userDataTablename": "ZotUserDataTable",
162160
"versionTablename": "Version",
163161
}
@@ -173,7 +171,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
173171
"cacheTablename": "BlobTable",
174172
"repoMetaTablename": "RepoMetadataTable",
175173
"manifestDataTablename": "ManifestDataTable",
176-
"artifactDataTablename": "ArtifactDataTable",
177174
"userDataTablename": "ZotUserDataTable",
178175
"versionTablename": "Version",
179176
}
@@ -188,7 +185,6 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
188185
"cacheTablename": "BlobTable",
189186
"repoMetaTablename": "RepoMetadataTable",
190187
"manifestDataTablename": "ManifestDataTable",
191-
"artifactDataTablename": "ArtifactDataTable",
192188
"userDataTablename": "ZotUserDataTable",
193189
"versionTablename": "Version",
194190
}
@@ -222,7 +218,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
222218
"cachetablename": "BlobTable",
223219
"repometatablename": "RepoMetadataTable",
224220
"manifestdatatablename": "ManifestDataTable",
225-
"artifactDataTablename": "ArtifactDataTable",
226221
"userdatatablename": "UserDatatable",
227222
}
228223

@@ -236,7 +231,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
236231
"cachetablename": "",
237232
"repometatablename": "RepoMetadataTable",
238233
"manifestdatatablename": "ManifestDataTable",
239-
"artifactDataTablename": "ArtifactDataTable",
240234
"userDataTablename": "ZotUserDataTable",
241235
"versiontablename": 1,
242236
}
@@ -252,7 +246,6 @@ func TestCreateRepoDBDriver(t *testing.T) {
252246
"repometatablename": "RepoMetadataTable",
253247
"manifestdatatablename": "ManifestDataTable",
254248
"indexdatatablename": "IndexDataTable",
255-
"artifactdatatablename": "ArtifactDataTable",
256249
"userdatatablename": "ZotUserDataTable",
257250
"versiontablename": "1",
258251
}
@@ -4312,138 +4305,15 @@ func TestArtifactReferences(t *testing.T) {
43124305
So(err, ShouldBeNil)
43134306
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
43144307
So(resp.Header().Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
4315-
})
4316-
})
4317-
4318-
Convey("Validate Artifact Manifest Reference", func() {
4319-
resp, err := resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4320-
So(err, ShouldBeNil)
4321-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4322-
4323-
var referrers ispec.Index
4324-
err = json.Unmarshal(resp.Body(), &referrers)
4325-
So(err, ShouldBeNil)
4326-
So(referrers.Manifests, ShouldBeEmpty)
4327-
4328-
// now upload a reference
4329-
4330-
// upload image config blob
4331-
resp, err = resty.R().Post(baseURL + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName))
4332-
So(err, ShouldBeNil)
4333-
So(resp.StatusCode(), ShouldEqual, http.StatusAccepted)
4334-
loc := test.Location(baseURL, resp)
4335-
cblob, cdigest := test.GetEmptyImageConfig()
4336-
4337-
resp, err = resty.R().
4338-
SetContentLength(true).
4339-
SetHeader("Content-Length", fmt.Sprintf("%d", len(cblob))).
4340-
SetHeader("Content-Type", "application/octet-stream").
4341-
SetQueryParam("digest", cdigest.String()).
4342-
SetBody(cblob).
4343-
Put(loc)
4344-
So(err, ShouldBeNil)
4345-
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
4346-
4347-
// create a artifact
4348-
manifest := ispec.Artifact{
4349-
MediaType: ispec.MediaTypeArtifactManifest,
4350-
ArtifactType: artifactType,
4351-
Blobs: []ispec.Descriptor{
4352-
{
4353-
MediaType: "application/vnd.oci.image.layer.v1.tar",
4354-
Digest: digest,
4355-
Size: int64(len(content)),
4356-
},
4357-
},
4358-
Subject: &ispec.Descriptor{
4359-
MediaType: ispec.MediaTypeImageManifest,
4360-
Digest: digest,
4361-
Size: int64(len(content)),
4362-
},
4363-
Annotations: map[string]string{
4364-
"key": "val",
4365-
},
4366-
}
4367-
Convey("Using invalid content", func() {
4368-
content := []byte("invalid data")
4369-
So(err, ShouldBeNil)
4370-
mdigest := godigest.FromBytes(content)
4371-
So(mdigest, ShouldNotBeNil)
4372-
resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeArtifactManifest).
4373-
SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, mdigest.String()))
4374-
So(err, ShouldBeNil)
4375-
So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest)
4376-
4377-
// unknown repo will return status not found
4378-
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", "unknown", digest.String()))
4379-
So(err, ShouldBeNil)
4380-
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
4381-
4382-
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4383-
So(err, ShouldBeNil)
4384-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4308+
So(resp.Header().Get("OCI-Filters-Applied"), ShouldEqual, artifactType)
43854309

4386-
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType}).
4387-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4388-
So(err, ShouldBeNil)
4389-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4390-
})
4391-
Convey("Using valid content", func() {
4392-
content, err = json.Marshal(manifest)
4393-
So(err, ShouldBeNil)
4394-
mdigest := godigest.FromBytes(content)
4395-
So(mdigest, ShouldNotBeNil)
4396-
resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeArtifactManifest).
4397-
SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/%s", repoName, mdigest.String()))
4398-
So(err, ShouldBeNil)
4399-
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
4400-
4401-
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4402-
So(err, ShouldBeNil)
4403-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4404-
4405-
resp, err = resty.R().SetQueryParams(map[string]string{"artifact": "invalid"}).
4406-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4407-
So(err, ShouldBeNil)
4408-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4409-
4410-
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": "invalid"}).
4411-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4412-
So(err, ShouldBeNil)
4413-
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
4414-
4415-
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType}).
4416-
Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()))
4310+
resp, err = resty.R().SetQueryParams(map[string]string{"artifactType": artifactType +
4311+
",otherArtType"}).Get(baseURL + fmt.Sprintf("/v2/%s/referrers/%s", repoName,
4312+
digest.String()))
44174313
So(err, ShouldBeNil)
44184314
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
44194315
So(resp.Header().Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
4420-
4421-
var index ispec.Index
4422-
err = json.Unmarshal(resp.Body(), &index)
4423-
So(err, ShouldBeNil)
4424-
So(index.Manifests, ShouldNotBeEmpty)
4425-
So(index.Annotations[storageConstants.ReferrerFilterAnnotation], ShouldNotBeEmpty)
4426-
4427-
// filter by multiple artifactTypes
4428-
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet,
4429-
baseURL+fmt.Sprintf("/v2/%s/referrers/%s", repoName, digest.String()), nil)
4430-
So(err, ShouldBeNil)
4431-
values := url.Values{}
4432-
values.Add("artifactType", artifactType)
4433-
values.Add("artifactType", "foobar")
4434-
req.URL.RawQuery = values.Encode()
4435-
rsp, err := http.DefaultClient.Do(req)
4436-
So(err, ShouldBeNil)
4437-
defer rsp.Body.Close()
4438-
So(rsp.StatusCode, ShouldEqual, http.StatusOK)
4439-
So(rsp.Header.Get("Content-Type"), ShouldEqual, ispec.MediaTypeImageIndex)
4440-
body, err := io.ReadAll(rsp.Body)
4441-
So(err, ShouldBeNil)
4442-
err = json.Unmarshal(body, &index)
4443-
So(err, ShouldBeNil)
4444-
So(index.Manifests, ShouldNotBeEmpty)
4445-
So(index.Annotations[storageConstants.ReferrerFilterAnnotation], ShouldNotBeEmpty)
4446-
So(len(strings.Split(index.Annotations[storageConstants.ReferrerFilterAnnotation], ",")), ShouldEqual, 2)
4316+
So(resp.Header().Get("OCI-Filters-Applied"), ShouldEqual, artifactType+",otherArtType")
44474317
})
44484318
})
44494319
})

pkg/api/routes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func (rh *RouteHandler) GetManifest(response http.ResponseWriter, request *http.
408408
}
409409

410410
if rh.c.RepoDB != nil {
411-
err := meta.OnGetManifest(name, reference, digest, content, rh.c.StoreController, rh.c.RepoDB, rh.c.Log)
411+
err := meta.OnGetManifest(name, reference, content, rh.c.StoreController, rh.c.RepoDB, rh.c.Log)
412412

413413
if errors.Is(err, zerr.ErrOrphanSignature) {
414414
rh.c.Log.Error().Err(err).Msg("image is an orphan signature")
@@ -514,6 +514,7 @@ func (rh *RouteHandler) GetReferrers(response http.ResponseWriter, request *http
514514
return
515515
}
516516

517+
response.Header().Set("OCI-Filters-Applied", strings.Join(artifactTypes, ","))
517518
WriteData(response, http.StatusOK, ispec.MediaTypeImageIndex, out)
518519
}
519520

pkg/cli/client.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,8 @@ func isNotationSigned(ctx context.Context, repo, digestStr string, searchConf se
490490
return false
491491
}
492492

493-
for _, reference := range referrers.Manifests {
494-
if reference.ArtifactType == notreg.ArtifactTypeNotation {
495-
return true
496-
}
493+
if len(referrers.Manifests) > 0 {
494+
return true
497495
}
498496

499497
return false

0 commit comments

Comments
 (0)