From 8be11a7e7e4c490036a35dbdecbf7482a097a5f6 Mon Sep 17 00:00:00 2001 From: Basuotian <93654253+basuotian@users.noreply.github.com> Date: Mon, 10 Jan 2022 19:42:06 +0800 Subject: [PATCH] Feat: Add Lark support for notification (#3053) (#3059) Signed-off-by: Shuai Tian Co-authored-by: Shuai Tian --- .../defwithtemplate/notification.yaml | 50 ++++++++++++++++++ .../defwithtemplate/notification.yaml | 50 ++++++++++++++++++ docs/examples/workflow/notification/app.yaml | 6 +++ pkg/stdlib/op.cue | 13 +++++ pkg/stdlib/pkgs/lark.cue | 4 ++ .../internal/workflowstep/notification.cue | 51 +++++++++++++++++++ 6 files changed, 174 insertions(+) create mode 100644 pkg/stdlib/pkgs/lark.cue diff --git a/charts/vela-core/templates/defwithtemplate/notification.yaml b/charts/vela-core/templates/defwithtemplate/notification.yaml index 748356ce9..08d1497af 100644 --- a/charts/vela-core/templates/defwithtemplate/notification.yaml +++ b/charts/vela-core/templates/defwithtemplate/notification.yaml @@ -17,6 +17,27 @@ spec: ) parameter: { + lark?: { + // +usage=Specify the the lark url, you can either sepcify it in value or use secretRef + url: { + value: string + } | { + secretRef: { + // +usage=name is the name of the secret + name: string + // +usage=key is the key in the secret + key: string + } + } + // +useage=Specify the message that you want to sent + message: { + // +usage=msg_type can be text, post, image, interactive, share_chat, share_user, audio, media, file, sticker + msg_type: string + // +usage=content should be json encode string + content: string + } + } + dingding?: { // +usage=Specify the the dingding url, you can either sepcify it in value or use secretRef url: { @@ -207,6 +228,35 @@ spec: } } } + lark: op.#Steps & { + if parameter.lark != _|_ { + if parameter.lark.url.value != _|_ { + lark1: op.#Lark & { + message: parameter.lark.message + larkUrl: parameter.lark.url.value + } + } + if parameter.lark.url.secretRef != _|_ && parameter.lark.url.value == _|_ { + read: op.#Read & { + value: { + apiVersion: "v1" + kind: "Secret" + metadata: { + name: parameter.lark.url.secretRef.name + namespace: context.namespace + } + } + } + + decoded: base64.Decode(null, read.value.data[parameter.lark.url.secretRef.key]) + stringValue: op.#ConvertString & {bt: decoded} + lark2: op.#Lark & { + message: parameter.lark.message + larkUrl: stringValue.str + } + } + } + } slack: op.#Steps & { if parameter.slack != _|_ { if parameter.slack.url.value != _|_ { diff --git a/charts/vela-minimal/templates/defwithtemplate/notification.yaml b/charts/vela-minimal/templates/defwithtemplate/notification.yaml index 748356ce9..08d1497af 100644 --- a/charts/vela-minimal/templates/defwithtemplate/notification.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/notification.yaml @@ -17,6 +17,27 @@ spec: ) parameter: { + lark?: { + // +usage=Specify the the lark url, you can either sepcify it in value or use secretRef + url: { + value: string + } | { + secretRef: { + // +usage=name is the name of the secret + name: string + // +usage=key is the key in the secret + key: string + } + } + // +useage=Specify the message that you want to sent + message: { + // +usage=msg_type can be text, post, image, interactive, share_chat, share_user, audio, media, file, sticker + msg_type: string + // +usage=content should be json encode string + content: string + } + } + dingding?: { // +usage=Specify the the dingding url, you can either sepcify it in value or use secretRef url: { @@ -207,6 +228,35 @@ spec: } } } + lark: op.#Steps & { + if parameter.lark != _|_ { + if parameter.lark.url.value != _|_ { + lark1: op.#Lark & { + message: parameter.lark.message + larkUrl: parameter.lark.url.value + } + } + if parameter.lark.url.secretRef != _|_ && parameter.lark.url.value == _|_ { + read: op.#Read & { + value: { + apiVersion: "v1" + kind: "Secret" + metadata: { + name: parameter.lark.url.secretRef.name + namespace: context.namespace + } + } + } + + decoded: base64.Decode(null, read.value.data[parameter.lark.url.secretRef.key]) + stringValue: op.#ConvertString & {bt: decoded} + lark2: op.#Lark & { + message: parameter.lark.message + larkUrl: stringValue.str + } + } + } + } slack: op.#Steps & { if parameter.slack != _|_ { if parameter.slack.url.value != _|_ { diff --git a/docs/examples/workflow/notification/app.yaml b/docs/examples/workflow/notification/app.yaml index 5b96b11f1..6b6af22f6 100644 --- a/docs/examples/workflow/notification/app.yaml +++ b/docs/examples/workflow/notification/app.yaml @@ -29,6 +29,12 @@ spec: msgtype: text text: content: Hello KubeVela + lark: + url: + value: + message: + msg_type: "text" + content: "{\"text\":\" Hello KubeVela\"}" slack: url: # use url in secret diff --git a/pkg/stdlib/op.cue b/pkg/stdlib/op.cue index 44f34faf2..b7300db5b 100644 --- a/pkg/stdlib/op.cue +++ b/pkg/stdlib/op.cue @@ -108,6 +108,19 @@ import ( } } +#Lark: #Steps & { + message: lark.#LarkMessage + larkUrl: string + do: http.#Do & { + method: "POST" + url: larkUrl + request: { + body: json.Marshal(message) + header: "Content-Type": "application/json" + } + } +} + #Slack: #Steps & { message: slack.#SlackMessage slackUrl: string diff --git a/pkg/stdlib/pkgs/lark.cue b/pkg/stdlib/pkgs/lark.cue new file mode 100644 index 000000000..2edf8e0d0 --- /dev/null +++ b/pkg/stdlib/pkgs/lark.cue @@ -0,0 +1,4 @@ +#LarkMessage: { + msg_type: string + content: string +} diff --git a/vela-templates/definitions/internal/workflowstep/notification.cue b/vela-templates/definitions/internal/workflowstep/notification.cue index e0601653a..f6593326c 100644 --- a/vela-templates/definitions/internal/workflowstep/notification.cue +++ b/vela-templates/definitions/internal/workflowstep/notification.cue @@ -12,6 +12,27 @@ import ( template: { parameter: { + lark?: { + // +usage=Specify the the lark url, you can either sepcify it in value or use secretRef + url: { + value: string + } | { + secretRef: { + // +usage=name is the name of the secret + name: string + // +usage=key is the key in the secret + key: string + } + } + // +useage=Specify the message that you want to sent + message: { + // +usage=msg_type can be text, post, image, interactive, share_chat, share_user, audio, media, file, sticker + msg_type: string + // +usage=content should be json encode string + content: string + } + } + dingding?: { // +usage=Specify the the dingding url, you can either sepcify it in value or use secretRef url: { @@ -209,6 +230,36 @@ template: { } } + lark: op.#Steps & { + if parameter.lark != _|_ { + if parameter.lark.url.value != _|_ { + lark1: op.#Lark & { + message: parameter.lark.message + larkUrl: parameter.lark.url.value + } + } + if parameter.lark.url.secretRef != _|_ && parameter.lark.url.value == _|_ { + read: op.#Read & { + value: { + apiVersion: "v1" + kind: "Secret" + metadata: { + name: parameter.lark.url.secretRef.name + namespace: context.namespace + } + } + } + + decoded: base64.Decode(null, read.value.data[parameter.lark.url.secretRef.key]) + stringValue: op.#ConvertString & {bt: decoded} + lark2: op.#Lark & { + message: parameter.lark.message + larkUrl: stringValue.str + } + } + } + } + slack: op.#Steps & { if parameter.slack != _|_ { if parameter.slack.url.value != _|_ {