Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make username parameter always be injected. #4102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mitchdenny
Copy link
Member

@mitchdenny mitchdenny commented May 7, 2024

Fixes #4100 and #4099

This PR does a few things:

  1. Changes the PgAdmin config writer hook to use the password from UserNameParameter on the Postgres server resource.
  2. Changes the UserNameParameter on the postgres server resource to be non-nullable and adjust in the constructor as well.

The reason for this change is that if you want to use the Postgres database resource from a container that is not built around .NET, the connection string format that the resource exposes won't necessarily be in the format that you want. For that reason you want to be able to get at the username and password parameters and know that they are always there. The password parameter is fine, but the fact that the username parameter is optional is problematic and makes consuming code more complex.

This represents a breaking change ... see unshipped API diff.

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label May 7, 2024
@mitchdenny mitchdenny self-assigned this May 7, 2024
@mitchdenny mitchdenny added this to the 8.1 milestone May 7, 2024
@mitchdenny mitchdenny added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label May 7, 2024
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.

I think this will cause azd to always prompt for a user name now.

@@ -17,7 +17,7 @@ public class PostgresServerResource : ContainerResource, IResourceWithConnection
/// <param name="name">The name of the resource.</param>
/// <param name="userName">A parameter that contains the PostgreSQL server user name, or <see langword="null"/> to use a default value.</param>
/// <param name="password">A parameter that contains the PostgreSQL server password.</param>
public PostgresServerResource(string name, ParameterResource? userName, ParameterResource password) : base(name)
public PostgresServerResource(string name, ParameterResource userName, ParameterResource password) : base(name)
Copy link
Member

Choose a reason for hiding this comment

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

We should be consistent across all resources that take a user name.

public RabbitMQServerResource(string name, ParameterResource? userName, ParameterResource password) : base(name)

@@ -17,7 +17,7 @@ public class PostgresServerResource : ContainerResource, IResourceWithConnection
/// <param name="name">The name of the resource.</param>
/// <param name="userName">A parameter that contains the PostgreSQL server user name, or <see langword="null"/> to use a default value.</param>
Copy link
Member

Choose a reason for hiding this comment

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

This doc should be updated.

@@ -34,7 +34,7 @@ public PostgresServerResource(string name, ParameterResource? userName, Paramete
/// <summary>
/// Gets the parameter that contains the PostgreSQL server user name.
/// </summary>
public ParameterResource? UserNameParameter { get; }
public ParameterResource UserNameParameter { get; }

internal ReferenceExpression UserNameReference =>
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed now that the UserNameParameter can't be null.

@@ -17,7 +17,7 @@ public class PostgresServerResource : ContainerResource, IResourceWithConnection
/// <param name="name">The name of the resource.</param>
Copy link
Member

Choose a reason for hiding this comment

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

Should be able to remove line 12:

private const string DefaultUserName = "postgres";

Comment on lines +724 to +732
"postgres-username": {
"type": "parameter.v0",
"value": "{postgres-username.inputs.value}",
"inputs": {
"value": {
"type": "string"
}
}
},
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that users will always be prompted for a user name when they deploy via azd?

Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to have the default value be a constant?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that was ever implemented in azd, or Aspire.

The way we do it today is we just put the constant directly where it needs to go. i.e. it isn't a "parameter".

Copy link
Member

Choose a reason for hiding this comment

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

8.1

Copy link
Member Author

Choose a reason for hiding this comment

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

What we could do is expand the the manifest so you can do this:

{
  "inputs": {
    "value": {
      "type": "string",
      "default": {
        "value": "postgres"
      }
    }
  }
}

This would be a trigger for an aspire-8.1.json schema. If value is provided then generate isn't allowed. azd would prompt and show the default value (the user just hits ENTER). If it is secret it wouldn't show the value but indicate somehow that it should accept the default.

/cc @vhvb1989

Copy link
Member Author

Choose a reason for hiding this comment

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

So do we have enough to decide what we want to go ahead with this? We would need:

  1. A change to AZD to support using default values if they are present (in accordance with the schema above).
  2. A change to our schema (introduce an 8.1 version of the schema)
  3. Introduce the necessary API changes to allow for setting the default value.

Copy link
Member

Choose a reason for hiding this comment

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

Can we make this change in a non breaking way that doesn't require a schema update? AZD can prompt in older versions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well the value field is additive, so we can add it without rev'ing the schema. And tools use use the value if they understand it. We might be able to get away with that?

Copy link
Member

Choose a reason for hiding this comment

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

Added an API proposal with the manifest schema change above #4429

Copy link
Member

Choose a reason for hiding this comment

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

I now think we shouldn't version the schema here. On an older azd you'll get the prompting behavior.

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WithPgAdmin does not use username parameter value when provided.
4 participants