-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slack interceptor 1542 #1548
Slack interceptor 1542 #1548
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## Slack slash command EventListener | ||
|
||
Creates an EventListener that listens for Slack events. | ||
|
||
### Try it out locally: | ||
|
||
1. To create the slack trigger and all related resources, run: | ||
|
||
```bash | ||
kubectl apply -f . | ||
``` | ||
|
||
1. Port forward: | ||
|
||
```bash | ||
kubectl port-forward service/el-slack-listener 8080 | ||
``` | ||
|
||
1. Test by sending the sample payload. | ||
|
||
```bash | ||
curl -v \ | ||
-H 'X-Slack-Signature: sha1=ba0cdc263b3492a74b601d240c27efe81c4720cb' \ | ||
-H 'Content-Type: application/x-www-form-urlencoded' \ | ||
-d 'token=EidhofDor5uIpqQ9RrtOVdnC&team_id=T04PK47eDS4&team_domain=demoworkspace-tid8978&channel_id=C04NETw4NBH&channel_name=sample-app&user_id=U04NVDwF7R8&&command=%2Fbuild&text=main+2222&api_app_id=A04NXU23L&is_enterprise_install=false&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT04PK47EDS4%2F4863712501879%2FdOMNffCDfTjlSskBrmB1bOtR&trigger_id=4890883491553.4801143489888.910b8eaae200b381834de25310583f74' \ | ||
http://localhost:8080 | ||
``` | ||
|
||
The response status code should be `202 Accepted` | ||
|
||
|
||
1. You should see a new TaskRun that got created: | ||
|
||
```bash | ||
kubectl get taskruns | grep slack-run- | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
curl -v \ | ||
-H 'X-Slack-Signature: sha1=ba0cdc263b3492a74b601d240c27efe81c4720cb' \ | ||
-H 'Content-Type: application/x-www-form-urlencoded' \ | ||
-d 'token=EidhofDor5uIpqQ9RrtOVdnC&team_id=T04PK47eDS4&team_domain=demoworkspace-tid8978&channel_id=C04NETw4NBH&channel_name=sample-app&user_id=U04NVDwF7R8&&command=%2Fbuild&text=main+2222&api_app_id=A04NXU23L&is_enterprise_install=false&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT04PK47EDS4%2F4863712501879%2FdOMNffCDfTjlSskBrmB1bOtR&trigger_id=4890883491553.4801143489888.910b8eaae200b381834de25310583f74' \ | ||
http://localhost:8080 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../rbac.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
apiVersion: triggers.tekton.dev/v1beta1 | ||
kind: EventListener | ||
metadata: | ||
name: slack-listener | ||
annotations: | ||
tekton.dev/payload-validation: "false" | ||
spec: | ||
serviceAccountName: tekton-triggers-example-sa | ||
triggers: | ||
- name: slack-trigger | ||
interceptors: | ||
- ref: | ||
name: "slack" | ||
kind: ClusterInterceptor | ||
params: | ||
- name: requestedFields | ||
value: | ||
- text | ||
- ref: | ||
name: cel | ||
params: | ||
- name: "overlays" | ||
value: | ||
- key: branch | ||
expression: 'extensions.text[0].split(" ")[0]' | ||
- key: image | ||
expression: 'extensions.text[0].split(" ")[1]' | ||
bindings: | ||
- name: branch | ||
value: $(extensions.branch) | ||
- name: image | ||
value: $(extensions.image) | ||
template: | ||
spec: | ||
params: | ||
- name: response | ||
resourcetemplates: | ||
- apiVersion: tekton.dev/v1beta1 | ||
kind: TaskRun | ||
metadata: | ||
generateName: slack-run- | ||
spec: | ||
taskSpec: | ||
steps: | ||
- image: ubuntu | ||
script: | | ||
#! /bin/bash | ||
echo "response of slack : $(tt.params.response)" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,13 @@ type WebhookInterceptor struct { | |
Header []v1beta1.Param `json:"header,omitempty"` | ||
} | ||
|
||
type SlackInterceptor struct { | ||
// the Requested fields to be extracted from data form | ||
|
||
// +listType=atomic | ||
RequestedFields []string `json:"requestedFields,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a mandatory field? or do we extract all fields by default if no requestedFields is specifed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We extract only the requested fields. |
||
} | ||
|
||
// BitbucketInterceptor provides a webhook to intercept and pre-process events | ||
type BitbucketInterceptor struct { | ||
SecretRef *SecretRef `json:"secretRef,omitempty"` | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should update our payload validation to allow json and form/urlencoded content types and return invalid for anything else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @khrm