Skip to content

Commit

Permalink
Merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsplaisted committed Jun 30, 2023
2 parents 2f3650c + d4d8423 commit bfee8d8
Show file tree
Hide file tree
Showing 92 changed files with 1,570 additions and 2,744 deletions.
2 changes: 2 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<!-- End: Package sources from dotnet-runtime -->
<!-- Begin: Package sources from dotnet-templating -->
<add key="darc-pub-dotnet-templating-1aba81f" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-templating-1aba81f2/nuget/v3/index.json" />
<add key="darc-pub-dotnet-templating-1aba81f-8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-templating-1aba81f2-8/nuget/v3/index.json" />
<add key="darc-pub-dotnet-templating-1aba81f-7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-templating-1aba81f2-7/nuget/v3/index.json" />
<add key="darc-pub-dotnet-templating-1aba81f-6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-templating-1aba81f2-6/nuget/v3/index.json" />
<add key="darc-pub-dotnet-templating-1aba81f-5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-templating-1aba81f2-5/nuget/v3/index.json" />
<add key="darc-pub-dotnet-templating-1aba81f-4" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-templating-1aba81f2-4/nuget/v3/index.json" />
Expand Down
4 changes: 4 additions & 0 deletions build/RunTestsOnHelix.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ set DOTNET_CLI_HOME=%TestExecutionDirectory%\.dotnet
mkdir %TestExecutionDirectory%
robocopy %HELIX_CORRELATION_PAYLOAD%\t\TestExecutionDirectoryFiles %TestExecutionDirectory% /s

set DOTNET_SDK_TEST_EXECUTION_DIRECTORY=%TestExecutionDirectory%
set DOTNET_SDK_TEST_MSBUILDSDKRESOLVER_FOLDER=%HELIX_CORRELATION_PAYLOAD%\r
set DOTNET_SDK_TEST_ASSETS_DIRECTORY=%TestExecutionDirectory%\assets

REM call dotnet new so the first run message doesn't interfere with the first test
dotnet new --debug:ephemeral-hive
REM avoid potetial concurrency issues when nuget is creating nuget.config
Expand Down
4 changes: 4 additions & 0 deletions build/RunTestsOnHelix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ mkdir $TestExecutionDirectory
export DOTNET_CLI_HOME=$TestExecutionDirectory/.dotnet
cp -a $HELIX_CORRELATION_PAYLOAD/t/TestExecutionDirectoryFiles/. $TestExecutionDirectory/

export DOTNET_SDK_TEST_EXECUTION_DIRECTORY=$TestExecutionDirectory
export DOTNET_SDK_TEST_MSBUILDSDKRESOLVER_FOLDER=$HELIX_CORRELATION_PAYLOAD/r
export DOTNET_SDK_TEST_ASSETS_DIRECTORY=$TestExecutionDirectory/Assets

