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

Eval env variables in config values #171

Closed
wants to merge 1 commit into from
Closed

Eval env variables in config values #171

wants to merge 1 commit into from

Conversation

TravisTheTechie
Copy link
Contributor

Applies to NuGet/Home#1852

Takes environment variable references in config values, and evaluates those references to what's in the environment. Uses Environment.ExpandEnvironmentVariables, so it should be cross platform already.

Execution

Tested

  • Windows
  • Mac OS X
  • Linux
  • Unit tests
  • Functional tests

Considerations

  • Environment.ExpandEnvironmentVariables looks for %ENV_NAME% and *nix-based systems use the format $ENV_NAME. Both could be supported, but looking at a couple other projects, it seems the Windows-style naming is consistent on .NET-based cross platform projects.
  • Are there other channels this misses? ConfigurationDefaults, for example, uses both GetValue and GetSettingValues. I didn't obviously see another location that taps into this different.

@dnfclas
Copy link

dnfclas commented Jan 3, 2016

Hi @TravisTheTechie, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@dnfclas
Copy link

dnfclas commented Jan 3, 2016

@TravisTheTechie, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;


private string ApplyEnvironmentTransform(string configValue)
{
if (String.IsNullOrEmpty(configValue))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use the string.IsNullOrEmpty casing

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 was matching the casing existing in the file, e.g. https://github.com/TravisTheTechie/NuGet.Client/blob/issue-1852-eval-env-variables-in-config-values/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs#L59, should I go ahead an update the other references to match or just leave it with my changes?

@yishaigalatzer
Copy link
Contributor

@TravisTheTechie looks pretty neat! I'm excited about this fix.

I would add a functional test for this (add a test that uses the nuget command line to read a source location) and properly prints it out (or restores from it). You can use a local folder that you put in a config file and expand it.

It will also be nice to create a PR in the docs repo (CC @csharpfritz) showing an example for this cool feature

@yishaigalatzer
Copy link
Contributor

@emgarten @zhili1208 @deepakaravindr can you guys take a look?

</configuration>";

[Fact]
public void GetValueEvalutatesEnvironmentVariable()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spelling error

@TravisTheTechie
Copy link
Contributor Author

Applied feedback, minus functional test. I'll poke around and see if I can figure that out. I see my changes working locally, but everyone shouldn't have to reproduce my setup:
nuget-env-windows

Or on my Mac.

$ cat nuget.config 
<configuration>
    <config>
        <add key="repositoryPath" value="%HOME%\NuGetPackages-with-env" />
    </config>
</configuration>

$ mono NuGet.exe config repositoryPath
/Users/tsmith\NuGetPackages-with-env

Is there a way I can build just NuGet.exe using build.ps1? It takes me on the order of 30 minutes to fully build everything and it would be awesome to have a quicker turn around on that.

@TravisTheTechie
Copy link
Contributor Author

And I can make a PR for docs once this is complete.

@yishaigalatzer
Copy link
Contributor

Building fast is build.ps1 -SkipTests would get you 4-5 minute build

@TravisTheTechie
Copy link
Contributor Author

So I added a PowerShell script which should test this functionality. Though I can't figure out how to execute it correctly. Am I going down the right track for functional tests?

@yishaigalatzer
Copy link
Contributor

This should be a simple unit test spinning nuget.exe look at the tests in the nuget.commandline.test

@TravisTheTechie
Copy link
Contributor Author

Added functional test.

Tested on Ubuntu.
ubuntu-nuget-env

I believe this covers everyone's feedback. Anything additional?

@yishaigalatzer
Copy link
Contributor

Docs pr

@TravisTheTechie
Copy link
Contributor Author

NuGet/NuGetDocs#431 covers the docs. Unless someone has other feedback for me, I think this is done.

It doesn't look like you do it normally, but if you want I can squash my commits for cleaner history.

@yishaigalatzer
Copy link
Contributor

We actually do squash it normally (some people missed it in the last few weeks). So yes Please!

@yishaigalatzer
Copy link
Contributor

@deepakaravindr please have a final review and merge (just the code, we will merge the doc PR when we ship). @TravisTheTechie it is better that you squash so we don't accidentally remove you as the author

* Added tests for `Settings.GetValue()` and
`Settings.GetSettingValues()`
* Added simple implementation for `Settings.GetValue()`
* `Settings.GetSettingValues()` still needs an implementation, or an
implementation that overlaps both.
@TravisTheTechie
Copy link
Contributor Author

Squashed. Will squash docs as well.

@yishaigalatzer
Copy link
Contributor

@deepakaravindr ping

@deepakaravindr deepakaravindr self-assigned this Feb 5, 2016
@deepakaravindr
Copy link
Contributor

Merged with 603907b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants