mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-27 17:21:58 +01:00
subject: fix missing media type recognition for nydus (#19453)
Nydus images are compatible with both docker scheme v2 and OCI image spec v1 types of config media type: - application/vnd.oci.image.config.v1+json - application/vnd.docker.container.image.v1+json The patch fixes the media type recognition on the accessory type check. Signed-off-by: Yan Song <yansong.ys@antgroup.com> Co-authored-by: MinerYang <yminer@vmware.com>
This commit is contained in:
parent
d030ab216b
commit
13f4fca96e
@ -129,7 +129,7 @@ func Middleware() func(http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
accData.Type = model.TypeSubject
|
accData.Type = model.TypeSubject
|
||||||
switch mf.Config.MediaType {
|
switch mf.Config.MediaType {
|
||||||
case schema2.MediaTypeImageConfig:
|
case ocispec.MediaTypeImageConfig, schema2.MediaTypeImageConfig:
|
||||||
if isNydusImage(mf) {
|
if isNydusImage(mf) {
|
||||||
accData.Type = model.TypeNydusAccelerator
|
accData.Type = model.TypeNydusAccelerator
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/distribution/manifest/schema2"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
@ -253,11 +254,12 @@ func (suite *MiddlewareTestSuite) TestSubjectDup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *MiddlewareTestSuite) TestIsNydusImage() {
|
func (suite *MiddlewareTestSuite) TestIsNydusImage() {
|
||||||
mf := `{
|
makeManifest := func(configType string) string {
|
||||||
|
return fmt.Sprintf(`{
|
||||||
"schemaVersion": 2,
|
"schemaVersion": 2,
|
||||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
"config": {
|
"config": {
|
||||||
"mediaType": "application/vnd.docker.container.image.v1+json",
|
"mediaType": "%s",
|
||||||
"digest": "sha256:e314d79415361272a5ff6919ce70eb1d82ae55641ff60dcd8286b731cae2b5e7",
|
"digest": "sha256:e314d79415361272a5ff6919ce70eb1d82ae55641ff60dcd8286b731cae2b5e7",
|
||||||
"size": 3322
|
"size": 3322
|
||||||
},
|
},
|
||||||
@ -317,12 +319,16 @@ func (suite *MiddlewareTestSuite) TestIsNydusImage() {
|
|||||||
"digest": "sha256:f4d532d482a050a3bb02886be6d6deda9c22cf8df44b1465f04c8648ee573a70",
|
"digest": "sha256:f4d532d482a050a3bb02886be6d6deda9c22cf8df44b1465f04c8648ee573a70",
|
||||||
"size": 1363
|
"size": 1363
|
||||||
}
|
}
|
||||||
}`
|
}`, configType)
|
||||||
|
}
|
||||||
manifest := &ocispec.Manifest{}
|
manifest := &ocispec.Manifest{}
|
||||||
err := json.Unmarshal([]byte(mf), manifest)
|
err := json.Unmarshal([]byte(makeManifest(ocispec.MediaTypeImageConfig)), manifest)
|
||||||
suite.Nil(err)
|
suite.Nil(err)
|
||||||
suite.True(isNydusImage(manifest))
|
suite.True(isNydusImage(manifest))
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(makeManifest(schema2.MediaTypeImageConfig)), manifest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.True(isNydusImage(manifest))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMiddlewareTestSuite(t *testing.T) {
|
func TestMiddlewareTestSuite(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user