# call dotnet new so the first run message doesn't interfere with the first test
dotnet new --debug:ephemeral-hive
# We downloaded a special zip of files to the .nuget folder so add that as a source
Expand Down
172 changes: 86 additions & 86 deletions eng/Version.Details.xml

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/runtime -->
<MicrosoftNETCoreAppRefPackageVersion>7.0.7</MicrosoftNETCoreAppRefPackageVersion>
<VSRedistCommonNetCoreSharedFrameworkx6470PackageVersion>7.0.7-servicing.23274.4</VSRedistCommonNetCoreSharedFrameworkx6470PackageVersion>
<MicrosoftNETCoreAppRuntimewinx64PackageVersion>7.0.7</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
<MicrosoftNETCoreAppRefPackageVersion>7.0.8</MicrosoftNETCoreAppRefPackageVersion>
<VSRedistCommonNetCoreSharedFrameworkx6470PackageVersion>7.0.8-servicing.23318.7</VSRedistCommonNetCoreSharedFrameworkx6470PackageVersion>
<MicrosoftNETCoreAppRuntimewinx64PackageVersion>7.0.8</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
<MicrosoftNETCoreAppRuntimePackageVersion>$(MicrosoftNETCoreAppRuntimewinx64PackageVersion)</MicrosoftNETCoreAppRuntimePackageVersion>
<MicrosoftExtensionsDependencyModelPackageVersion>7.0.0</MicrosoftExtensionsDependencyModelPackageVersion>
<MicrosoftNETCoreDotNetHostResolverPackageVersion>7.0.7</MicrosoftNETCoreDotNetHostResolverPackageVersion>
<MicrosoftNETHostModelVersion>7.0.7-servicing.23274.4</MicrosoftNETHostModelVersion>
<MicrosoftNETCoreDotNetHostResolverPackageVersion>7.0.8</MicrosoftNETCoreDotNetHostResolverPackageVersion>
<MicrosoftNETHostModelVersion>7.0.8-servicing.23318.7</MicrosoftNETHostModelVersion>
<MicrosoftExtensionsFileSystemGlobbingPackageVersion>6.0.0</MicrosoftExtensionsFileSystemGlobbingPackageVersion>
<MicrosoftExtensionsDependencyModelVersion>$(MicrosoftExtensionsDependencyModelPackageVersion)</MicrosoftExtensionsDependencyModelVersion>
<MicrosoftExtensionsLoggingConsoleVersion>6.0.0</MicrosoftExtensionsLoggingConsoleVersion>
Expand All @@ -65,7 +65,7 @@
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/nuget/nuget.client -->
<NuGetBuildTasksPackageVersion>6.7.0-rc.106</NuGetBuildTasksPackageVersion>
<NuGetBuildTasksPackageVersion>6.7.0-rc.111</NuGetBuildTasksPackageVersion>
<NuGetBuildTasksConsolePackageVersion>$(NuGetBuildTasksPackageVersion)</NuGetBuildTasksConsolePackageVersion>
<NuGetLocalizationPackageVersion>6.0.0-rc.278</NuGetLocalizationPackageVersion>
<NuGetBuildTasksPackPackageVersion>$(NuGetBuildTasksPackageVersion)</NuGetBuildTasksPackPackageVersion>
Expand Down Expand Up @@ -96,7 +96,7 @@
<SystemCodeDomPackageVersion>7.0.0</SystemCodeDomPackageVersion>
<SystemTextEncodingCodePagesPackageVersion>7.0.0</SystemTextEncodingCodePagesPackageVersion>
<SystemResourcesExtensionsPackageVersion>7.0.0</SystemResourcesExtensionsPackageVersion>
<MicrosoftDotNetILCompilerPackageVersion>7.0.7</MicrosoftDotNetILCompilerPackageVersion>
<MicrosoftDotNetILCompilerPackageVersion>7.0.8</MicrosoftDotNetILCompilerPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/format -->
Expand Down Expand Up @@ -140,38 +140,38 @@
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/Microsoft/visualfsharp -->
<MicrosoftFSharpCompilerPackageVersion>12.7.0-beta.23323.1</MicrosoftFSharpCompilerPackageVersion>
<MicrosoftFSharpCompilerPackageVersion>12.7.0-beta.23328.4</MicrosoftFSharpCompilerPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/roslyn -->
<MicrosoftNetCompilersToolsetPackageVersion>4.7.0-3.23326.8</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCodeAnalysisPackageVersion>4.7.0-3.23326.8</MicrosoftCodeAnalysisPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.7.0-3.23326.8</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>4.7.0-3.23326.8</MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.7.0-3.23326.8</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.7.0-3.23326.8</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.7.0-3.23326.8</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.7.0-3.23329.1</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCodeAnalysisPackageVersion>4.7.0-3.23329.1</MicrosoftCodeAnalysisPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.7.0-3.23329.1</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>4.7.0-3.23329.1</MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.7.0-3.23329.1</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.7.0-3.23329.1</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.7.0-3.23329.1</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
<MicrosoftNetCompilersToolsetVersion>$(MicrosoftNetCompilersToolsetPackageVersion)</MicrosoftNetCompilersToolsetVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/aspnet/AspNetCore -->
<MicrosoftAspNetCoreDeveloperCertificatesXPlatPackageVersion>7.0.7-servicing.23274.8</MicrosoftAspNetCoreDeveloperCertificatesXPlatPackageVersion>
<MicrosoftAspNetCoreComponentsSdkAnalyzersPackageVersion>7.0.7-servicing.23274.8</MicrosoftAspNetCoreComponentsSdkAnalyzersPackageVersion>
<MicrosoftAspNetCoreMvcAnalyzersPackageVersion>7.0.7-servicing.23274.8</MicrosoftAspNetCoreMvcAnalyzersPackageVersion>
<MicrosoftAspNetCoreMvcApiAnalyzersPackageVersion>7.0.7-servicing.23274.8</MicrosoftAspNetCoreMvcApiAnalyzersPackageVersion>
<MicrosoftAspNetCoreAnalyzersPackageVersion>7.0.7-servicing.23274.8</MicrosoftAspNetCoreAnalyzersPackageVersion>
<MicrosoftAspNetCoreTestHostPackageVersion>7.0.7</MicrosoftAspNetCoreTestHostPackageVersion>
<MicrosoftAspNetCoreDeveloperCertificatesXPlatPackageVersion>7.0.8-servicing.23318.7</MicrosoftAspNetCoreDeveloperCertificatesXPlatPackageVersion>
<MicrosoftAspNetCoreComponentsSdkAnalyzersPackageVersion>7.0.8-servicing.23318.7</MicrosoftAspNetCoreComponentsSdkAnalyzersPackageVersion>
<MicrosoftAspNetCoreMvcAnalyzersPackageVersion>7.0.8-servicing.23318.7</MicrosoftAspNetCoreMvcAnalyzersPackageVersion>
<MicrosoftAspNetCoreMvcApiAnalyzersPackageVersion>7.0.8-servicing.23318.7</MicrosoftAspNetCoreMvcApiAnalyzersPackageVersion>
<MicrosoftAspNetCoreAnalyzersPackageVersion>7.0.8-servicing.23318.7</MicrosoftAspNetCoreAnalyzersPackageVersion>
<MicrosoftAspNetCoreTestHostPackageVersion>7.0.8</MicrosoftAspNetCoreTestHostPackageVersion>
</PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/razor -->
<PropertyGroup>
<MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>7.0.0-preview.23326.2</MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>
<MicrosoftCodeAnalysisRazorToolingInternalVersion>7.0.0-preview.23326.2</MicrosoftCodeAnalysisRazorToolingInternalVersion>
<MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>7.0.0-preview.23330.1</MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>
<MicrosoftCodeAnalysisRazorToolingInternalVersion>7.0.0-preview.23330.1</MicrosoftCodeAnalysisRazorToolingInternalVersion>
<MicrosoftAspNetCoreRazorSourceGeneratorToolingInternalPackageVersion>7.0.0-preview.23167.3</MicrosoftAspNetCoreRazorSourceGeneratorToolingInternalPackageVersion>
<MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>7.0.0-preview.23326.2</MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>
<MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>7.0.0-preview.23330.1</MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/wpf -->
<MicrosoftNETSdkWindowsDesktopPackageVersion>7.0.7-servicing.23274.5</MicrosoftNETSdkWindowsDesktopPackageVersion>
<MicrosoftNETSdkWindowsDesktopPackageVersion>7.0.8-servicing.23318.3</MicrosoftNETSdkWindowsDesktopPackageVersion>
</PropertyGroup>
<PropertyGroup Label="Manually updated">
<!-- Dependencies from https://github.com/microsoft/MSBuildLocator -->
Expand All @@ -191,7 +191,7 @@
<FluentAssertionsVersion>6.10.0</FluentAssertionsVersion>
<FluentAssertionsJsonVersion>6.1.0</FluentAssertionsJsonVersion>
<MicrosoftDotNetXUnitExtensionsVersion>7.0.0-beta.23316.4</MicrosoftDotNetXUnitExtensionsVersion>
<MoqPackageVersion>4.8.2</MoqPackageVersion>
<MoqPackageVersion>4.18.4</MoqPackageVersion>
<MicrosoftDotNetInstallerWindowsSecurityTestDataPackageVersion>6.0.0-beta.22262.1</MicrosoftDotNetInstallerWindowsSecurityTestDataPackageVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/xlf/CommonLocalizableStrings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Si usa zsh, puede agregarlo a su perfil mediante la ejecución del comando sigui

