/// <summary> /// Upload a manifest for an OCI Artifact. /// </summary> /// <param name="manifest">The manifest to upload.</param> /// <param name="options">Options for configuring the upload operation.</param> /// <param name="cancellationToken"> The cancellation token to use. </param> /// <returns></returns> public virtual async Task <Response <UploadManifestResult> > UploadManifestAsync(OciManifest manifest, UploadManifestOptions options = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(manifest, nameof(manifest)); options ??= new UploadManifestOptions(); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRegistryBlobClient)}.{nameof(UploadManifest)}"); scope.Start(); try { Stream manifestStream = SerializeManifest(manifest); string manifestDigest = OciBlobDescriptor.ComputeDigest(manifestStream); string tagOrDigest = options.Tag ?? manifestDigest; ResponseWithHeaders <ContainerRegistryCreateManifestHeaders> response = await _restClient.CreateManifestAsync(_repositoryName, tagOrDigest, manifestStream, ManifestMediaType.OciManifest.ToString(), cancellationToken).ConfigureAwait(false); if (!manifestDigest.Equals(response.Headers.DockerContentDigest, StringComparison.Ordinal)) { throw _clientDiagnostics.CreateRequestFailedException(response, new ResponseError(null, "The digest in the response does not match the digest of the uploaded manifest.")); } return(Response.FromValue(new UploadManifestResult(response.Headers.DockerContentDigest), response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <Response <UploadManifestResult> > UploadManifestAsync(Stream stream, UploadManifestOptions options = default, CancellationToken cancellationToken = default) { options ??= new UploadManifestOptions(); string reference = options.Tag ?? DigestHelper.ComputeDigest(DigestHelper.AlgorithmIdentifierSha256, stream); stream.Position = 0; ResponseWithHeaders <ContainerRegistryCreateManifestHeaders> response = await _restClient.CreateManifestAsync(_repositoryName, reference, options.MediaType, stream, cancellationToken).ConfigureAwait(false); return(Response.FromValue(new UploadManifestResult(), response.GetRawResponse())); }