Skip to content
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
61 changes: 36 additions & 25 deletions charts/vela-workflow/templates/definitions/request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,45 @@ spec:
cue:
template: |
import (
"vela/op"
"encoding/json"
"vela/http"
"vela/op"
"encoding/json"
)

http: op.#HTTPDo & {
method: parameter.method
url: parameter.url
request: {
if parameter.body != _|_ {
body: json.Marshal(parameter.body)
}
if parameter.header != _|_ {
header: parameter.header
}
}
}
req: http.#HTTPDo & {
$params: {
method: parameter.method
url: parameter.url
request: {
if parameter.body != _|_ {
body: json.Marshal(parameter.body)
}
if parameter.header != _|_ {
header: parameter.header
}
}
}
} @step(1)

wait: op.#ConditionalWait & {
continue: req.$returns != _|_
message?: "Waiting for response from \(parameter.url)"
} @step(2)

fail: op.#Steps & {
if http.response.statusCode > 400 {
requestFail: op.#Fail & {
message: "request of \(parameter.url) is fail: \(http.response.statusCode)"
}
}
}
response: json.Unmarshal(http.response.body)
if req.$returns.statusCode > 400 {
requestFail: op.#Fail & {
message: "request of \(parameter.url) is fail: \(req.$returns.statusCode)"
}
}
} @step(3)

response: json.Unmarshal(req.$returns.body)

parameter: {
url: string
method: *"GET" | "POST" | "PUT" | "DELETE"
body?: {...}
header?: [string]: string
url: string
method: *"GET" | "POST" | "PUT" | "DELETE"
body?: {...}
header?: [string]: string
}

21 changes: 9 additions & 12 deletions pkg/providers/http/http.cue
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@
}

$returns?: {
// +usage=The response of the request will be filled in this field after the action is executed
response: {
// +usage=The body of the response
body: string
// +usage=The header of the response
header?: [string]: [...string]
// +usage=The trailer of the response
trailer?: [string]: [...string]
// +usage=The status code of the response
statusCode: int
...
}
// +usage=The body of the response
body: string
// +usage=The header of the response
header?: [string]: [...string]
// +usage=The trailer of the response
trailer?: [string]: [...string]
// +usage=The status code of the response
statusCode: int
...
}
...
}
Expand Down
Loading