From fcd29ac50f102a5a4c7985929980d2fbfb4b398e Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Thu, 9 Feb 2017 10:47:58 +0800 Subject: [PATCH 1/3] Add 'ImageLayoutFile' const Signed-off-by: Lei Jitang --- specs-go/v1/layout.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/specs-go/v1/layout.go b/specs-go/v1/layout.go index c1c7a7870..fc79e9e0d 100644 --- a/specs-go/v1/layout.go +++ b/specs-go/v1/layout.go @@ -14,8 +14,12 @@ package v1 -// ImageLayoutVersion is the version of ImageLayout -const ImageLayoutVersion = "1.0.0" +const ( + // ImageLayoutFile is the file name of oci image layout file + ImageLayoutFile = "oci-layout" + // ImageLayoutVersion is the version of ImageLayout + ImageLayoutVersion = "1.0.0" +) // ImageLayout is the structure in the "oci-layout" file, found in the root // of an OCI Image-layout directory. From 2aed29aea9a31afae314fe6b6e7f686866ad4203 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Thu, 9 Feb 2017 10:51:33 +0800 Subject: [PATCH 2/3] Add image layout validator Add image layout validator so the image tool or other tools can use the image-spec to validate the oci image. Signed-off-by: Lei Jitang --- schema/schema.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/schema/schema.go b/schema/schema.go index 1ca6312c4..5e23ef51c 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -26,6 +26,7 @@ const ( MediaTypeManifest Validator = v1.MediaTypeImageManifest MediaTypeManifestList Validator = v1.MediaTypeImageManifestList MediaTypeImageConfig Validator = v1.MediaTypeImageConfig + TypeImageLayout Validator = v1.ImageLayoutFile MediaTypeImageLayer unimplemented = v1.MediaTypeImageLayer ) @@ -40,6 +41,7 @@ var ( MediaTypeManifest: "image-manifest-schema.json", MediaTypeManifestList: "manifest-list-schema.json", MediaTypeImageConfig: "config-schema.json", + TypeImageLayout: "image-layout-schema.json", } ) From 88d41e8d66b7cbdcd7c589a99c287359cc1f5e4f Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Thu, 9 Feb 2017 10:59:28 +0800 Subject: [PATCH 3/3] Let media type validator start with validator Signed-off-by: Lei Jitang --- schema/config_test.go | 2 +- schema/descriptor_test.go | 2 +- .../manifest_backwards_compatibility_test.go | 6 ++--- schema/manifest_test.go | 2 +- schema/manifestlist_test.go | 2 +- schema/schema.go | 22 +++++++++---------- schema/validator.go | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/schema/config_test.go b/schema/config_test.go index 69ae067c0..f31d14117 100644 --- a/schema/config_test.go +++ b/schema/config_test.go @@ -211,7 +211,7 @@ func TestConfig(t *testing.T) { }, } { r := strings.NewReader(tt.config) - err := schema.MediaTypeImageConfig.Validate(r) + err := schema.ValidatorMediaTypeImageConfig.Validate(r) if got := err != nil; tt.fail != got { t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) diff --git a/schema/descriptor_test.go b/schema/descriptor_test.go index 6921f0854..1fe925782 100644 --- a/schema/descriptor_test.go +++ b/schema/descriptor_test.go @@ -204,7 +204,7 @@ func TestDescriptor(t *testing.T) { }, } { r := strings.NewReader(tt.descriptor) - err := schema.MediaTypeDescriptor.Validate(r) + err := schema.ValidatorMediaTypeDescriptor.Validate(r) if got := err != nil; tt.fail != got { t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) diff --git a/schema/manifest_backwards_compatibility_test.go b/schema/manifest_backwards_compatibility_test.go index aa105ec4e..dcae68252 100644 --- a/schema/manifest_backwards_compatibility_test.go +++ b/schema/manifest_backwards_compatibility_test.go @@ -116,7 +116,7 @@ func TestBackwardsCompatibilityManifestList(t *testing.T) { manifestlist := convertFormats(tt.manifestlist) r := strings.NewReader(manifestlist) - err := schema.MediaTypeManifestList.Validate(r) + err := schema.ValidatorMediaTypeManifestList.Validate(r) if got := err != nil; tt.fail != got { t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) @@ -178,7 +178,7 @@ func TestBackwardsCompatibilityManifest(t *testing.T) { manifest := convertFormats(tt.manifest) r := strings.NewReader(manifest) - err := schema.MediaTypeManifest.Validate(r) + err := schema.ValidatorMediaTypeManifest.Validate(r) if got := err != nil; tt.fail != got { t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) @@ -217,7 +217,7 @@ func TestBackwardsCompatibilityConfig(t *testing.T) { config := convertFormats(tt.config) r := strings.NewReader(config) - err := schema.MediaTypeImageConfig.Validate(r) + err := schema.ValidatorMediaTypeImageConfig.Validate(r) if got := err != nil; tt.fail != got { t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) diff --git a/schema/manifest_test.go b/schema/manifest_test.go index 42a886aaf..2a6a53529 100644 --- a/schema/manifest_test.go +++ b/schema/manifest_test.go @@ -193,7 +193,7 @@ func TestManifest(t *testing.T) { }, } { r := strings.NewReader(tt.manifest) - err := schema.MediaTypeManifest.Validate(r) + err := schema.ValidatorMediaTypeManifest.Validate(r) if got := err != nil; tt.fail != got { t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) diff --git a/schema/manifestlist_test.go b/schema/manifestlist_test.go index 50de4f273..cff054275 100644 --- a/schema/manifestlist_test.go +++ b/schema/manifestlist_test.go @@ -239,7 +239,7 @@ func TestManifestList(t *testing.T) { }, } { r := strings.NewReader(tt.manifestList) - err := schema.MediaTypeManifestList.Validate(r) + err := schema.ValidatorMediaTypeManifestList.Validate(r) if got := err != nil; tt.fail != got { t.Errorf("test %d: expected validation failure %t but got %t, err %v", i, tt.fail, got, err) diff --git a/schema/schema.go b/schema/schema.go index 5e23ef51c..bdc5873d5 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -22,12 +22,12 @@ import ( // Media types for the OCI image formats const ( - MediaTypeDescriptor Validator = v1.MediaTypeDescriptor - MediaTypeManifest Validator = v1.MediaTypeImageManifest - MediaTypeManifestList Validator = v1.MediaTypeImageManifestList - MediaTypeImageConfig Validator = v1.MediaTypeImageConfig - TypeImageLayout Validator = v1.ImageLayoutFile - MediaTypeImageLayer unimplemented = v1.MediaTypeImageLayer + ValidatorMediaTypeDescriptor Validator = v1.MediaTypeDescriptor + ValidatorMediaTypeManifest Validator = v1.MediaTypeImageManifest + ValidatorMediaTypeManifestList Validator = v1.MediaTypeImageManifestList + ValidatorMediaTypeImageConfig Validator = v1.MediaTypeImageConfig + ValidatorTypeImageLayout Validator = v1.ImageLayoutFile + ValidatorMediaTypeImageLayer unimplemented = v1.MediaTypeImageLayer ) var ( @@ -37,11 +37,11 @@ var ( // specs maps OCI schema media types to schema files. specs = map[Validator]string{ - MediaTypeDescriptor: "content-descriptor.json", - MediaTypeManifest: "image-manifest-schema.json", - MediaTypeManifestList: "manifest-list-schema.json", - MediaTypeImageConfig: "config-schema.json", - TypeImageLayout: "image-layout-schema.json", + ValidatorMediaTypeDescriptor: "content-descriptor.json", + ValidatorMediaTypeManifest: "image-manifest-schema.json", + ValidatorMediaTypeManifestList: "manifest-list-schema.json", + ValidatorMediaTypeImageConfig: "config-schema.json", + ValidatorTypeImageLayout: "image-layout-schema.json", } ) diff --git a/schema/validator.go b/schema/validator.go index 432e7b992..6a3385779 100644 --- a/schema/validator.go +++ b/schema/validator.go @@ -33,7 +33,7 @@ type Validator string type validateDescendantsFunc func(r io.Reader) error var mapValidateDescendants = map[Validator]validateDescendantsFunc{ - MediaTypeManifest: validateManifestDescendants, + ValidatorMediaTypeManifest: validateManifestDescendants, } // ValidationError contains all the errors that happened during validation.