Beispiel #1
0
        /// <summary>
        /// Create an OciManifest type that matches the contents of the manifest.json test data file.
        /// </summary>
        /// <returns></returns>
        private static OciManifest CreateManifest()
        {
            OciManifest manifest = new OciManifest()
            {
                SchemaVersion = 2,
                Config        = new OciBlobDescriptor()
                {
                    MediaType = "application/vnd.acme.rocket.config",
                    Digest    = "sha256:d25b42d3dbad5361ed2d909624d899e7254a822c9a632b582ebd3a44f9b0dbc8",
                    Size      = 171
                }
            };

            manifest.Layers.Add(new OciBlobDescriptor()
            {
                MediaType   = "application/vnd.oci.image.layer.v1.tar",
                Digest      = "sha256:654b93f61054e4ce90ed203bb8d556a6200d5f906cf3eca0620738d6dc18cbed",
                Size        = 28,
                Annotations = new OciAnnotations()
                {
                    Name = "artifact.txt"
                }
            });

            return(manifest);
        }
Beispiel #2
0
 public OciArtifactResult(string manifestDigest, OciManifest manifest, Stream manifestStream, Stream moduleStream)
 {
     this.ManifestDigest = manifestDigest;
     this.Manifest       = manifest;
     this.ManifestStream = manifestStream;
     this.ModuleStream   = moduleStream;
 }
Beispiel #3
0
        private static void ValidateManifest(OciManifest manifest)
        {
            // These are from the values in the Data\oci-artifact\manifest.json file.
            Assert.IsNotNull(manifest);

            Assert.IsNotNull(manifest.Config);
            Assert.AreEqual("application/vnd.acme.rocket.config", manifest.Config.MediaType);
            Assert.AreEqual("sha256:d25b42d3dbad5361ed2d909624d899e7254a822c9a632b582ebd3a44f9b0dbc8", manifest.Config.Digest);
            Assert.AreEqual(171, manifest.Config.Size);

            Assert.IsNotNull(manifest.Layers);
            Assert.AreEqual(1, manifest.Layers.Count);
            Assert.AreEqual("application/vnd.oci.image.layer.v1.tar", manifest.Layers[0].MediaType);
            Assert.AreEqual("sha256:654b93f61054e4ce90ed203bb8d556a6200d5f906cf3eca0620738d6dc18cbed", manifest.Layers[0].Digest);
            Assert.AreEqual(28, manifest.Layers[0].Size);
        }
Beispiel #4
0
        public async Task PushArtifactAsync(Configuration.RootConfiguration configuration, OciArtifactModuleReference moduleReference, StreamDescriptor config, params StreamDescriptor[] layers)
        {
            // TODO: Add similar exception handling as in the pull* method

            // TODO: How do we choose this? Does it ever change?
            var algorithmIdentifier = DescriptorFactory.AlgorithmIdentifierSha256;

            var blobClient = this.CreateBlobClient(configuration, moduleReference);

            config.ResetStream();
            var configDescriptor = DescriptorFactory.CreateDescriptor(algorithmIdentifier, config);

            config.ResetStream();
            var configUploadResult = await blobClient.UploadBlobAsync(config.Stream);

            var layerDescriptors = new List <OciDescriptor>(layers.Length);

            foreach (var layer in layers)
            {
                layer.ResetStream();
                var layerDescriptor = DescriptorFactory.CreateDescriptor(algorithmIdentifier, layer);
                layerDescriptors.Add(layerDescriptor);

                layer.ResetStream();
                var layerUploadResult = await blobClient.UploadBlobAsync(layer.Stream);
            }

            var manifest = new OciManifest(2, configDescriptor, layerDescriptors);

            using var manifestStream = new MemoryStream();
            OciSerialization.Serialize(manifestStream, manifest);

            manifestStream.Position = 0;
            // BUG: the client closes the stream :(
            var manifestUploadResult = await blobClient.UploadManifestAsync(manifestStream, new UploadManifestOptions(ContentType.ApplicationVndOciImageManifestV1Json, moduleReference.Tag));
        }
Beispiel #5
0
        private static async Task <Stream> ProcessManifest(BicepRegistryBlobClient client, OciManifest manifest)
        {
            ProcessConfig(manifest.Config);
            if (manifest.Layers.Length != 1)
            {
                throw new InvalidModuleException("Expected a single layer in the OCI artifact.");
            }

            var layer = manifest.Layers.Single();

            return(await ProcessLayer(client, layer));
        }
Beispiel #6
0
 /// <summary> Initializes a new instance of <see cref="Specialized.DownloadManifestResult" />. </summary>
 /// <param name="digest"> The manifest's digest, calculated by the registry. </param>
 /// <param name="manifest">The OCI manifest that was downloaded.</param>
 /// <param name="manifestStream">Manifest stream that was downloaded.</param>
 /// <returns> A new <see cref="Specialized.DownloadManifestResult"/> instance for mocking. </returns>
 public static DownloadManifestResult DownloadManifestResult(string digest = null, OciManifest manifest = null, Stream manifestStream = null)
 {
     return(new DownloadManifestResult(digest, manifest, manifestStream));
 }