Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public static IResourceBuilder<YarpResource> AddYarp(
{
yarpBuilder.WithEnvironment(ctx =>
{
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var developerCertificateService = ctx.ExecutionContext.ServiceProvider.GetRequiredService<IDeveloperCertificateService>();
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
if (!developerCertificateService.SupportsContainerTrust)
{
// On systems without the ASP.NET DevCert updates introduced in .NET 10, YARP will not trust the cert used
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ internal static IEnumerable<NetworkIdentifier> GetSupportedNetworks(this IResour
Func<CertificateTrustScope, ReferenceExpression> certificateDirectoryPathsFactory,
CancellationToken cancellationToken = default)
{
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var developerCertificateService = executionContext.ServiceProvider.GetRequiredService<IDeveloperCertificateService>();
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var trustDevCert = developerCertificateService.TrustCertificate;

var certificates = new X509Certificate2Collection();
Expand Down
4 changes: 4 additions & 0 deletions src/Aspire.Hosting/Dcp/DcpExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ internal sealed partial class DcpExecutor : IDcpExecutor, IConsoleLogsService, I
private readonly CancellationTokenSource _shutdownCancellation = new();
private readonly DcpExecutorEvents _executorEvents;
private readonly Locations _locations;
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
private readonly IDeveloperCertificateService _developerCertificateService;
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
Comment on lines +73 to +75
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field declaration and constructor parameter both suppress the same warning. Consider placing the pragma at file scope to avoid duplicating the suppression for both the field (lines 73-75) and constructor parameter (lines 110-112).

Copilot uses AI. Check for mistakes.

private readonly DcpResourceState _resourceState;
private readonly ResourceSnapshotBuilder _snapshotBuilder;
Expand Down Expand Up @@ -105,7 +107,9 @@ public DcpExecutor(ILogger<DcpExecutor> logger,
DcpNameGenerator nameGenerator,
DcpExecutorEvents executorEvents,
Locations locations,
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
IDeveloperCertificateService developerCertificateService)
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
{
_distributedApplicationLogger = distributedApplicationLogger;
_kubernetesService = kubernetesService;
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/DeveloperCertificateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace Aspire.Hosting;

#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
internal class DeveloperCertificateService : IDeveloperCertificateService
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
{
private readonly Lazy<ImmutableList<X509Certificate2>> _certificates;
private readonly Lazy<bool> _supportsContainerTrust;
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/DistributedApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)

return new AspireStore(Path.Combine(aspireDir, ".aspire"));
});
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
_innerBuilder.Services.AddSingleton<IDeveloperCertificateService, DeveloperCertificateService>();
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

// Shared DCP things (even though DCP isn't used in 'publish' and 'inspect' mode
// we still honour the DCP options around container runtime selection.
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/IDeveloperCertificateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography.X509Certificates;

namespace Aspire.Hosting;

/// <summary>
/// Service that provides information about developer certificate trust capabilities.
/// </summary>
[Experimental("ASPIRECERTIFICATES001", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
public interface IDeveloperCertificateService
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,7 @@ private static DcpExecutor CreateAppExecutor(

var developerCertificateService = new TestDeveloperCertificateService(new List<X509Certificate2>(), false, false);

#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
return new DcpExecutor(
NullLogger<DcpExecutor>.Instance,
NullLogger<DistributedApplication>.Instance,
Expand All @@ -2043,6 +2044,7 @@ private static DcpExecutor CreateAppExecutor(
events ?? new DcpExecutorEvents(),
new Locations(),
developerCertificateService);
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}

private sealed class TestExecutableResource(string directory) : ExecutableResource("TestExecutable", "test", directory);
Expand Down
2 changes: 2 additions & 0 deletions tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ public async Task VerifyContainerIncludesExpectedDevCertificateConfiguration(boo
await app.StartAsync().DefaultTimeout(TestConstants.DefaultOrchestratorTestLongTimeout);

var s = app.Services.GetRequiredService<IKubernetesService>();
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var dc = app.Services.GetRequiredService<IDeveloperCertificateService>();
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var list = await s.ListAsync<Container>().DefaultTimeout(TestConstants.DefaultOrchestratorTestLongTimeout);

Assert.Collection(list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

namespace Aspire.Hosting.Tests.Utils;

#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
public sealed class TestDeveloperCertificateService(List<X509Certificate2> certificates, bool supportsContainerTrust, bool trustCertificate) : IDeveloperCertificateService
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
{
/// <inheritdoc />
public ImmutableList<X509Certificate2> Certificates { get; } = certificates.ToImmutableList();
Expand Down
8 changes: 8 additions & 0 deletions tests/Aspire.Hosting.Yarp.Tests/AddYarpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void VerifyYarpResourceWithTargetPort()
[InlineData(false)]
public async Task VerifyRunEnvVariablesAreSet(bool containerCertificateSupport)
{
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pragma warning disable could be placed at the file scope (after the using statements) rather than within individual test methods. This would reduce repetition across 5 test methods and make the code more maintainable. The experimental nature of IDeveloperCertificateService applies to the entire test file.

Copilot uses AI. Check for mistakes.
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Run);

// Report that developer certificates won't support container scenarios
Expand Down Expand Up @@ -57,6 +58,7 @@ public async Task VerifyRunEnvVariablesAreSet(bool containerCertificateSupport)
var value = Assert.Contains("YARP_UNSAFE_OLTP_CERT_ACCEPT_ANY_SERVER_CERTIFICATE", env);
Assert.Equal("true", value);
}
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}

[Fact]
Expand All @@ -78,6 +80,7 @@ public async Task VerifyPublishEnvVariablesAreSet()
[Fact]
public async Task VerifyWithStaticFilesAddsEnvironmentVariable()
{
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Run);

// Yarp requires an IDeveloperCertificateService in run mode when building it's environment variables.
Expand All @@ -94,11 +97,13 @@ public async Task VerifyWithStaticFilesAddsEnvironmentVariable()

var value = Assert.Contains("YARP_ENABLE_STATIC_FILES", env);
Assert.Equal("true", value);
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}

[Fact]
public async Task VerifyWithStaticFilesWorksInPublishOperation()
{
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);

// Yarp requires an IDeveloperCertificateService in run mode when building it's environment variables.
Expand All @@ -114,11 +119,13 @@ public async Task VerifyWithStaticFilesWorksInPublishOperation()

var value = Assert.Contains("YARP_ENABLE_STATIC_FILES", env);
Assert.Equal("true", value);
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}

[Fact]
public async Task VerifyWithStaticFilesBindMountAddsEnvironmentVariable()
{
#pragma warning disable ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Run);

// Yarp requires an IDeveloperCertificateService in run mode when building it's environment variables.
Expand All @@ -137,6 +144,7 @@ public async Task VerifyWithStaticFilesBindMountAddsEnvironmentVariable()

var value = Assert.Contains("YARP_ENABLE_STATIC_FILES", env);
Assert.Equal("true", value);
#pragma warning restore ASPIRECERTIFICATES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}

[Fact]
Expand Down
Loading