-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added lua script as event filter Signed-off-by: Vaibhav Page <vaibhav.page@gmail.com> * feat: added script filter Signed-off-by: Vaibhav Page <vaibhav.page@gmail.com> * chore: ran codegen Signed-off-by: Vaibhav Page <vaibhav.page@gmail.com>
- Loading branch information
1 parent
111c337
commit 2d9fc5d
Showing
11 changed files
with
520 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Event Payload | ||
# | ||
# { | ||
# "a": "b", | ||
# "c": 10, | ||
# "d": { | ||
# "e": "z" | ||
# } | ||
# } | ||
# | ||
|
||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Sensor | ||
metadata: | ||
name: with-script-filter | ||
spec: | ||
dependencies: | ||
- name: test-dep | ||
eventSourceName: webhook | ||
eventName: example | ||
filters: | ||
script: |- | ||
if event.a == "b" and event.d.e == "z" then return true else return false end | ||
triggers: | ||
- template: | ||
name: workflow | ||
k8s: | ||
operation: create | ||
source: | ||
resource: | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: workflow- | ||
spec: | ||
entrypoint: whalesay | ||
arguments: | ||
parameters: | ||
- name: message | ||
# value will get overridden by the event payload | ||
value: hello world | ||
templates: | ||
- name: whalesay | ||
inputs: | ||
parameters: | ||
- name: message | ||
container: | ||
image: docker/whalesay:latest | ||
command: [cowsay] | ||
args: ["{{inputs.parameters.message}}"] | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: name | ||
dest: spec.arguments.parameters.0.value |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package dependencies | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestScriptFilter(t *testing.T) { | ||
tests := []struct { | ||
script string | ||
event *v1alpha1.Event | ||
result bool | ||
hasError bool | ||
}{ | ||
{ | ||
script: ` | ||
if event.a == "hello" then return true else return false end | ||
`, | ||
event: &v1alpha1.Event{ | ||
Data: []byte(`{"a":"hello"}`), | ||
}, | ||
result: true, | ||
hasError: false, | ||
}, | ||
{ | ||
script: ` | ||
if event.a == "hello" and event.b == "world" then return false else return true end | ||
`, | ||
event: &v1alpha1.Event{ | ||
Data: []byte(`{"a":"hello","b":"world"}`), | ||
}, | ||
result: false, | ||
hasError: false, | ||
}, | ||
{ | ||
script: ` | ||
if event.a == "hello" return false else return true end | ||
`, | ||
event: &v1alpha1.Event{ | ||
Data: []byte(`{"a":"hello"}`), | ||
}, | ||
result: false, | ||
hasError: true, | ||
}, | ||
{ | ||
script: ` | ||
if a.a == "hello" then return true else return false end | ||
`, | ||
event: &v1alpha1.Event{ | ||
Data: []byte(`{"a":"hello"}`), | ||
}, | ||
result: false, | ||
hasError: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
result, err := filterScript(tt.script, tt.event) | ||
if tt.hasError { | ||
assert.NotNil(t, err) | ||
} else { | ||
assert.Nil(t, err) | ||
assert.Equal(t, tt.result, result) | ||
} | ||
} | ||
} |