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

Introduce WithEnvironment overload for custom connection string keys #3002 #3239

Merged
merged 10 commits into from
Mar 29, 2024

Conversation

danikishin
Copy link
Contributor

@danikishin danikishin commented Mar 28, 2024

This PR introduces a new overload for WithEnvironment method in the ResourceBuilderExtensions class, which allows setting the connection string of a resource under a custom environment variable name.

Changes

  • Added WithEnvironment overload to accept a custom environment variable name.

Background

The issue #3002 describes a scenario where existing projects do not use the 'ConnectionStrings__' prefix for environment variables.

Example Usage

builder.AddProject<Projects.Web>("web").WithEnvironment("CustomEnvVarName", redis);
 ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/aspire/pull/3239)

Allow custom env var names for connection strings

Introduce a new WithEnvironment overload in ResourceBuilderExtensions that
enables setting a connection string under a custom environment variable name.

Fixes dotnet#3002.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 28, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 28, 2024
@danikishin
Copy link
Contributor Author

@danikishin please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

@dotnet-policy-service agree

@davidfowl
Copy link
Member

This should have tests. Look at the existing WithEnvironment tests

@davidfowl davidfowl merged commit c7d9933 into dotnet:main Mar 29, 2024
8 checks passed
@davidfowl davidfowl added this to the 8.1 milestone Mar 29, 2024
@mitchdenny
Copy link
Member

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/aspire/actions/runs/8626583440

Copy link
Contributor

@mitchdenny backporting to release/8.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Update ResourceBuilderExtensions.cs
Applying: Update ResourceBuilderExtensions.cs
Applying: Update ResourceBuilderExtensions.cs
Applying: Update src/Aspire.Hosting/ResourceBuilderExtensions.cs
Applying: Remove async keyword
error: sha1 information is lacking or useless (src/Aspire.Hosting/ResourceBuilderExtensions.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0005 Remove async keyword
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@mitchdenny an error occurred while backporting to release/8.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

mitchdenny pushed a commit that referenced this pull request Apr 10, 2024
…3002 (#3239)

* Update ResourceBuilderExtensions.cs

Allow custom env var names for connection strings

Introduce a new WithEnvironment overload in ResourceBuilderExtensions that
enables setting a connection string under a custom environment variable name.

Fixes #3002.

* Update ResourceBuilderExtensions.cs

* Update ResourceBuilderExtensions.cs

* Update src/Aspire.Hosting/ResourceBuilderExtensions.cs

* Remove async keyword

* Added unit tests to verify the behavior of the WithEnvironment method

* typo fix

* verify the behavior of the WithEnvironment extension method in run mode

* Apply suggestions from code review

---------

Co-authored-by: David Fowler <[email protected]>
davidfowl added a commit that referenced this pull request Apr 10, 2024
…r<IResourceWithConnectionString) (#3549)

* Introduce WithEnvironment overload for custom connection string keys #3002 (#3239)

* Update ResourceBuilderExtensions.cs

Allow custom env var names for connection strings

Introduce a new WithEnvironment overload in ResourceBuilderExtensions that
enables setting a connection string under a custom environment variable name.

Fixes #3002.

* Update ResourceBuilderExtensions.cs

* Update ResourceBuilderExtensions.cs

* Update src/Aspire.Hosting/ResourceBuilderExtensions.cs

* Remove async keyword

* Added unit tests to verify the behavior of the WithEnvironment method

* typo fix

* verify the behavior of the WithEnvironment extension method in run mode

* Apply suggestions from code review

---------

Co-authored-by: David Fowler <[email protected]>

* Fix test after merge.

---------

Co-authored-by: danikishin <[email protected]>
Co-authored-by: David Fowler <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 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.

3 participants