Skip to content

Commit

Permalink
Merge pull request #459 from yannisgu/fallbackToConfigAuth
Browse files Browse the repository at this point in the history
Fallback to config auth if environment variables are empty
  • Loading branch information
forki committed Dec 20, 2014
2 parents 327a437 + 60830d4 commit 2ca01ca
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Paket.Core/PackageSources.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type EnvironmentVariable =
let expanded = Environment.GetEnvironmentVariable(trimmed)
if expanded = null then
traceWarnfn "environment variable '%s' not found" variable
None
Some { Variable = variable; Value = ""}
else
Some { Variable = variable; Value = expanded }
else
Expand Down Expand Up @@ -46,12 +46,21 @@ let private parseAuth(text, source) =
let username = userNameRegex.Match(text).Groups.[1].Value
let password = passwordRegex.Match(text).Groups.[1].Value

match EnvironmentVariable.Create(username),
EnvironmentVariable.Create(password) with
| Some userNameVar, Some passwordVar ->
Some (EnvVarAuthentication(userNameVar, passwordVar))
| _, _ ->
Some (PlainTextAuthentication(username, password))
let auth =
match EnvironmentVariable.Create(username),
EnvironmentVariable.Create(password) with
| Some userNameVar, Some passwordVar ->
EnvVarAuthentication(userNameVar, passwordVar)
| _, _ ->
PlainTextAuthentication(username, password)

let basicAuth = toBasicAuth auth
if(basicAuth.Username = "" && basicAuth.Password = "") then
ConfigFile.GetCredentials source
|> Option.map (fun (username,password) ->
ConfigAuthentication(username, password))
else
Some(auth)
else
if text.Contains("username:") || text.Contains("password:") then
failwithf "Could not parse auth in \"%s\"" text
Expand Down

0 comments on commit 2ca01ca

Please sign in to comment.