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

Fixes environment variable prefixes with double underscores preventing environment variables from being parsed #42932

Merged
merged 7 commits into from
Dec 23, 2020

Conversation

Emzi0767
Copy link
Contributor

@Emzi0767 Emzi0767 commented Sep 30, 2020

This PR fixes #40911.

The following changes are implemented:

  • AzureEnvToAppEnv now filters out variables which do not start with any of the valid prefixes.
  • Environment variable name processing is altered as such:
    • The specified variable prefix is stripped from the variable name before normalization.
    • The variable name is normalized.
    • The prefix is then prepended to the variable name.

Relevant tests have been added to the repository. All passing.

The fix implementation works like so:
- The environment variable prefix is stripped from a variable name.
- The variable name is then normalized.
- The prefix is then prepended to the variable name.
- Additionally, the filtering now occurs at the same time as
parsing/transformation.
@ghost
Copy link

ghost commented Sep 30, 2020

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

@dnfadmin
Copy link

dnfadmin commented Sep 30, 2020

CLA assistant check
All CLA requirements met.

@Emzi0767
Copy link
Contributor Author

Emzi0767 commented Sep 30, 2020

I should mention: this PR also supersedes #41092, the author of which appears to be inactive.

Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

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

Should we support more than double _?

@Emzi0767
Copy link
Contributor Author

Emzi0767 commented Oct 2, 2020

Should we support more than double _?

This PR simply prevents normalization of the prefix. Number of underscores doesn't matter. So long as it's part of the prefix, it will not be normalized.

@Emzi0767
Copy link
Contributor Author

Emzi0767 commented Oct 2, 2020

I should also point out, that the error here occured due to the fact that normalization of variable name happened before the user-specified prefix was fixed, which led to situations where if variables were prefixed with a string that contained a double-or-longer underscore substring, it was normalized, and then no longer matched the prefix, which meant the variables weren't loaded. The fix was to simply swap the order of those operations.

@danmoseley
Copy link
Member

@maryamariyan what is the next step here? this one seems to have got stuck. 😃

@safern
Copy link
Member

safern commented Dec 15, 2020

Overall, looks good, @maryamariyan and I left some comments. Also, merge conflicts need to be addressed.

@Emzi0767
Copy link
Contributor Author

I shall address the changes later this week, possibly today

@Emzi0767
Copy link
Contributor Author

I am stuck with a problem: I am either misunderstanding something or #44923 altered the behaviour of loading SQL connection strings:

Prior to #44923, adding a connectionstring-prefixed envvar to the collection would yield it back in the configuration with ConnectionStrings: prefix. Post 44923 it does not. Is this a regression or am I misunderstanding something?

@Emzi0767
Copy link
Contributor Author

Nevermind above, I have tested above and it seems I misunderstood.

@Emzi0767
Copy link
Contributor Author

I apologize for the slight mess in commits, however git is refusing to recognize that I've merged a change.

Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

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

LGTM

@ghost
Copy link

ghost commented Dec 21, 2020

Hello @safern!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@safern safern merged commit 9a322a5 into dotnet:master Dec 23, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment Variable configuration provider doesn't work if the prefix has 2 underscores
7 participants