cat &lt;&lt; \EOF &gt;&gt; ~/.zprofile
# Agregue las herramientas del SDK de .NET Core
exporte PATH="$PATH:{0}"
export PATH="$PATH:{0}"
EOF

Y ejecute "zsh -l" para que esté disponible para la sesión actual.
Expand Down
12 changes: 6 additions & 6 deletions src/Cli/dotnet/xlf/CommonLocalizableStrings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export PATH="$PATH:{0}"

cat &lt;&lt; \EOF &gt;&gt; ~/.bash_profile
# 添加 .NET Core SDK 工具
导出 PATH="$PATH:{0}"
export PATH="$PATH:{0}"
EOF

可运行以下命令将其添加到当前会话:

导出 PATH ="$PATH:{0}"
export PATH="$PATH:{0}"
</target>
<note />
</trans-unit>
Expand All @@ -99,14 +99,14 @@ export PATH="$PATH:{0}"

cat &lt;&lt; \EOF &gt;&gt; ~/.zprofile
# 添加 .NET Core SDK 工具
导出 PATH="$PATH:{0}"
export PATH="$PATH:{0}"
EOF

并运行 `zsh -l` 使其用于当前会话。

只可通过运行以下命令将其添加到当前会话:

导出 PATH="$PATH:{0}"
export PATH="$PATH:{0}"
</target>
<note />
</trans-unit>
Expand Down Expand Up @@ -864,12 +864,12 @@ export PATH="$PATH:{0}"

cat &lt;&lt; \EOF &gt;&gt; ~/.bash_profile
# 添加 .NET Core SDK 工具
导出 PATH="$PATH:{0}"
export PATH="$PATH:{0}"
EOF

可运行以下命令将其添加到当前会话:

导出 PATH ="$PATH:{0}"
export PATH="$PATH:{0}"
</target>
<note />
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public static async Task<int> ContainerizeAsync(
builtImage,
sourceImageReference,
destinationImageReference,
message => Console.WriteLine($"Containerize: {message}"),
cancellationToken)).ConfigureAwait(false);
logger.LogInformation(Strings.ContainerBuilder_ImageUploadedToRegistry, destinationImageReference.RepositoryAndTag, destinationImageReference.Registry.RegistryName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public static class ContainerHelpers

internal const string HostObjectPass = "SDK_CONTAINER_REGISTRY_PWORD";

internal const string ForceChunkedUploadEnabled = "SDK_CONTAINER_DEBUG_REGISTRY_FORCE_CHUNKED_UPLOAD";
internal const string ChunkedUploadSizeBytes = "SDK_CONTAINER_REGISTRY_CHUNKED_UPLOAD_SIZE_BYTES";

internal const string ParallelUploadEnabled = "SDK_CONTAINER_REGISTRY_PARALLEL_UPLOAD";

/// <summary>
/// Matches an environment variable name - must start with a letter or underscore, and can only contain letters, numbers, and underscores.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Containers/Microsoft.NET.Build.Containers/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
[assembly: InternalsVisibleTo("containerize, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo("Microsoft.NET.Build.Containers.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo("Microsoft.NET.Build.Containers.IntegrationTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
// moq unit tests
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
33 changes: 18 additions & 15 deletions src/Containers/Microsoft.NET.Build.Containers/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Microsoft.NET.Build.Containers;

internal record struct Layer
internal class Layer
{
// NOTE: The SID string below was created using the following snippet. As the code is Windows only we keep the constant
// private static string CreateUserOwnerAndGroupSID()
Expand All @@ -30,17 +30,24 @@ internal record struct Layer

private const string BuiltinUsersSecurityDescriptor = "AQAAgBQAAAAkAAAAAAAAAAAAAAABAgAAAAAABSAAAAAhAgAAAQIAAAAAAAUgAAAAIQIAAA==";

public Descriptor Descriptor { get; private set; }
public virtual Descriptor Descriptor { get; }

public string BackingFile { get; private set; }
public string BackingFile { get; }

internal Layer()
{
Descriptor = new Descriptor();
BackingFile = "";
}
internal Layer(string backingFile, Descriptor descriptor)
{
BackingFile = backingFile;
Descriptor = descriptor;
}

public static Layer FromDescriptor(Descriptor descriptor)
{
return new()
{
BackingFile = ContentStore.PathForDescriptor(descriptor),
Descriptor = descriptor
};
return new(ContentStore.PathForDescriptor(descriptor), descriptor);
}

public static Layer FromDirectory(string directory, string containerPath, bool isWindowsLayer)
Expand Down Expand Up @@ -183,15 +190,11 @@ void EnsureDirectoryEntries(TarWriter tar,

File.Move(tempTarballPath, storedContent, overwrite: true);

Layer l = new()
{
Descriptor = descriptor,
BackingFile = storedContent,
};

return l;
return new(storedContent, descriptor);
}

internal virtual Stream OpenBackingFile() => File.OpenRead(BackingFile);

private readonly static char[] PathSeparators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };

/// <summary>
Expand Down
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;
}
}
Loading

0 comments on commit bfee8d8

Please sign in to comment.