cake-build/cake — pull request #125 by devlead (2014-12-05 16:14:40+00:00)
Title: Suggestion for safer handling of private feeds under CI

**Background**
When working with private feeds & CI we want to be as secure as possible, meaning we don't want to store passwords or sensitive information in the `build.cake` but use the standard `NuGet` sources configuration.

**Solution**
To support this I have added 3 new Cake script methods.

1. NuGetAddSource
- Adds NuGet package source using the specified name, source & settings to global user config
2. NuGetRemoveSource
- Removes NuGet package source using the specified name & source from global user config
3. NuGetHasSource
- Checks if NuGet package source exists in global user config using the specified source & settings

**Usage**
Below is a concise `build.cake` script to illustrate above methods usage, fetching sensitive information from the CI system environment variables.
```csharp
var nugetSourceSettings = new NuGetSourcesSettings
{
UserName = EnvironmentVariable("PRIVATE_FEED_USERNAME"),
Password = EnvironmentVariable("PRIVATE_FEED_PASSWORD"),
IsSensitiveSource = true,
Verbosity = NuGetVerbosity.Detailed
};

var feed = new
{
Name = EnvironmentVariable("PRIVATE_FEED_TELERIK_NAME"),
Source = EnvironmentVariable("PRIVATE_FEED_TELERIK_SOURCE")
};

if (!NuGetHasSource(
source:feed.Source,
settings:nugetSourceSettings
))
{
NuGetAddSource(
name:feed.Name,
source:feed.Source,
settings:nugetSourceSettings
);
}
else
{
Information("Source already exists");
}

NuGetRemoveSource(
name:feed.Name,
source:feed.Source,
settings:nugetSourceSettings
);
```
The output of execution (`.\cake build.cake -target= -verbosity=diagnostic`) will basically be(stripped standard cake output)
```
Compiling build script...
Executing: ./tools/nuget/NuGet.exe sources Add -Name "private-telerik" -Source "[REDACTED]" -Verbosity detailed -NonInteractive -UserName "devlead" -Password "[REDACTED]"
Package Source with Name: private-telerik added successfully.
Executing: ./tools/nuget/NuGet.exe sources Remove -Name "private-telerik" -Source "[REDACTED]" -Verbosity detailed -NonInteractive
Package source with Name: private-telerik removed successfully.
```

This a initial (albeit working) suggestion to solve this, so feedback is very welcome.