diff --git a/src/OrasProject.Oras/Constants/OCIMediaTypes .cs b/src/OrasProject.Oras/Constants/OCIMediaTypes .cs deleted file mode 100644 index 6eccb43..0000000 --- a/src/OrasProject.Oras/Constants/OCIMediaTypes .cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright The ORAS Authors. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace OrasProject.Oras.Constants -{ - public static class OCIMediaTypes - { - // MediaTypeDescriptor specifies the media type for a content descriptor. - public const string Descriptor = "application/vnd.oci.descriptor.v1+json"; - - // MediaTypeLayoutHeader specifies the media type for the oci-layout. - public const string LayoutHeader = "application/vnd.oci.layout.header.v1+json"; - - // MediaTypeImageManifest specifies the media type for an image manifest. - public const string ImageManifest = "application/vnd.oci.image.manifest.v1+json"; - - // MediaTypeImageIndex specifies the media type for an image index. - public const string ImageIndex = "application/vnd.oci.image.index.v1+json"; - - // MediaTypeImageLayer is the media type used for layers referenced by the manifest. - public const string ImageLayer = "application/vnd.oci.image.layer.v1.tar"; - - // MediaTypeImageLayerGzip is the media type used for gzipped layers - // referenced by the manifest. - public const string ImageLayerGzip = "application/vnd.oci.image.layer.v1.tar+gzip"; - - // MediaTypeImageLayerZstd is the media type used for zstd compressed - // layers referenced by the manifest. - public const string ImageLayerZstd = "application/vnd.oci.image.layer.v1.tar+zstd"; - - // MediaTypeImageLayerNonDistributable is the media type for layers referenced by - // the manifest but with distribution restrictions. - public const string ImageLayerNonDistributable = "application/vnd.oci.image.layer.nondistributable.v1.tar"; - - // MediaTypeImageLayerNonDistributableGzip is the media type for - // gzipped layers referenced by the manifest but with distribution - // restrictions. - public const string ImageLayerNonDistributableGzip = "application/vnd.oci.image.layer.nondistributable.v1.tar+gzip"; - - // MediaTypeImageLayerNonDistributableZstd is the media type for zstd - // compressed layers referenced by the manifest but with distribution - // restrictions. - public const string ImageLayerNonDistributableZstd = "application/vnd.oci.image.layer.nondistributable.v1.tar+zstd"; - - // MediaTypeImageConfig specifies the media type for the image configuration. - public const string ImageConfig = "application/vnd.oci.image.config.v1+json"; - - } -} diff --git a/src/OrasProject.Oras/Content/Content.cs b/src/OrasProject.Oras/Content/Content.cs index 163fce4..b9fa802 100644 --- a/src/OrasProject.Oras/Content/Content.cs +++ b/src/OrasProject.Oras/Content/Content.cs @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using OrasProject.Oras.Constants; using OrasProject.Oras.Exceptions; using OrasProject.Oras.Interfaces; using OrasProject.Oras.Oci; @@ -39,8 +38,8 @@ public static async Task> SuccessorsAsync(IFetcher fetcher, De { switch (node.MediaType) { - case DockerMediaTypes.Manifest: - case OCIMediaTypes.ImageManifest: + case Docker.MediaType.Manifest: + case Oci.MediaType.ImageManifest: { var content = await FetchAllAsync(fetcher, node, cancellationToken); var manifest = JsonSerializer.Deserialize(content); @@ -48,8 +47,8 @@ public static async Task> SuccessorsAsync(IFetcher fetcher, De descriptors.AddRange(manifest.Layers); return descriptors; } - case DockerMediaTypes.ManifestList: - case OCIMediaTypes.ImageIndex: + case Docker.MediaType.ManifestList: + case Oci.MediaType.ImageIndex: { var content = await FetchAllAsync(fetcher, node, cancellationToken); // docker manifest list and oci index are equivalent for successors. diff --git a/src/OrasProject.Oras/Constants/DockerMediaTypes.cs b/src/OrasProject.Oras/Docker/MediaType.cs similarity index 53% rename from src/OrasProject.Oras/Constants/DockerMediaTypes.cs rename to src/OrasProject.Oras/Docker/MediaType.cs index 7ed9099..afa26f4 100644 --- a/src/OrasProject.Oras/Constants/DockerMediaTypes.cs +++ b/src/OrasProject.Oras/Docker/MediaType.cs @@ -11,14 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace OrasProject.Oras.Constants +namespace OrasProject.Oras.Docker; + +/// +/// Docker media types +/// +public static class MediaType { - public static class DockerMediaTypes - { - // Docker media types - public const string Config = "application/vnd.docker.container.image.v1+json"; - public const string ManifestList = "application/vnd.docker.distribution.manifest.list.v2+json"; - public const string Manifest = "application/vnd.docker.distribution.manifest.v2+json"; - public const string ForeignLayer = "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip"; - } + public const string Config = "application/vnd.docker.container.image.v1+json"; + public const string ManifestList = "application/vnd.docker.distribution.manifest.list.v2+json"; + public const string Manifest = "application/vnd.docker.distribution.manifest.v2+json"; + public const string ForeignLayer = "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip"; } diff --git a/src/OrasProject.Oras/Oci/Index.cs b/src/OrasProject.Oras/Oci/Index.cs index a0b85d8..e11eff2 100644 --- a/src/OrasProject.Oras/Oci/Index.cs +++ b/src/OrasProject.Oras/Oci/Index.cs @@ -21,8 +21,8 @@ public class Index : Versioned // MediaType specifies the type of this document data structure e.g. `application/vnd.oci.image.index.v1+json` [JsonPropertyName("mediaType")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public string? MediaType { get; set; } - + public string? MediaType { get; set; } + [JsonPropertyName("artifactType")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public string? ArtifactType { get; set; } diff --git a/src/OrasProject.Oras/Oci/Manifest.cs b/src/OrasProject.Oras/Oci/Manifest.cs index acfc86e..330f17f 100644 --- a/src/OrasProject.Oras/Oci/Manifest.cs +++ b/src/OrasProject.Oras/Oci/Manifest.cs @@ -24,13 +24,13 @@ public class Manifest : Versioned [JsonPropertyName("artifactType")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public string? ArtifactType { get; set; } - + public string? ArtifactType { get; set; } + [JsonPropertyName("config")] public required Descriptor Config { get; set; } [JsonPropertyName("layers")] - public required IList Layers { get; set; } + public required IList Layers { get; set; } [JsonPropertyName("subject")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] diff --git a/src/OrasProject.Oras/Oci/MediaType.cs b/src/OrasProject.Oras/Oci/MediaType.cs new file mode 100644 index 0000000..9026042 --- /dev/null +++ b/src/OrasProject.Oras/Oci/MediaType.cs @@ -0,0 +1,84 @@ +// Copyright The ORAS Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace OrasProject.Oras.Oci; + +public static class MediaType +{ + /// + /// Descriptor specifies the media type for a content descriptor. + /// + public const string Descriptor = "application/vnd.oci.descriptor.v1+json"; + + /// + /// LayoutHeader specifies the media type for the oci-layout. + /// + public const string LayoutHeader = "application/vnd.oci.layout.header.v1+json"; + + /// + /// ImageIndex specifies the media type for an image index. + /// + public const string ImageIndex = "application/vnd.oci.image.index.v1+json"; + + /// + /// ImageManifest specifies the media type for an image manifest. + /// + public const string ImageManifest = "application/vnd.oci.image.manifest.v1+json"; + + /// + /// ImageConfig specifies the media type for the image configuration. + /// + public const string ImageConfig = "application/vnd.oci.image.config.v1+json"; + + /// + /// EmptyJSON specifies the media type for an unused blob containing the value "{}". + /// + public const string EmptyJson = "application/vnd.oci.empty.v1+json"; + + /// + /// ImageLayer is the media type used for layers referenced by the manifest. + /// + public const string ImageLayer = "application/vnd.oci.image.layer.v1.tar"; + + /// + /// ImageLayerGzip is the media type used for gzipped layers + /// referenced by the manifest. + /// + public const string ImageLayerGzip = "application/vnd.oci.image.layer.v1.tar+gzip"; + + /// + /// ImageLayerZstd is the media type used for zstd compressed + /// layers referenced by the manifest. + /// + public const string ImageLayerZstd = "application/vnd.oci.image.layer.v1.tar+zstd"; + + /// + /// ImageLayerNonDistributable is the media type for layers referenced by + /// the manifest but with distribution restrictions. + /// + public const string ImageLayerNonDistributable = "application/vnd.oci.image.layer.nondistributable.v1.tar"; + + /// + /// ImageLayerNonDistributableGzip is the media type for + /// gzipped layers referenced by the manifest but with distribution + /// restrictions. + /// + public const string ImageLayerNonDistributableGzip = "application/vnd.oci.image.layer.nondistributable.v1.tar+gzip"; + + /// + /// ImageLayerNonDistributableZstd is the media type for zstd + /// compressed layers referenced by the manifest but with distribution + /// restrictions. + /// + public const string ImageLayerNonDistributableZstd = "application/vnd.oci.image.layer.nondistributable.v1.tar+zstd"; +} diff --git a/src/OrasProject.Oras/Remote/ManifestUtility.cs b/src/OrasProject.Oras/Remote/ManifestUtility.cs index 535b257..154faa2 100644 --- a/src/OrasProject.Oras/Remote/ManifestUtility.cs +++ b/src/OrasProject.Oras/Remote/ManifestUtility.cs @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using OrasProject.Oras.Constants; using OrasProject.Oras.Oci; using System.Linq; @@ -21,10 +20,10 @@ internal static class ManifestUtility { internal static string[] DefaultManifestMediaTypes = new[] { - DockerMediaTypes.Manifest, - DockerMediaTypes.ManifestList, - OCIMediaTypes.ImageIndex, - OCIMediaTypes.ImageManifest + Docker.MediaType.Manifest, + Docker.MediaType.ManifestList, + Oci.MediaType.ImageIndex, + Oci.MediaType.ImageManifest }; /// diff --git a/tests/OrasProject.Oras.Tests/CopyTest.cs b/tests/OrasProject.Oras.Tests/CopyTest.cs index 9f66cd1..50a848d 100644 --- a/tests/OrasProject.Oras.Tests/CopyTest.cs +++ b/tests/OrasProject.Oras.Tests/CopyTest.cs @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using OrasProject.Oras.Constants; using OrasProject.Oras.Memory; using OrasProject.Oras.Oci; using System.Text; @@ -54,12 +53,12 @@ public async Task CanCopyBetweenMemoryTargetsWithTaggedNode() Layers = layers }; var manifestBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(manifest)); - appendBlob(OCIMediaTypes.ImageManifest, manifestBytes); + appendBlob(MediaType.ImageManifest, manifestBytes); }; var getBytes = (string data) => Encoding.UTF8.GetBytes(data); - appendBlob(OCIMediaTypes.ImageConfig, getBytes("config")); // blob 0 - appendBlob(OCIMediaTypes.ImageLayer, getBytes("foo")); // blob 1 - appendBlob(OCIMediaTypes.ImageLayer, getBytes("bar")); // blob 2 + appendBlob(MediaType.ImageConfig, getBytes("config")); // blob 0 + appendBlob(MediaType.ImageLayer, getBytes("foo")); // blob 1 + appendBlob(MediaType.ImageLayer, getBytes("bar")); // blob 2 generateManifest(descs[0], descs.GetRange(1, 2)); // blob 3 for (var i = 0; i < blobs.Count; i++) @@ -117,12 +116,12 @@ public async Task CanCopyBetweenMemoryTargets() Layers = layers }; var manifestBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(manifest)); - appendBlob(OCIMediaTypes.ImageManifest, manifestBytes); + appendBlob(MediaType.ImageManifest, manifestBytes); }; var getBytes = (string data) => Encoding.UTF8.GetBytes(data); - appendBlob(OCIMediaTypes.ImageConfig, getBytes("config")); // blob 0 - appendBlob(OCIMediaTypes.ImageLayer, getBytes("foo")); // blob 1 - appendBlob(OCIMediaTypes.ImageLayer, getBytes("bar")); // blob 2 + appendBlob(MediaType.ImageConfig, getBytes("config")); // blob 0 + appendBlob(MediaType.ImageLayer, getBytes("foo")); // blob 1 + appendBlob(MediaType.ImageLayer, getBytes("bar")); // blob 2 generateManifest(descs[0], descs.GetRange(1, 2)); // blob 3 for (var i = 0; i < blobs.Count; i++) diff --git a/tests/OrasProject.Oras.Tests/MemoryTest/MemoryTargetTest.cs b/tests/OrasProject.Oras.Tests/MemoryTest/MemoryTargetTest.cs index 940bea1..826abd7 100644 --- a/tests/OrasProject.Oras.Tests/MemoryTest/MemoryTargetTest.cs +++ b/tests/OrasProject.Oras.Tests/MemoryTest/MemoryTargetTest.cs @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using OrasProject.Oras.Constants; using OrasProject.Oras.Exceptions; using OrasProject.Oras.Memory; using OrasProject.Oras.Oci; @@ -193,7 +192,7 @@ public async Task ShouldReturnPredecessorsOfNodes() Layers = layers }; var manifestBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(manifest)); - appendBlob(OCIMediaTypes.ImageManifest, manifestBytes); + appendBlob(MediaType.ImageManifest, manifestBytes); }; var generateIndex = (List manifests) => @@ -203,13 +202,13 @@ public async Task ShouldReturnPredecessorsOfNodes() Manifests = manifests }; var indexBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(index)); - appendBlob(OCIMediaTypes.ImageIndex, indexBytes); + appendBlob(MediaType.ImageIndex, indexBytes); }; var getBytes = (string data) => Encoding.UTF8.GetBytes(data); - appendBlob(OCIMediaTypes.ImageConfig, getBytes("config")); // blob 0 - appendBlob(OCIMediaTypes.ImageLayer, getBytes("foo")); // blob 1 - appendBlob(OCIMediaTypes.ImageLayer, getBytes("bar")); // blob 2 - appendBlob(OCIMediaTypes.ImageLayer, getBytes("hello")); // blob 3 + appendBlob(MediaType.ImageConfig, getBytes("config")); // blob 0 + appendBlob(MediaType.ImageLayer, getBytes("foo")); // blob 1 + appendBlob(MediaType.ImageLayer, getBytes("bar")); // blob 2 + appendBlob(MediaType.ImageLayer, getBytes("hello")); // blob 3 generateManifest(descs[0], descs.GetRange(1, 2)); // blob 4 generateManifest(descs[0], new() { descs[3] }); // blob 5 generateManifest(descs[0], descs.GetRange(1, 3)); // blob 6 diff --git a/tests/OrasProject.Oras.Tests/RemoteTest/RepositoryTest.cs b/tests/OrasProject.Oras.Tests/RemoteTest/RepositoryTest.cs index d4bcded..bb8c5d8 100644 --- a/tests/OrasProject.Oras.Tests/RemoteTest/RepositoryTest.cs +++ b/tests/OrasProject.Oras.Tests/RemoteTest/RepositoryTest.cs @@ -13,7 +13,6 @@ using Moq; using Moq.Protected; -using OrasProject.Oras.Constants; using OrasProject.Oras.Exceptions; using OrasProject.Oras.Memory; using OrasProject.Oras.Oci; @@ -176,7 +175,7 @@ public async Task Repository_FetchAsync() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; var func = (HttpRequestMessage req, CancellationToken cancellationToken) => @@ -201,7 +200,7 @@ public async Task Repository_FetchAsync() if (path == "/v2/test/manifests/" + indexDesc.Digest) { - if (!req.Headers.Accept.Contains(new MediaTypeWithQualityHeaderValue(OCIMediaTypes.ImageIndex))) + if (!req.Headers.Accept.Contains(new MediaTypeWithQualityHeaderValue(MediaType.ImageIndex))) { resp.StatusCode = HttpStatusCode.BadRequest; Debug.WriteLine("manifest not convertable: " + req.Headers.Accept); @@ -250,7 +249,7 @@ public async Task Repository_PushAsync() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; var uuid = Guid.NewGuid().ToString(); @@ -296,7 +295,7 @@ public async Task Repository_PushAsync() req.RequestUri!.AbsolutePath == "/v2/test/manifests/" + indexDesc.Digest) { if (req.Headers.TryGetValues("Content-Type", out var values) && - !values.Contains(OCIMediaTypes.ImageIndex)) + !values.Contains(MediaType.ImageIndex)) { resp.StatusCode = HttpStatusCode.BadRequest; return resp; @@ -342,7 +341,7 @@ public async Task Repository_ExistsAsync() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; var func = (HttpRequestMessage req, CancellationToken cancellationToken) => @@ -365,7 +364,7 @@ public async Task Repository_ExistsAsync() if (req.RequestUri!.AbsolutePath == "/v2/test/manifests/" + indexDesc.Digest) { if (req.Headers.TryGetValues("Accept", out var values) && - !values.Contains(OCIMediaTypes.ImageIndex)) + !values.Contains(MediaType.ImageIndex)) { return new HttpResponseMessage(HttpStatusCode.NotAcceptable); } @@ -407,7 +406,7 @@ public async Task Repository_DeleteAsync() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; var indexDeleted = false; @@ -466,7 +465,7 @@ public async Task Repository_ResolveAsync() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; var reference = "foobar"; @@ -490,7 +489,7 @@ public async Task Repository_ResolveAsync() { if (req.Headers.TryGetValues("Accept", out var values) && - !values.Contains(OCIMediaTypes.ImageIndex)) + !values.Contains(MediaType.ImageIndex)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } @@ -541,7 +540,7 @@ public async Task Repository_TagAsync() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; byte[]? gotIndex = null; @@ -561,7 +560,7 @@ public async Task Repository_TagAsync() req.RequestUri?.AbsolutePath == "/v2/test/manifests/" + indexDesc.Digest) { if (req.Headers.TryGetValues("Accept", out var values) && - !values.Contains(OCIMediaTypes.ImageIndex)) + !values.Contains(MediaType.ImageIndex)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } @@ -577,7 +576,7 @@ public async Task Repository_TagAsync() { if (req.Headers.TryGetValues("Content-Type", out var values) && - !values.Contains(OCIMediaTypes.ImageIndex)) + !values.Contains(MediaType.ImageIndex)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } @@ -616,7 +615,7 @@ public async Task Repository_PushReferenceAsync() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; byte[]? gotIndex = null; @@ -629,7 +628,7 @@ public async Task Repository_PushReferenceAsync() if (req.Method == HttpMethod.Put && req.RequestUri?.AbsolutePath == "/v2/test/manifests/" + reference) { if (req.Headers.TryGetValues("Content-Type", out var values) && - !values.Contains(OCIMediaTypes.ImageIndex)) + !values.Contains(MediaType.ImageIndex)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } @@ -672,7 +671,7 @@ public async Task Repository_FetchReferenceAsyc() var indexDesc = new Descriptor() { Digest = CalculateDigest(index), - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Size = index.Length }; var reference = "foobar"; @@ -695,7 +694,7 @@ public async Task Repository_FetchReferenceAsyc() || req.RequestUri?.AbsolutePath == "/v2/test/manifests/" + reference) { if (req.Headers.TryGetValues("Accept", out var values) && - !values.Contains(OCIMediaTypes.ImageIndex)) + !values.Contains(MediaType.ImageIndex)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } @@ -1522,7 +1521,7 @@ public async Task ManifestStore_FetchAsync() var manifest = """{"layers":[]}"""u8.ToArray(); var manifestDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageManifest, + MediaType = MediaType.ImageManifest, Digest = CalculateDigest(manifest), Size = manifest.Length }; @@ -1537,12 +1536,12 @@ public async Task ManifestStore_FetchAsync() } if (req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{manifestDesc.Digest}") { - if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(OCIMediaTypes.ImageManifest)) + if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(MediaType.ImageManifest)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } res.Content = new ByteArrayContent(manifest); - res.Content.Headers.Add("Content-Type", new string[] { OCIMediaTypes.ImageManifest }); + res.Content.Headers.Add("Content-Type", new string[] { MediaType.ImageManifest }); res.Content.Headers.Add("Docker-Content-Digest", new string[] { manifestDesc.Digest }); return res; } @@ -1561,7 +1560,7 @@ public async Task ManifestStore_FetchAsync() var content = """{"manifests":[]}"""u8.ToArray(); var contentDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Digest = CalculateDigest(content), Size = content.Length }; @@ -1578,7 +1577,7 @@ public async Task ManifestStore_PushAsync() var manifest = """{"layers":[]}"""u8.ToArray(); var manifestDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageManifest, + MediaType = MediaType.ImageManifest, Digest = CalculateDigest(manifest), Size = manifest.Length }; @@ -1590,7 +1589,7 @@ public async Task ManifestStore_PushAsync() res.RequestMessage = req; if (req.Method == HttpMethod.Put && req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{manifestDesc.Digest}") { - if (req.Headers.TryGetValues("Content-Type", out IEnumerable? values) && !values.Contains(OCIMediaTypes.ImageManifest)) + if (req.Headers.TryGetValues("Content-Type", out IEnumerable? values) && !values.Contains(MediaType.ImageManifest)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } @@ -1629,7 +1628,7 @@ public async Task ManifestStore_ExistAsync() var manifest = """{"layers":[]}"""u8.ToArray(); var manifestDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageManifest, + MediaType = MediaType.ImageManifest, Digest = CalculateDigest(manifest), Size = manifest.Length }; @@ -1643,12 +1642,12 @@ public async Task ManifestStore_ExistAsync() } if (req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{manifestDesc.Digest}") { - if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(OCIMediaTypes.ImageManifest)) + if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(MediaType.ImageManifest)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } res.Content.Headers.Add("Docker-Content-Digest", new string[] { manifestDesc.Digest }); - res.Content.Headers.Add("Content-Type", new string[] { OCIMediaTypes.ImageManifest }); + res.Content.Headers.Add("Content-Type", new string[] { MediaType.ImageManifest }); res.Content.Headers.Add("Content-Length", new string[] { manifest.Length.ToString() }); return res; } @@ -1665,7 +1664,7 @@ public async Task ManifestStore_ExistAsync() var content = """{"manifests":[]}"""u8.ToArray(); var contentDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Digest = CalculateDigest(content), Size = content.Length }; @@ -1683,7 +1682,7 @@ public async Task ManifestStore_DeleteAsync() var manifest = """{"layers":[]}"""u8.ToArray(); var manifestDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageManifest, + MediaType = MediaType.ImageManifest, Digest = CalculateDigest(manifest), Size = manifest.Length }; @@ -1704,13 +1703,13 @@ public async Task ManifestStore_DeleteAsync() } if (req.Method == HttpMethod.Get && req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{manifestDesc.Digest}") { - if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(OCIMediaTypes.ImageManifest)) + if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(MediaType.ImageManifest)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } res.Content = new ByteArrayContent(manifest); res.Content.Headers.Add("Docker-Content-Digest", new string[] { manifestDesc.Digest }); - res.Content.Headers.Add("Content-Type", new string[] { OCIMediaTypes.ImageManifest }); + res.Content.Headers.Add("Content-Type", new string[] { MediaType.ImageManifest }); return res; } return new HttpResponseMessage(HttpStatusCode.NotFound); @@ -1726,7 +1725,7 @@ public async Task ManifestStore_DeleteAsync() var content = """{"manifests":[]}"""u8.ToArray(); var contentDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Digest = CalculateDigest(content), Size = content.Length }; @@ -1743,7 +1742,7 @@ public async Task ManifestStore_ResolveAsync() var manifest = """{"layers":[]}"""u8.ToArray(); var manifestDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageManifest, + MediaType = MediaType.ImageManifest, Digest = CalculateDigest(manifest), Size = manifest.Length }; @@ -1758,12 +1757,12 @@ public async Task ManifestStore_ResolveAsync() } if (req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{manifestDesc.Digest}" || req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{reference}") { - if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(OCIMediaTypes.ImageManifest)) + if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(MediaType.ImageManifest)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } res.Content.Headers.Add("Docker-Content-Digest", new string[] { manifestDesc.Digest }); - res.Content.Headers.Add("Content-Type", new string[] { OCIMediaTypes.ImageManifest }); + res.Content.Headers.Add("Content-Type", new string[] { MediaType.ImageManifest }); res.Content.Headers.Add("Content-Length", new string[] { manifest.Length.ToString() }); return res; } @@ -1790,7 +1789,7 @@ public async Task ManifestStore_ResolveAsync() var content = """{"manifests":[]}"""u8.ToArray(); var contentDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Digest = CalculateDigest(content), Size = content.Length }; @@ -1809,7 +1808,7 @@ public async Task ManifestStore_FetchReferenceAsync() var manifest = """{"layers":[]}"""u8.ToArray(); var manifestDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageManifest, + MediaType = MediaType.ImageManifest, Digest = CalculateDigest(manifest), Size = manifest.Length }; @@ -1824,13 +1823,13 @@ public async Task ManifestStore_FetchReferenceAsync() } if (req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{manifestDesc.Digest}" || req.RequestUri?.AbsolutePath == $"/v2/test/manifests/{reference}") { - if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(OCIMediaTypes.ImageManifest)) + if (req.Headers.TryGetValues("Accept", out IEnumerable? values) && !values.Contains(MediaType.ImageManifest)) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } res.Content = new ByteArrayContent(manifest); res.Content.Headers.Add("Docker-Content-Digest", new string[] { manifestDesc.Digest }); - res.Content.Headers.Add("Content-Type", new string[] { OCIMediaTypes.ImageManifest }); + res.Content.Headers.Add("Content-Type", new string[] { MediaType.ImageManifest }); return res; } return new HttpResponseMessage(HttpStatusCode.NotFound); @@ -1894,7 +1893,7 @@ public async Task ManifestStore_TagAsync() var index = """{"manifests":[]}"""u8.ToArray(); var indexDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Digest = CalculateDigest(index), Size = index.Length }; @@ -1970,7 +1969,7 @@ public async Task ManifestStore_PushReferenceAsync() var index = """{"manifests":[]}"""u8.ToArray(); var indexDesc = new Descriptor { - MediaType = OCIMediaTypes.ImageIndex, + MediaType = MediaType.ImageIndex, Digest = CalculateDigest(index), Size = index.Length }; @@ -2024,7 +2023,7 @@ public async Task CopyFromRepositoryToMemory() var exampleManifestDescriptor = new Descriptor { - MediaType = OCIMediaTypes.Descriptor, + MediaType = MediaType.Descriptor, Digest = CalculateSHA256DigestFromBytes(exampleManifest), Size = exampleManifest.Length }; @@ -2039,7 +2038,7 @@ public async Task CopyFromRepositoryToMemory() { res.StatusCode = HttpStatusCode.Accepted; res.Headers.Location = new Uri($"{path}/{exampleUploadUUid}"); - res.Headers.Add("Content-Type", OCIMediaTypes.ImageManifest); + res.Headers.Add("Content-Type", MediaType.ImageManifest); return res; } if (path.Contains("/blobs/uploads/" + exampleUploadUUid) && method == HttpMethod.Get) @@ -2059,12 +2058,12 @@ public async Task CopyFromRepositoryToMemory() if (method == HttpMethod.Get) { res.Content = new ByteArrayContent(exampleManifest); - res.Content.Headers.Add("Content-Type", OCIMediaTypes.Descriptor); + res.Content.Headers.Add("Content-Type", MediaType.Descriptor); res.Content.Headers.Add("Docker-Content-Digest", exampleManifestDescriptor.Digest); res.Content.Headers.Add("Content-Length", exampleManifest.Length.ToString()); return res; } - res.Content.Headers.Add("Content-Type", OCIMediaTypes.Descriptor); + res.Content.Headers.Add("Content-Type", MediaType.Descriptor); res.Content.Headers.Add("Docker-Content-Digest", exampleManifestDescriptor.Digest); res.Content.Headers.Add("Content-Length", exampleManifest.Length.ToString()); return res;