Files
kubevela/vela-templates/definitions/internal/workflowstep/webhook.cue
2021-12-30 10:11:19 +08:00

82 lines
1.7 KiB
CUE

import (
"vela/op"
"encoding/json"
"encoding/base64"
)
"webhook": {
type: "workflow-step"
annotations: {}
labels: {}
description: "Send webhook request to the url"
}
template: {
data: op.#Steps & {
if parameter.data == _|_ {
read: op.#Read & {
value: {
apiVersion: "core.oam.dev/v1beta1"
kind: "Application"
metadata: {
name: context.name
namespace: context.namespace
}
}
} @step(1)
value: json.Marshal(read.value) @step(2)
}
if parameter.data != _|_ {
value: json.Marshal(parameter.data) @step(3)
}
}
webhook: op.#Steps & {
if parameter.url.value != _|_ {
http: op.#HTTPPost & {
url: parameter.url.value
request: {
body: data.value
header: "Content-Type": "application/json"
}
} @step(4)
}
if parameter.url.secretRef != _|_ && parameter.url.value == _|_ {
read: op.#Read & {
value: {
apiVersion: "v1"
kind: "Secret"
metadata: {
name: parameter.url.secretRef.name
namespace: context.namespace
}
}
} @step(5)
decoded: base64.Decode(null, read.value.data[parameter.url.secretRef.key]) @step(6)
stringValue: op.#ConvertString & {bt: decoded} @step(7)
http: op.#HTTPPost & {
url: stringValue.str
request: {
body: data.value
header: "Content-Type": "application/json"
}
} @step(8)
}
}
parameter: {
// +usage=Specify the webhook url
url: {
value: string
} | {
secretRef: {
// +usage=name is the name of the secret
name: string
// +usage=key is the key in the secret
key: string
}
}
// +usage=Specify the data you want to send
data?: {...}
}
}