Skip to content

Conversation

@Alirexaa
Copy link
Contributor

@Alirexaa Alirexaa commented Mar 31, 2025

Description

This pull request introduces several enhancements and new features for PostgreSQL, Redis, and SQL Server resource builders, along with some test updates. The key changes include adding methods to configure passwords, usernames, and host ports for these resources, as well as updates to the corresponding tests to ensure these configurations are correctly applied.

Enhancements to resource builders:

  • Added methods to configure passwords, usernames, and host ports for PostgreSQL resources in PostgresBuilderExtensions.cs.
  • Added methods to configure passwords and host ports for Redis resources in RedisBuilderExtensions.cs.
  • Added methods to configure passwords and host ports for SQL Server resources in SqlServerBuilderExtensions.cs.

Internal resource updates:

  • Updated PostgresServerResource.cs to include methods for setting passwords and usernames.
  • Updated RedisResource.cs to include a method for setting passwords.
  • Updated SqlServerServerResource.cs to include a method for setting passwords.

Test updates:

  • Added new tests in AzurePostgresExtensionsTests.cs to verify the correct configuration of usernames and passwords for PostgreSQL resources.
  • Added new tests in AzureRedisExtensionsTests.cs to verify the correct configuration of host and password for Redis resources.
  • Updated AzureSqlExtensionsTests.cs to include necessary imports for new tests.

Miscellaneous:

  • Added a new suppression entry for a fake username in .config/CredScanSuppressions.json.
  • Introduced a constant for the Redis password environment variable in RedisBuilderExtensions.cs.

Fixes #7918

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 31, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 31, 2025
@Alirexaa Alirexaa marked this pull request as ready for review March 31, 2025 19:21
@Copilot Copilot AI review requested due to automatic review settings March 31, 2025 19:21
@Alirexaa Alirexaa closed this Mar 31, 2025
@Alirexaa Alirexaa reopened this Mar 31, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the SQL Server container configuration by adding a new options parameter for specifying the port and password, and extends testing to verify these changes.

  • Adds a new parameter, configureOptions, to the RunAsContainer method.
  • Introduces the RunAsContainerOptions class to encapsulate port and password settings.
  • Adds unit tests to verify that the SQL Server container is properly configured.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
tests/Aspire.Hosting.Azure.Tests/AzureSqlExtensionsTests.cs Added unit tests to validate password and port configuration for containerized SQL Server
src/Aspire.Hosting.Azure.Sql/RunAsContainerOptions.cs New options class for configuring SQL Server container settings
src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs Extended the RunAsContainer method to support configuration via RunAsContainerOptions
Files not reviewed (1)
  • src/Aspire.Hosting.Azure.Sql/CompatibilitySuppressions.xml: Language not supported
Comments suppressed due to low confidence (1)

src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs:153

  • [nitpick] The parameters 'configureContainer' and 'configureOptions' are similar in naming, which could cause confusion. Consider renaming 'configureOptions' to 'configureContainerOptions' for improved clarity.
public static IResourceBuilder<AzureSqlServerResource> RunAsContainer(this IResourceBuilder<AzureSqlServerResource> builder, Action<IResourceBuilder<SqlServerServerResource>>? configureContainer = null, Action<RunAsContainerOptions>? configureOptions = null)

@joperezr
Copy link
Member

joperezr commented Apr 1, 2025

cc: @eerhardt @sebastienros

@Alirexaa Alirexaa force-pushed the azure-sql-configure-run-as-container branch from 347c77b to f462b63 Compare April 1, 2025 23:04
@eerhardt
Copy link
Member

eerhardt commented Apr 2, 2025

@Alirexaa - check out the discussion here: #6886 (comment)

Basically, I think a better API approach is:

var somePassword = ...;

var sql1 = builder.AddAzureSqlServer("sql1")
                  .RunAsContainer(c =>
                  {
                      c.WithHostPort(5555)
                          .WithPassword(somePassword);
                  });

@Alirexaa
Copy link
Contributor Author

Alirexaa commented Apr 2, 2025

OK @eerhardt, I will update the PR to reflect your approach.

@Alirexaa
Copy link
Contributor Author

Alirexaa commented Apr 2, 2025

@eerhardt, Some adjustments are needed, but please take a look. After your feedback, I will add more tests and XML docs.

