Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to support manifest upload/download #5

Draft
wants to merge 1 commit into
base: feature/containerregistry/oci-blob-api
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class ArtifactBlobDescriptor
internal IList<Uri> Urls { get; }

/// <summary> Additional information provided through arbitrary metadata. </summary>
internal Annotations Annotations { get; }
//internal Annotations Annotations { get; }

internal static string ComputeDigest(Stream stream)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,101 @@ protected ContainerRegistryBlobClient()

#region File Upload/Download

///// <summary>
///// </summary>
///// <param name="stream"></param>
///// <param name="options"></param>
///// <param name="cancellationToken"></param>
///// <returns></returns>
//public virtual Response<UploadManifestResult> UploadManifest(Stream stream, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
//{
// throw new NotImplementedException();
//}

///// <summary>
///// </summary>
///// <param name="stream"></param>
///// <param name="options"></param>
///// <param name="cancellationToken"></param>
///// <returns></returns>
//public async virtual Task<Response<UploadManifestResult>> UploadManifestAsync(Stream stream, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
//{
// options ??= new UploadManifestOptions();

// using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRegistryBlobClient)}.{nameof(UploadManifest)}");
// scope.Start();
// try
// {
// string tagOrDigest = options.Tag ?? ArtifactBlobDescriptor.ComputeDigest(stream);
// ResponseWithHeaders<ContainerRegistryCreateManifestHeaders> response = await _restClient.CreateManifestAsync(_repositoryName, tagOrDigest, stream, ManifestMediaType.OciManifest.ToString(), cancellationToken).ConfigureAwait(false);
// return Response.FromValue(new UploadManifestResult(response.Headers.DockerContentDigest), response.GetRawResponse());
// }
// catch (Exception e)
// {
// scope.Failed(e);
// throw;
// }
//}

///// <summary>
///// </summary>
///// <param name="manifest"></param>
///// <param name="options"></param>
///// <param name="cancellationToken"></param>
///// <returns></returns>
//public virtual Response<UploadManifestResult> UploadManifest(OciManifest manifest, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
//{
// throw new NotImplementedException();
//}

///// <summary>
///// </summary>
///// <param name="manifest"></param>
///// <param name="options"></param>
///// <param name="cancellationToken"></param>
///// <returns></returns>
//public async virtual Task<Response<UploadManifestResult>> UploadManifestAsync(OciManifest manifest, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
//{
// Argument.AssertNotNull(manifest, "manifest");

// MemoryStream stream = new MemoryStream();
// Utf8JsonWriter jsonWriter = new Utf8JsonWriter(stream);
// ((IUtf8JsonSerializable)manifest).Write(jsonWriter);
// return await UploadManifestAsync(stream, options, cancellationToken).ConfigureAwait(false);
//}

/// <summary>
/// </summary>
/// <param name="stream"></param>
/// <param name="manifest"></param>
/// <param name="options"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Response<UploadManifestResult> UploadManifest(Stream stream, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
public virtual Response<UploadManifestResult> UploadManifest(OciManifest manifest, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

/// <summary>
/// </summary>
/// <param name="stream"></param>
/// <param name="manifest"></param>
/// <param name="options"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async virtual Task<Response<UploadManifestResult>> UploadManifestAsync(Stream stream, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
public async virtual Task<Response<UploadManifestResult>> UploadManifestAsync(OciManifest manifest, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
{
options ??= new UploadManifestOptions();

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ContainerRegistryBlobClient)}.{nameof(UploadManifest)}");
scope.Start();
try
{
MemoryStream stream = new MemoryStream();
Utf8JsonWriter jsonWriter = new Utf8JsonWriter(stream);
((IUtf8JsonSerializable)manifest).Write(jsonWriter);
jsonWriter.Flush();

string tagOrDigest = options.Tag ?? ArtifactBlobDescriptor.ComputeDigest(stream);
ResponseWithHeaders<ContainerRegistryCreateManifestHeaders> response = await _restClient.CreateManifestAsync(_repositoryName, tagOrDigest, stream, ManifestMediaType.OciManifest.ToString(), cancellationToken).ConfigureAwait(false);
ResponseWithHeaders<ContainerRegistryCreateManifestHeaders> response = await _restClient.CreateManifestAsync(_repositoryName, tagOrDigest, manifest, ManifestMediaType.OciManifest.ToString(), cancellationToken).ConfigureAwait(false);
return Response.FromValue(new UploadManifestResult(response.Headers.DockerContentDigest), response.GetRawResponse());
}
catch (Exception e)
Expand All @@ -114,33 +182,6 @@ public async virtual Task<Response<UploadManifestResult>> UploadManifestAsync(St
}
}

/// <summary>
/// </summary>
/// <param name="manifest"></param>
/// <param name="options"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Response<UploadManifestResult> UploadManifest(OciManifest manifest, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

/// <summary>
/// </summary>
/// <param name="manifest"></param>
/// <param name="options"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async virtual Task<Response<UploadManifestResult>> UploadManifestAsync(OciManifest manifest, UploadManifestOptions options = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(manifest, "manifest");

MemoryStream stream = new MemoryStream();
Utf8JsonWriter jsonWriter = new Utf8JsonWriter(stream);
((IUtf8JsonSerializable)manifest).Write(jsonWriter);
return await UploadManifestAsync(stream, options, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// </summary>
/// <param name="stream"></param>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;
using Azure.Core;

namespace Azure.Containers.ContainerRegistry.Specialized
{
/// <summary>
/// </summary>
[CodeGenModel("Manifest")]
#pragma warning disable AZC0012 // Avoid single word type names
public partial class Manifest
#pragma warning restore AZC0012 // Avoid single word type names
{
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading