Skip to content

Commit

Permalink
Flow http flatten (#371)
Browse files Browse the repository at this point in the history
Co-authored-by: Tony Worm <tony@topcialsource.com>
  • Loading branch information
verdverm and Tony Worm authored May 17, 2024
1 parent 87cf8d7 commit 0b6a23a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 70 deletions.
51 changes: 0 additions & 51 deletions .github/workflows/hof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,55 +73,4 @@ jobs:
hof fmt start @v0.6.8
hof fmt info
docker ps -a
- name: test/self
env:
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: |-
# self: gen -> diff
set -e
# mods & deps
hof mod tidy
hof fmt cue.mod/module.cue
hof mod vendor
# gen self
hof gen
# should have no diff
git diff --exit-code
- name: test/gen
env:
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/gen ./test.cue
- name: test/create
env:
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/create ./test.cue
- name: test/structural
env:
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/st ./test.cue
- name: test/datamodel
env:
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/dm ./test.cue
- name: test/flow
env:
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/flow ./test.cue
- name: test/fmt
env:
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: |-
docker ps -a
hof fmt info
hof flow @test/fmt ./test.cue
- name: test/mod
run: hof flow @test/mod ./test.cue
env:
GITHUB_TOKEN: ${{secrets.HOF_HOMEBREW_PAT}}
GITLAB_TOKEN: ${{secrets.GITLAB_TOKEN}}
BITBUCKET_USERNAME: hofstadter
BITBUCKET_PASSWORD: ${{secrets.BITBUCKET_TOKEN}}
services: {}
29 changes: 15 additions & 14 deletions ci/gha/hof.cue
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ ghacue.#Workflow & {
"""
// "if": "startsWith( runner.os, 'macos')"
},
] + #TestSteps + [{
// should probably be last for external workflows?
// or maybe separate workflow for permissions?
name: "test/mod"
run: """
hof flow @test/mod ./test.cue
"""
env: {
GITHUB_TOKEN: "${{secrets.HOF_HOMEBREW_PAT}}"
GITLAB_TOKEN: "${{secrets.GITLAB_TOKEN}}"
BITBUCKET_USERNAME: "hofstadter"
BITBUCKET_PASSWORD: "${{secrets.BITBUCKET_TOKEN}}"
}
}]
]
// ] + #TestSteps + [{
// // should probably be last for external workflows?
// // or maybe separate workflow for permissions?
// name: "test/mod"
// run: """
// hof flow @test/mod ./test.cue
// """
// env: {
// GITHUB_TOKEN: "${{secrets.HOF_HOMEBREW_PAT}}"
// GITLAB_TOKEN: "${{secrets.GITLAB_TOKEN}}"
// BITBUCKET_USERNAME: "hofstadter"
// BITBUCKET_PASSWORD: "${{secrets.BITBUCKET_TOKEN}}"
// }
// }]
}
}

Expand Down
30 changes: 26 additions & 4 deletions flow/tasks/api/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
hofcontext "github.com/hofstadter-io/hof/flow/context"
"github.com/hofstadter-io/hof/flow/flow"
"github.com/hofstadter-io/hof/flow/tasks/csp"
"github.com/hofstadter-io/hof/lib/cuetils"
)

type Serve struct {
Expand Down Expand Up @@ -262,8 +263,9 @@ func (T *Serve) routeFromValue(path string, route cue.Value, e *echo.Echo, ctx *

resp := tmp.LookupPath(cue.ParsePath("resp"))
if resp.Err() != nil {
fmt.Println("handler resp error:", resp.Err())
return resp.Err()
e := cuetils.ExpandCueError(resp.Err())
fmt.Println("handler resp error:", e, tmp)
return e
}

err = T.fillRespFromValue(resp, c)
Expand Down Expand Up @@ -320,9 +322,29 @@ func (T *Serve) buildReqValue(c echo.Context) (map[string]interface{}, error) {
R := c.Request()

req["method"] = R.Method
req["header"] = R.Header
req["url"] = R.URL
req["query"] = c.QueryParams()

// flatten any headers of len 1
hm := map[string]any{}
for k,v := range R.Header {
if len(v) == 1 {
hm[k] = v[0]
} else {
hm[k] = v
}
}
req["header"] = hm

// flatten any query params of len 1
qm := map[string]any{}
for k,v := range c.QueryParams() {
if len(v) == 1 {
qm[k] = v[0]
} else {
qm[k] = v
}
}
req["query"] = qm

b, err := io.ReadAll(R.Body)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/dagger/main/hof.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func main() {
"st",
"dm",
"flow",
"mod",
// "mod",
"fmt",
"cue",
}
Expand Down

0 comments on commit 0b6a23a

Please sign in to comment.