github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/workflowstep/webhook.cue (about) 1 import ( 2 "vela/op" 3 "encoding/json" 4 "encoding/base64" 5 ) 6 7 "webhook": { 8 type: "workflow-step" 9 annotations: { 10 "category": "External Intergration" 11 } 12 labels: {} 13 description: "Send a POST request to the specified Webhook URL. If no request body is specified, the current Application body will be sent by default." 14 } 15 template: { 16 data: op.#Steps & { 17 if parameter.data == _|_ { 18 read: op.#Read & { 19 value: { 20 apiVersion: "core.oam.dev/v1beta1" 21 kind: "Application" 22 metadata: { 23 name: context.name 24 namespace: context.namespace 25 } 26 } 27 } @step(1) 28 value: json.Marshal(read.value) @step(2) 29 } 30 if parameter.data != _|_ { 31 value: json.Marshal(parameter.data) @step(3) 32 } 33 } 34 webhook: op.#Steps & { 35 if parameter.url.value != _|_ { 36 http: op.#HTTPPost & { 37 url: parameter.url.value 38 request: { 39 body: data.value 40 header: "Content-Type": "application/json" 41 } 42 } @step(4) 43 } 44 if parameter.url.secretRef != _|_ && parameter.url.value == _|_ { 45 read: op.#Read & { 46 value: { 47 apiVersion: "v1" 48 kind: "Secret" 49 metadata: { 50 name: parameter.url.secretRef.name 51 namespace: context.namespace 52 } 53 } 54 } @step(5) 55 56 stringValue: op.#ConvertString & {bt: base64.Decode(null, read.value.data[parameter.url.secretRef.key])} @step(6) 57 http: op.#HTTPPost & { 58 url: stringValue.str 59 request: { 60 body: data.value 61 header: "Content-Type": "application/json" 62 } 63 } @step(7) 64 } 65 } 66 67 parameter: { 68 // +usage=Specify the webhook url 69 url: close({ 70 value: string 71 }) | close({ 72 secretRef: { 73 // +usage=name is the name of the secret 74 name: string 75 // +usage=key is the key in the secret 76 key: string 77 } 78 }) 79 // +usage=Specify the data you want to send 80 data?: {...} 81 } 82 }