-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
1,570 additions
and
2,744 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultBlobOperations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Diagnostics; | ||
using System.Net; | ||
using System.Text.Json.Nodes; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.NET.Build.Containers; | ||
|
||
internal class DefaultBlobOperations : IBlobOperations | ||
{ | ||
private readonly Uri _baseUri; | ||
private readonly HttpClient _client; | ||
private readonly ILogger _logger; | ||
|
||
public DefaultBlobOperations(Uri baseUri, HttpClient client, ILogger logger) | ||
{ | ||
_baseUri = baseUri; | ||
_client = client; | ||
_logger = logger; | ||
Upload = new DefaultBlobUploadOperations(_baseUri, _client, _logger); | ||
} | ||
|
||
public IBlobUploadOperations Upload { get; } | ||
|
||
public async Task<bool> ExistsAsync(string repositoryName, string digest, CancellationToken cancellationToken) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
HttpResponseMessage response = await _client.SendAsync(new HttpRequestMessage(HttpMethod.Head, new Uri(_baseUri, $"/v2/{repositoryName}/blobs/{digest}")), cancellationToken).ConfigureAwait(false); | ||
return response.StatusCode == HttpStatusCode.OK; | ||
} | ||
|
||
public async Task<JsonNode> GetJsonAsync(string repositoryName, string digest, CancellationToken cancellationToken) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
HttpResponseMessage response = await GetAsync(repositoryName, digest, cancellationToken).ConfigureAwait(false); | ||
|
||
JsonNode? configDoc = JsonNode.Parse(await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)); | ||
Debug.Assert(configDoc is not null); | ||
|
||
return configDoc; | ||
} | ||
|
||
public async Task<Stream> GetStreamAsync(string repositoryName, string digest, CancellationToken cancellationToken) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
HttpResponseMessage response = await GetAsync(repositoryName, digest, cancellationToken).ConfigureAwait(false); | ||
|
||
return await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
private async Task<HttpResponseMessage> GetAsync(string repositoryName, string digest, CancellationToken cancellationToken) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(_baseUri, $"/v2/{repositoryName}/blobs/{digest}")).AcceptManifestFormats(); | ||
HttpResponseMessage response = await _client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); | ||
response.EnsureSuccessStatusCode(); | ||
return response; | ||
} | ||
} |
Oops, something went wrong.