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

cleanup, defense against empty sequences, etc. Thanks vasily! #745

Merged
merged 1 commit into from
Apr 7, 2015
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
33 changes: 15 additions & 18 deletions src/app/Fake.Deploy.Lib/HttpHeaderHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ let toHeaderValue (values:string []) : string =
x.Replace("\"", "%22")
|> sprintf "\"%s\""
)
|> fun strs -> System.String.Join(",", strs
)
|> String.concat ","

let private regex = Regex("(\"[^\"]*\")(?:,(\"[^\"]*\"))*", RegexOptions.Compiled)
let fromHeaderValue (value:string) : string [] =
let matches = regex.Matches(value)
//back compat: existing agents not expecting quoted params will continue to function.
if matches.Count = 0 then [|value|]
else
matches |> Seq.cast
|> Seq.collect (fun (m:Match) -> m.Groups |> Seq.cast)
|> Seq.skip 1
|> Seq.collect (fun (g:Group) ->
g.Captures |> Seq.cast |> Seq.map (fun (c:Capture) -> c.Value)
|> Seq.map (fun (x:string) ->
x.Substring(1, x.Length - 2)
|> fun y -> y.Replace("%22", "\"")
)
)
|> Array.ofSeq

let fromHeaderValue (value: string) =
match regex.Matches value |> Seq.cast<Match> |> Seq.toList with
| [] ->
//back compat: existing agents not expecting quoted params will continue to function.
[|value|]
| matches ->
match [ for m in matches do
for x in m.Groups -> x ] with
| _ :: gs ->
[| for g in gs do
for c in g.Captures do
yield c.Value.[1..c.Value.Length - 2].Replace("%22", "\"") |]
| _ -> [|value|]



20 changes: 14 additions & 6 deletions src/app/Fake.Deploy/DeploymentAgent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ let getBodyFromNancyRequest (ctx : Nancy.Request) =
ctx.Body.CopyTo ms
ms.ToArray()

let getScriptArgumentsFromNancyRequest (ctx : Nancy.Request) =
ctx.Headers
|> Seq.choose (fun pair -> if pair.Key = FakeDeployAgentHelper.scriptArgumentsHeaderName then Some <| pair.Value else None)
|> Seq.head
|> Seq.head
|> fromHeaderValue
let getScriptArgumentsFromNancyRequest (ctx : Nancy.Request) : string [] =
let args =
ctx.Headers
|> Seq.choose (fun pair ->
if pair.Key = FakeDeployAgentHelper.scriptArgumentsHeaderName then
Some pair.Value
else None
)
|> List.ofSeq

match args with
| [] -> [||]
| _ -> args |> Seq.collect id |> Seq.map fromHeaderValue |> Seq.collect id |> Array.ofSeq


let runDeployment workDir (ctx : Nancy.Request) =
let packageBytes = getBodyFromNancyRequest ctx
Expand Down
14 changes: 8 additions & 6 deletions src/deploy.web/Fake.Deploy.Web/Modules/Api.Package.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ type ApiPackage (dataProvider : IDataProvider) as http =
let agent = dataProvider.GetAgents [agentId] |> Seq.head
let url = agent.Address.AbsoluteUri + "fake/"
let env =
[agent.EnvironmentId]
|>dataProvider.GetEnvironments
|> Seq.head
|> fun x -> x.Name
|> sprintf "env=%s"
match [agent.EnvironmentId]
|>dataProvider.GetEnvironments with
| [||] -> None
| envs -> envs |> Seq.head |> fun x -> x.Name |> sprintf "env=%s" |> Some

let args = Seq.choose id [env] |> Array.ofSeq

Directory.CreateDirectory(packageTemp) |> ignore
let files =
http.Request.Files
Expand All @@ -64,7 +66,7 @@ type ApiPackage (dataProvider : IDataProvider) as http =
let code, message =
files
|> Seq.map(fun file ->
match postDeploymentPackage url file [|env|] with
match postDeploymentPackage url file args with
| Failure(err) ->
file, Some err, HttpStatusCode.InternalServerError, Some(err)
| Success a ->
Expand Down