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

Support callback, custom config key and publishing for parameters. #5586

Merged
merged 14 commits into from
Sep 20, 2024

Conversation

davidebbo
Copy link
Contributor

@davidebbo davidebbo commented Sep 7, 2024

Description

See #4429 for details.

Fixes #4429

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected to support new manifest value
  • 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?
    • Yes
      • Link to aspire-docs issue: none yet
    • No
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 Sep 7, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 7, 2024
@mitchdenny
Copy link
Member

mitchdenny commented Sep 8, 2024

Any thoughts on supporting a Func<IServiceProvder, Task> variant? Although just looking at it now I am not sure how we do it without breaking API. I guess if someone really wanted to asynchrously load a parameter value they could by using a config extensibility and then referencing a config value.

@mitchdenny
Copy link
Member

Thanks once again for the contribution @davidebbo

@davidebbo
Copy link
Contributor Author

@mitchdenny per discussion with @davidfowl, we decided not to tackle async at this time, though this could be a future thing (it does look hard!).

Note that per #4429 (comment) and discord chat, we'll be making some design changes for publishing the value, so I'll be evolving the PR.

@davidfowl
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

"inputs": {
"value": {
"type": "string",
"default": {
Copy link
Member

Choose a reason for hiding this comment

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

@mitchdenny This is new schema for parameters to specify a default value. We should update the schema and file an issue on azd to implement this.

@vhvb1989 Thoughts on implementing this idea of no prompting for parameters with defaults? Or being able to suppress them somehow?

Copy link
Contributor Author

@davidebbo davidebbo Sep 10, 2024

Choose a reason for hiding this comment

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

@vhvb1989 Thoughts on implementing this idea of no prompting for parameters with defaults? Or being able to suppress them somehow?

If it's a 'default', there needs to be a way to override them. Maybe there are two modes (e.g. controlled by switches):

  1. Use all manifest defaults without prompting
  2. Prompt, but prefill the field with the manifest default

Choose a reason for hiding this comment

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

FYI, azd suports a generate field in default, like

image

Azd uses the gereate config to produce the value instead of prompt. If you need a static default value, we could add a rule to the generate config to just use the provided value

@eerhardt

When we added support for this, we considered a case where azd could ask forlk if they wanted to auto-generate the value (based on the rules) or enter a value manually. This is supported by azd already (just not mapped to any configuration from the Aspire Manifest).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me, it feels a little strange to have this in generate (because there is no generation), which is why I went with an alternative value property, e.g.

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

Either way, whoever owns the aspire manifest schema should decide where to put that. If we want it under generate that's easy to do.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that generate is strange. I like the above proposal of having a "default" section.

Copy link
Member

Choose a reason for hiding this comment

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

Yep

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I pushed the schema change. I also added test coverage for "generate", as it was missing. @mitchdenny PTAL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mitchdenny Also, how does the schema make its way from this repo to https://github.com/dotnet/dotnet/blob/main/src/aspire/src/Schema/aspire-8.0.json? Automatic or we need to push it?

Copy link
Member

Choose a reason for hiding this comment

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

Manually I think

Copy link
Member

Choose a reason for hiding this comment

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

Yeah all manual.

@davidfowl
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidfowl davidfowl merged commit 4d80745 into dotnet:main Sep 20, 2024
11 checks passed
@davidfowl
Copy link
Member

cc @vhvb1989 @ellismg

@davidfowl
Copy link
Member

Filed Azure/azure-dev#4359

@vhvb1989
Copy link

@davidebbo @davidfowl @mitchdenny is it safe to asume that a default.value will never be set as secure ?, like:

"param-with-value": {
      "type": "parameter.v0",
      "value": "{param-with-value.inputs.value}",
      "inputs": {
        "value": {
          "type": "string",
          "secret": true,
          "default":{
            "value": "default value for param"
          }
        }
      }
    },

See the "secret": true, there.

I am working on making azd to fail on this case as per: https://learn.microsoft.com/azure/azure-resource-manager/bicep/linter-rule-secure-parameter-default

image

But I am wondering if the AppHost is even allowing this or not? (maybe is blocked in AppHost so I don't even need to worry)?

@davidebbo
Copy link
Contributor Author

davidebbo commented Sep 24, 2024

@vhvb1989 we do not block it today, but I agree that we should. So I think we should allow:

var foo = builder.AddParameter("foo", value: "somesecret", secret: true);

as this only uses the value at runtime, but not:

var foo = builder.AddParameter("foo", value: "somesecret", publishValueAsDefault: true, secret: true);

which results in having the secret in the manifest.

@davidfowl @mitchdenny do you agree? If so, I can make a follow-up change to prevent this. e.g. an error like the 'publishValueAsDefault' and 'secret' flags are mutually exclusive, to prevent saving a secret to the manifest

@davidebbo
Copy link
Contributor Author

I sent #5891 to make this change.

@davidebbo
Copy link
Contributor Author

@vhvb1989 This is now blocked in AppHost, so you should not encounter this unless people mess with their manifest by hand,

@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication 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.

AddParameter overloads that supports providing a value
4 participants