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

Fallback to config auth if environment variables are empty #459

Merged
merged 1 commit into from
Dec 20, 2014
Merged
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
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