Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/content/nuget-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ The [`paket.lock` file](lock-file.html) will also reflect these settings.
values are `basic` and `ntlm`. If no authentication type is specified, basic
authentication will be used.

It's also possible to specify the entire source line as an environment variable.
This is useful if you don't want the feed URL (or its credentials) to appear in
source control at all:

```paket
source %FEED_URL%
```

Here, the `FEED_URL` environment variable must contain everything that would
normally follow the `source` keyword, for example:

```
http://myserver/nuget/api/v2 username: "%PRIVATE_FEED_USER%" password: "%PRIVATE_FEED_PASS%" authtype: "ntlm"
```

**Note:** If [`paket.dependencies` file](dependencies-file.html) exists while
running the [`convert-from-nuget` command](paket-convert-from-nuget.html), the
`PRIVATE_FEED_USER` and `PRIVATE_FEED_PASS` will *not* be expanded. Please see
Expand Down
12 changes: 8 additions & 4 deletions src/Paket.Core/Versioning/PackageSources.fs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,14 @@ type PackageSource =
|> fun xs -> if xs.Length = 0 then afterSource.Length else Array.min xs
afterSource.Substring(0, stopIdx).Trim().Replace("\"","").TrimEnd([| '/' |])

let feed = normalizeFeedUrl source
PackageSource.Parse(feed, parseAuth(line, feed))

static member Parse(source,auth) =
match EnvironmentVariable.Create(source) with
| None ->
let feed = normalizeFeedUrl source
PackageSource.Parse(feed, parseAuth(line, feed))
| Some var ->
PackageSource.Parse ("source " + var.Value)

static member Parse(source, auth) =
match tryParseWindowsStyleNetworkPath source with
| Some path -> PackageSource.Parse(path)
| _ ->
Expand Down
37 changes: 37 additions & 0 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,43 @@ let ``should read config with password in env variable and auth type specified``
cfg.Groups.[Constants.MainDependencyGroup].Sources.Head.Auth.Retrieve true
|> shouldEqual (Some (Credentials{ Username = "user XYZ"; Password = "pw Love"; Type = NetUtils.AuthType.NTLM}))

let configWithSourceInEnvVariable = """
source %FEED_URL%
nuget Rx-Main
"""

[<Test>]
let ``should read config with source in env variable``() =
Environment.SetEnvironmentVariable("FEED_URL", "http://www.nuget.org/api/v2", EnvironmentVariableTarget.Process)
let cfg = DependenciesFile.FromSource(configWithSourceInEnvVariable)

cfg.Groups.[Constants.MainDependencyGroup].Sources
|> shouldEqual [
PackageSource.NuGetV2 {
Url = "http://www.nuget.org/api/v2"
Authentication = AuthProvider.empty} ]


let configWithSourceAndCredentialsInEnvVariable = """
source %FEED_URL%
nuget Rx-Main
"""

[<Test>]
let ``should read config with source and credentials in env variable``() =
Environment.SetEnvironmentVariable("FEED_USERNAME", "user XYZ", EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("FEED_PASSWORD", "pw Love", EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("FEED_URL", "http://www.nuget.org/api/v2 username: \"%FEED_USERNAME%\" password: \"%FEED_PASSWORD%\" authtype: \"nTlM\"", EnvironmentVariableTarget.Process)
let cfg = DependenciesFile.FromSource(configWithSourceAndCredentialsInEnvVariable)

cfg.Groups.[Constants.MainDependencyGroup].Sources
|> shouldEqual [
PackageSource.NuGetV2 {
Url = "http://www.nuget.org/api/v2"
Authentication = AuthProvider.empty} ]
cfg.Groups.[Constants.MainDependencyGroup].Sources.Head.Auth.Retrieve true
|> shouldEqual (Some (Credentials{ Username = "user XYZ"; Password = "pw Love"; Type = NetUtils.AuthType.NTLM}))

let configWithExplicitVersions = """
source "http://www.nuget.org/api/v2"

Expand Down
Loading