mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
Move api constants in separate 'constants' package to avoid circular imports
Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
parent
f53dc9eb8d
commit
353b0c6034
6 changed files with 66 additions and 56 deletions
11
pkg/api/constants/consts.go
Normal file
11
pkg/api/constants/consts.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package constants
|
||||
|
||||
const (
|
||||
ArtifactSpecRoutePrefix = "/oras/artifacts/v1"
|
||||
RoutePrefix = "/v2"
|
||||
DistAPIVersion = "Docker-Distribution-API-Version"
|
||||
DistContentDigestKey = "Docker-Content-Digest"
|
||||
BlobUploadUUID = "Blob-Upload-UUID"
|
||||
DefaultMediaType = "application/json"
|
||||
BinaryMediaType = "application/octet-stream"
|
||||
)
|
|
@ -44,6 +44,7 @@ import (
|
|||
"zotregistry.io/zot/errors"
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/api/constants"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
@ -128,6 +129,7 @@ func TestRunAlreadyRunningServer(t *testing.T) {
|
|||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
_ = ctlr.Server.Shutdown(ctx)
|
||||
|
@ -3045,7 +3047,7 @@ func TestImageSignatures(t *testing.T) {
|
|||
blobLoc := resp.Header().Get("Location")
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// upload image config blob
|
||||
resp, err = resty.R().Post(baseURL + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName))
|
||||
|
@ -3088,7 +3090,7 @@ func TestImageSignatures(t *testing.T) {
|
|||
SetBody(content).Put(baseURL + fmt.Sprintf("/v2/%s/manifests/1.0", repoName))
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
d := resp.Header().Get(api.DistContentDigestKey)
|
||||
d := resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(d, ShouldNotBeEmpty)
|
||||
So(d, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -3949,7 +3951,7 @@ func TestStorageCommit(t *testing.T) {
|
|||
blobLoc := resp.Header().Get("Location")
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// check a non-existent manifest
|
||||
resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
|
||||
|
@ -3998,7 +4000,7 @@ func TestStorageCommit(t *testing.T) {
|
|||
SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:1.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr := resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr := resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -4006,7 +4008,7 @@ func TestStorageCommit(t *testing.T) {
|
|||
SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:1.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr = resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr = resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -4055,7 +4057,7 @@ func TestStorageCommit(t *testing.T) {
|
|||
SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:2.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr = resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr = resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
zerr "zotregistry.io/zot/errors"
|
||||
"zotregistry.io/zot/pkg/api/constants"
|
||||
ext "zotregistry.io/zot/pkg/extensions"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
|
@ -37,15 +38,6 @@ import (
|
|||
_ "zotregistry.io/zot/swagger"
|
||||
)
|
||||
|
||||
const (
|
||||
RoutePrefix = "/v2"
|
||||
DistAPIVersion = "Docker-Distribution-API-Version"
|
||||
DistContentDigestKey = "Docker-Content-Digest"
|
||||
BlobUploadUUID = "Blob-Upload-UUID"
|
||||
DefaultMediaType = "application/json"
|
||||
BinaryMediaType = "application/octet-stream"
|
||||
)
|
||||
|
||||
type RouteHandler struct {
|
||||
c *Controller
|
||||
}
|
||||
|
@ -69,7 +61,7 @@ func (rh *RouteHandler) SetupRoutes() {
|
|||
rh.c.Router.Use(AuthzHandler(rh.c))
|
||||
}
|
||||
|
||||
prefixedRouter := rh.c.Router.PathPrefix(RoutePrefix).Subrouter()
|
||||
prefixedRouter := rh.c.Router.PathPrefix(constants.RoutePrefix).Subrouter()
|
||||
{
|
||||
prefixedRouter.HandleFunc(fmt.Sprintf("/{name:%s}/tags/list", NameRegexp.String()),
|
||||
rh.ListTags).Methods(allowedMethods("GET")...)
|
||||
|
@ -104,8 +96,8 @@ func (rh *RouteHandler) SetupRoutes() {
|
|||
}
|
||||
|
||||
// support for oras artifact reference types (alpha 1) - image signature use case
|
||||
rh.c.Router.HandleFunc(fmt.Sprintf("/oras/artifacts/v1/{name:%s}/manifests/{digest}/referrers", NameRegexp.String()),
|
||||
rh.GetReferrers).Methods("GET")
|
||||
rh.c.Router.HandleFunc(fmt.Sprintf("%s/{name:%s}/manifests/{digest}/referrers",
|
||||
constants.ArtifactSpecRoutePrefix, NameRegexp.String()), rh.GetReferrers).Methods("GET")
|
||||
|
||||
// swagger swagger "/swagger/v2/index.html"
|
||||
rh.c.Router.PathPrefix("/swagger/v2/").Methods("GET").Handler(httpSwagger.WrapHandler)
|
||||
|
@ -131,7 +123,7 @@ func (rh *RouteHandler) SetupRoutes() {
|
|||
// @Produce json
|
||||
// @Success 200 {string} string "ok".
|
||||
func (rh *RouteHandler) CheckVersionSupport(response http.ResponseWriter, request *http.Request) {
|
||||
response.Header().Set(DistAPIVersion, "registry/2.0")
|
||||
response.Header().Set(constants.DistAPIVersion, "registry/2.0")
|
||||
// NOTE: compatibility workaround - return this header in "allowed-read" mode to allow for clients to
|
||||
// work correctly
|
||||
if rh.c.Config.HTTP.AllowReadAccess {
|
||||
|
@ -284,7 +276,7 @@ func (rh *RouteHandler) ListTags(response http.ResponseWriter, request *http.Req
|
|||
// @Param name path string true "repository name"
|
||||
// @Param reference path string true "image reference or digest"
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Header 200 {object} api.DistContentDigestKey
|
||||
// @Header 200 {object} cosntants.DistContentDigestKey
|
||||
// @Failure 404 {string} string "not found"
|
||||
// @Failure 500 {string} string "internal server error".
|
||||
func (rh *RouteHandler) CheckManifest(response http.ResponseWriter, request *http.Request) {
|
||||
|
@ -325,7 +317,7 @@ func (rh *RouteHandler) CheckManifest(response http.ResponseWriter, request *htt
|
|||
return
|
||||
}
|
||||
|
||||
response.Header().Set(DistContentDigestKey, digest)
|
||||
response.Header().Set(constants.DistContentDigestKey, digest)
|
||||
response.Header().Set("Content-Length", fmt.Sprintf("%d", len(content)))
|
||||
response.Header().Set("Content-Type", mediaType)
|
||||
response.WriteHeader(http.StatusOK)
|
||||
|
@ -344,7 +336,7 @@ type ImageManifest struct {
|
|||
// @Param name path string true "repository name"
|
||||
// @Param reference path string true "image reference or digest"
|
||||
// @Success 200 {object} api.ImageManifest
|
||||
// @Header 200 {object} api.DistContentDigestKey
|
||||
// @Header 200 {object} constants.DistContentDigestKey
|
||||
// @Failure 404 {string} string "not found"
|
||||
// @Failure 500 {string} string "internal server error"
|
||||
// @Router /v2/{name}/manifests/{reference} [get].
|
||||
|
@ -388,7 +380,7 @@ func (rh *RouteHandler) GetManifest(response http.ResponseWriter, request *http.
|
|||
return
|
||||
}
|
||||
|
||||
response.Header().Set(DistContentDigestKey, digest)
|
||||
response.Header().Set(constants.DistContentDigestKey, digest)
|
||||
WriteData(response, http.StatusOK, mediaType, content)
|
||||
}
|
||||
|
||||
|
@ -399,7 +391,7 @@ func (rh *RouteHandler) GetManifest(response http.ResponseWriter, request *http.
|
|||
// @Produce json
|
||||
// @Param name path string true "repository name"
|
||||
// @Param reference path string true "image reference or digest"
|
||||
// @Header 201 {object} api.DistContentDigestKey
|
||||
// @Header 201 {object} constants.DistContentDigestKey
|
||||
// @Success 201 {string} string "created"
|
||||
// @Failure 400 {string} string "bad request"
|
||||
// @Failure 404 {string} string "not found"
|
||||
|
@ -464,7 +456,7 @@ func (rh *RouteHandler) UpdateManifest(response http.ResponseWriter, request *ht
|
|||
}
|
||||
|
||||
response.Header().Set("Location", fmt.Sprintf("/v2/%s/manifests/%s", name, digest))
|
||||
response.Header().Set(DistContentDigestKey, digest)
|
||||
response.Header().Set(constants.DistContentDigestKey, digest)
|
||||
response.WriteHeader(http.StatusCreated)
|
||||
}
|
||||
|
||||
|
@ -526,7 +518,7 @@ func (rh *RouteHandler) DeleteManifest(response http.ResponseWriter, request *ht
|
|||
// @Param name path string true "repository name"
|
||||
// @Param digest path string true "blob/layer digest"
|
||||
// @Success 200 {object} api.ImageManifest
|
||||
// @Header 200 {object} api.DistContentDigestKey
|
||||
// @Header 200 {object} constants.DistContentDigestKey
|
||||
// @Router /v2/{name}/blobs/{digest} [head].
|
||||
func (rh *RouteHandler) CheckBlob(response http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
|
@ -572,7 +564,7 @@ func (rh *RouteHandler) CheckBlob(response http.ResponseWriter, request *http.Re
|
|||
}
|
||||
|
||||
response.Header().Set("Content-Length", fmt.Sprintf("%d", blen))
|
||||
response.Header().Set(DistContentDigestKey, digest)
|
||||
response.Header().Set(constants.DistContentDigestKey, digest)
|
||||
response.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
@ -583,7 +575,7 @@ func (rh *RouteHandler) CheckBlob(response http.ResponseWriter, request *http.Re
|
|||
// @Produce application/vnd.oci.image.layer.v1.tar+gzip
|
||||
// @Param name path string true "repository name"
|
||||
// @Param digest path string true "blob/layer digest"
|
||||
// @Header 200 {object} api.DistContentDigestKey
|
||||
// @Header 200 {object} constants.DistContentDigestKey
|
||||
// @Success 200 {object} api.ImageManifest
|
||||
// @Router /v2/{name}/blobs/{digest} [get].
|
||||
func (rh *RouteHandler) GetBlob(response http.ResponseWriter, request *http.Request) {
|
||||
|
@ -630,7 +622,7 @@ func (rh *RouteHandler) GetBlob(response http.ResponseWriter, request *http.Requ
|
|||
}
|
||||
|
||||
response.Header().Set("Content-Length", fmt.Sprintf("%d", blen))
|
||||
response.Header().Set(DistContentDigestKey, digest)
|
||||
response.Header().Set(constants.DistContentDigestKey, digest)
|
||||
// return the blob data
|
||||
WriteDataFromReader(response, http.StatusOK, blen, mediaType, repo, rh.c.Log)
|
||||
}
|
||||
|
@ -767,8 +759,8 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
|
|||
|
||||
digest := digests[0]
|
||||
|
||||
if contentType := request.Header.Get("Content-Type"); contentType != BinaryMediaType {
|
||||
rh.c.Log.Warn().Str("actual", contentType).Str("expected", BinaryMediaType).Msg("invalid media type")
|
||||
if contentType := request.Header.Get("Content-Type"); contentType != constants.BinaryMediaType {
|
||||
rh.c.Log.Warn().Str("actual", contentType).Str("expected", constants.BinaryMediaType).Msg("invalid media type")
|
||||
response.WriteHeader(http.StatusUnsupportedMediaType)
|
||||
|
||||
return
|
||||
|
@ -805,7 +797,7 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
|
|||
}
|
||||
|
||||
response.Header().Set("Location", fmt.Sprintf("/v2/%s/blobs/%s", name, digest))
|
||||
response.Header().Set(BlobUploadUUID, sessionID)
|
||||
response.Header().Set(constants.BlobUploadUUID, sessionID)
|
||||
response.WriteHeader(http.StatusCreated)
|
||||
|
||||
return
|
||||
|
@ -988,7 +980,7 @@ func (rh *RouteHandler) PatchBlobUpload(response http.ResponseWriter, request *h
|
|||
response.Header().Set("Location", request.URL.String())
|
||||
response.Header().Set("Range", fmt.Sprintf("bytes=0-%d", clen-1))
|
||||
response.Header().Set("Content-Length", "0")
|
||||
response.Header().Set(BlobUploadUUID, sessionID)
|
||||
response.Header().Set(constants.BlobUploadUUID, sessionID)
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
|
@ -1002,7 +994,7 @@ func (rh *RouteHandler) PatchBlobUpload(response http.ResponseWriter, request *h
|
|||
// @Param digest query string true "blob/layer digest"
|
||||
// @Success 201 {string} string "created"
|
||||
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{digest}"
|
||||
// @Header 200 {object} api.DistContentDigestKey
|
||||
// @Header 200 {object} constants.DistContentDigestKey
|
||||
// @Failure 404 {string} string "not found"
|
||||
// @Failure 500 {string} string "internal server error"
|
||||
// @Router /v2/{name}/blobs/uploads/{session_id} [put].
|
||||
|
@ -1128,7 +1120,7 @@ finish:
|
|||
|
||||
response.Header().Set("Location", fmt.Sprintf("/v2/%s/blobs/%s", name, digest))
|
||||
response.Header().Set("Content-Length", "0")
|
||||
response.Header().Set(DistContentDigestKey, digest)
|
||||
response.Header().Set(constants.DistContentDigestKey, digest)
|
||||
response.WriteHeader(http.StatusCreated)
|
||||
}
|
||||
|
||||
|
@ -1280,7 +1272,7 @@ func WriteJSON(response http.ResponseWriter, status int, data interface{}) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
WriteData(response, status, DefaultMediaType, body)
|
||||
WriteData(response, status, constants.DefaultMediaType, body)
|
||||
}
|
||||
|
||||
func WriteData(w http.ResponseWriter, status int, mediaType string, data []byte) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/smartystreets/goconvey/convey/reporting"
|
||||
"gopkg.in/resty.v1"
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/constants"
|
||||
"zotregistry.io/zot/pkg/compliance"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
@ -59,7 +60,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
So(resp.String(), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Type"), ShouldEqual, api.DefaultMediaType)
|
||||
So(resp.Header().Get("Content-Type"), ShouldEqual, constants.DefaultMediaType)
|
||||
var repoList api.RepositoryList
|
||||
err = json.Unmarshal(resp.Body(), &repoList)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -155,7 +156,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
blobLoc := test.Location(baseURL, resp)
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
// upload reference should now be removed
|
||||
resp, err = resty.R().Get(loc)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -248,7 +249,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
blobLoc := test.Location(baseURL, resp)
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
// upload reference should now be removed
|
||||
resp, err = resty.R().Get(loc)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -316,7 +317,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
// upload reference should now be removed
|
||||
resp, err = resty.R().Get(loc)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -384,7 +385,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
// upload reference should now be removed
|
||||
resp, err = resty.R().Get(loc)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -429,7 +430,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
blobLoc := test.Location(baseURL, resp)
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// delete this blob
|
||||
resp, err = resty.R().Delete(blobLoc)
|
||||
|
@ -474,7 +475,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
blobLoc := resp.Header().Get("Location")
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// check a non-existent manifest
|
||||
resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
|
||||
|
@ -523,7 +524,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:1.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr := resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr := resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -531,7 +532,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:1.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr = resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr = resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -563,7 +564,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + "/v2/repo7/manifests/test:2.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr = resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr = resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -654,7 +655,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
blobLoc := resp.Header().Get("Location")
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// upload image config blob
|
||||
resp, err = resty.R().Post(baseURL + "/v2/page0/blobs/uploads/")
|
||||
|
@ -697,7 +698,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + fmt.Sprintf("/v2/page0/manifests/test:%d.0", index))
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
d := resp.Header().Get(api.DistContentDigestKey)
|
||||
d := resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(d, ShouldNotBeEmpty)
|
||||
So(d, ShouldEqual, digest.String())
|
||||
}
|
||||
|
@ -796,7 +797,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
firstblobLoc := resp.Header().Get("Location")
|
||||
So(firstblobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// second test
|
||||
resp, err = resty.R().SetQueryParam("digest", digest.String()).
|
||||
|
@ -806,7 +807,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
secondblobLoc := resp.Header().Get("Location")
|
||||
So(secondblobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// check a non-existent manifest
|
||||
resp, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
|
||||
|
@ -882,7 +883,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + "/v2/firsttest/first/manifests/test:1.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr := resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr := resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -891,7 +892,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + "/v2/secondtest/second/manifests/test:1.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr = resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr = resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -925,7 +926,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + "/v2/firsttest/first/manifests/test:2.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr = resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr = resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
@ -934,7 +935,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
|
|||
SetBody(content).Put(baseURL + "/v2/secondtest/second/manifests/test:2.0")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
digestHdr = resp.Header().Get(api.DistContentDigestKey)
|
||||
digestHdr = resp.Header().Get(constants.DistContentDigestKey)
|
||||
So(digestHdr, ShouldNotBeEmpty)
|
||||
So(digestHdr, ShouldEqual, digest.String())
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/sigstore/cosign/pkg/cosign"
|
||||
"gopkg.in/resty.v1"
|
||||
zerr "zotregistry.io/zot/errors"
|
||||
"zotregistry.io/zot/pkg/api/constants"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
)
|
||||
|
@ -67,7 +68,9 @@ func getNotaryRefs(client *resty.Client, regURL url.URL, repo, digest string, lo
|
|||
getReferrersURL := regURL
|
||||
|
||||
// based on manifest digest get referrers
|
||||
getReferrersURL.Path = path.Join(getReferrersURL.Path, "oras/artifacts/v1/", repo, "manifests", digest, "referrers")
|
||||
getReferrersURL.Path = path.Join(getReferrersURL.Path, constants.ArtifactSpecRoutePrefix,
|
||||
repo, "manifests", digest, "referrers")
|
||||
|
||||
getReferrersURL.RawQuery = getReferrersURL.Query().Encode()
|
||||
|
||||
resp, err := client.R().
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"gopkg.in/resty.v1"
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/api/constants"
|
||||
. "zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
||||
|
@ -181,7 +182,7 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
blobLoc := Location(baseURL, resp)
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
// wait until the file is populated
|
||||
byteValue, _ = ioutil.ReadAll(auditFile)
|
||||
|
|
Loading…
Reference in a new issue