Skip to content

Commit

Permalink
Allow sources to be specified as Environment Variables
Browse files Browse the repository at this point in the history
  • Loading branch information
msarilar committed Sep 3, 2024
1 parent d6fee24 commit da3c2f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Paket.Core/Versioning/PackageSources.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ type PackageSource =
else
parts.[1].Replace("\"","").TrimEnd([| '/' |])

let feed = normalizeFeedUrl source
let feed =
EnvironmentVariable.Create(source)
|> Option.map (fun var -> var.Value)
|> Option.defaultValue source
|> normalizeFeedUrl

PackageSource.Parse(feed, parseAuth(line, feed))

static member Parse(source,auth) =
Expand Down
20 changes: 18 additions & 2 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ nuget Rx-Main
let ``should read config with password in env variable``() =
Environment.SetEnvironmentVariable("FEED_USERNAME", "user XYZ", EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("FEED_PASSWORD", "pw Love", EnvironmentVariableTarget.Process)
let cfg = DependenciesFile.FromSource( configWithPasswordInEnvVariable)
let cfg = DependenciesFile.FromSource(configWithPasswordInEnvVariable)

cfg.Groups.[Constants.MainDependencyGroup].Sources
|> shouldEqual [
Expand All @@ -769,7 +769,7 @@ nuget Rx-Main
let ``should read config with password in env variable and auth type specified``() =
Environment.SetEnvironmentVariable("FEED_USERNAME", "user XYZ", EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("FEED_PASSWORD", "pw Love", EnvironmentVariableTarget.Process)
let cfg = DependenciesFile.FromSource( configWithPasswordInEnvVariableAndAuthType)
let cfg = DependenciesFile.FromSource(configWithPasswordInEnvVariableAndAuthType)

cfg.Groups.[Constants.MainDependencyGroup].Sources
|> shouldEqual [
Expand All @@ -779,6 +779,22 @@ 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 configWithExplicitVersions = """
source "http://www.nuget.org/api/v2"
Expand Down

0 comments on commit da3c2f7

Please sign in to comment.