@Alirexaa Alirexaa changed the title Provide port and password for AzureSql RunAsContainer Add ability to configure Port and Password for Redis and Postgres and SqlServer when they configured to run by 'RunAsContainer' Apr 2, 2025
@Alirexaa Alirexaa changed the title Add ability to configure Port and Password for Redis and Postgres and SqlServer when they configured to run by 'RunAsContainer' Add ability to configure Port and Password for Redis and Postgres and SqlServer when they configured to run by RunAsContainer Apr 2, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the resource builders for PostgreSQL, Redis, and SQL Server by adding configuration options for host port and password when running as a container. The changes include new extension methods and resource APIs to set passwords and host ports, as well as new and updated tests to assert that these settings are correctly applied.

  • Added WithPassword and WithHostPort extension methods for SQL Server, Redis, and PostgreSQL resources.
  • Updated resource classes (e.g., SqlServerServerResource, RedisResource, PostgresServerResource) to store password parameters.
  • Introduced tests for both containerized Azure and non-Azure resources to verify connection string construction.

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Aspire.Hosting.SqlServer.Tests/AddSqlServerTests.cs New tests for SQL Server host port and password configuration.
tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs New tests to verify Redis host port and password setup.
tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs Added tests for PostgreSQL host port, password, and username configurations.
tests/Aspire.Hosting.Azure.Tests/AzureSqlExtensionsTests.cs Added tests for containerized SQL Server resources.
tests/Aspire.Hosting.Azure.Tests/AzureRedisExtensionsTests.cs New tests for Azure Redis resource run-as-container configuration.
tests/Aspire.Hosting.Azure.Tests/AzurePostgresExtensionsTests.cs New tests for Azure Postgres flexible server settings.
src/Aspire.Hosting.SqlServer/SqlServerServerResource.cs Updated to support password setting with a private setter and new API.
src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs Added WithPassword and WithHostPort methods for SQL Server resource.
src/Aspire.Hosting.Redis/RedisResource.cs Updated to include a SetPassword method with a private setter.
src/Aspire.Hosting.Redis/RedisBuilderExtensions.cs Added WithPassword and WithHostPort methods for Redis resource.
src/Aspire.Hosting.PostgreSQL/PostgresServerResource.cs Added SetPassword and SetUserName methods to support new configuration.
src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs Added WithPassword, WithUserName, and WithHostPort methods for Postgres.
Files not reviewed (1)
  • .config/CredScanSuppressions.json: Language not supported

@eerhardt eerhardt added area-integrations Issues pertaining to Aspire Integrations packages and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 2, 2025
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

This is looking pretty good. Thanks @Alirexaa!

Just a few minor comments and then I think this can be merged.

"_justification": "Legitimate UT certificate file with private key, from dotnet/aspnetcore"
},
{
"placeholder": "user1",
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary?

cc @danmoseley @sebastienros

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure.

{
ArgumentNullException.ThrowIfNull(password);

PasswordParameter = password;
Copy link
Member

Choose a reason for hiding this comment

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

These properties are publically settable. We can remove these methods and just set the property.

Comment on lines 439 to 442
return builder.WithEnvironment(context =>
{
context.EnvironmentVariables[PasswordEnvVarName] = builder.Resource.PasswordParameter;
});
Copy link
Member

@eerhardt eerhardt Apr 10, 2025

Choose a reason for hiding this comment

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

We shouldn't need this because this code grabs the parameters from the resource, so it will continue to work if we set the parmaeter correctly.

.WithEnvironment(context =>
{
context.EnvironmentVariables[UserEnvVarName] = postgresServer.UserNameReference;
context.EnvironmentVariables[PasswordEnvVarName] = postgresServer.PasswordParameter;

(repeated elsewhere) #Closed

var password = "p@ssw0rd1";
var pass = builder.AddParameter("pass", password);
var redis = builder.
AddRedis("myRedis")
Copy link
Member

Choose a reason for hiding this comment

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

There are various code cleanups scattered around. We typically put the . on the trailing line, with the method being invoked.

Along with this, there are unnecessary blank lines and other whitespace issues. Can you clean these up?

Alirexaa and others added 2 commits April 11, 2025 16:32
Revert unnecessary changes
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the great work here, @Alirexaa!

@eerhardt eerhardt enabled auto-merge (squash) April 14, 2025 15:21
@eerhardt eerhardt merged commit 6ff4a88 into dotnet:main Apr 14, 2025
174 checks passed
@Alirexaa Alirexaa deleted the azure-sql-configure-run-as-container branch April 14, 2025 15:42
@github-actions github-actions bot locked and limited conversation to collaborators May 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow passing password and port to AddSqlServer via RunAsContainer()

4 participants