Skip to content

Commit

Permalink
refactor: overload DoPushAsync (#165)
Browse files Browse the repository at this point in the history
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia authored Nov 25, 2024
1 parent f8b3632 commit abdecc3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/OrasProject.Oras/Registry/Remote/ManifestStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ public async Task<bool> ExistsAsync(Descriptor target, CancellationToken cancell
}

/// <summary>
/// Pushes the content, matching the expected descriptor.
/// Pushes the manifest content, matching the expected descriptor.
/// </summary>
/// <param name="expected"></param>
/// <param name="content"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task PushAsync(Descriptor expected, Stream content, CancellationToken cancellationToken = default)
=> await InternalPushAsync(expected, content, expected.Digest, cancellationToken).ConfigureAwait(false);
=> await PushAsync(expected, content, expected.Digest, cancellationToken).ConfigureAwait(false);

/// <summary>
/// PushReferenceASync pushes the manifest with a reference tag.
/// Pushes the manifest content with a reference tag.
/// </summary>
/// <param name="expected"></param>
/// <param name="content"></param>
Expand All @@ -152,8 +152,8 @@ public async Task PushAsync(Descriptor expected, Stream content, CancellationTok
/// <returns></returns>
public async Task PushAsync(Descriptor expected, Stream content, string reference, CancellationToken cancellationToken = default)
{
var contentReference = Repository.ParseReference(reference).ContentReference!;
await InternalPushAsync(expected, content, contentReference, cancellationToken).ConfigureAwait(false);
var remoteReference = Repository.ParseReference(reference);
await DoPushAsync(expected, content, remoteReference, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -163,9 +163,8 @@ public async Task PushAsync(Descriptor expected, Stream content, string referenc
/// <param name="stream"></param>
/// <param name="contentReference"></param>
/// <param name="cancellationToken"></param>
private async Task InternalPushAsync(Descriptor expected, Stream stream, string contentReference, CancellationToken cancellationToken)
private async Task DoPushAsync(Descriptor expected, Stream stream, Reference remoteReference, CancellationToken cancellationToken)
{
var remoteReference = Repository.ParseReference(contentReference);
var url = new UriFactory(remoteReference, Repository.Options.PlainHttp).BuildRepositoryManifest();
var request = new HttpRequestMessage(HttpMethod.Put, url);
request.Content = new StreamContent(stream);
Expand Down Expand Up @@ -206,7 +205,7 @@ public async Task TagAsync(Descriptor descriptor, string reference, Cancellation
{
var remoteReference = Repository.ParseReference(reference);
using var contentStream = await FetchAsync(descriptor, cancellationToken).ConfigureAwait(false);
await InternalPushAsync(descriptor, contentStream, remoteReference.ContentReference!, cancellationToken).ConfigureAwait(false);
await DoPushAsync(descriptor, contentStream, remoteReference, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down

0 comments on commit abdecc3

Please sign in to comment.