forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
57 lines (51 loc) · 1.84 KB
/
Tiltfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def snyk(target, test_type, name='snyk', test_deps='', extra_opts='', trigger='manual', mode='gate'):
"""
Args:
name: a name for the resource. useful for labeling when running multiple tests.
target: path to the file/dir or container image name:tag to test
test_type: one of 'oss', 'container', or 'iac' corresponding to the various Snyk CLI tests
test_deps: automatically set for test types other than container, allows for setting an external file/dir dependency
extra_opts: additional CLI options; appended to the snyk command. see `snyk --help` for usage.
- container: this is where to insert the '--file=path/to/Dockerfile' option
trigger: trigger mode - auto or manual
mode: control Snyk exit code, info will always exit 0 - gate or info
"""
if test_type == 'oss':
snyk_cmd = [
"snyk test --all-projects",
target
]
test_deps = [target]
elif test_type == 'container':
snyk_cmd = [
"snyk container test",
target
]
elif test_type == 'iac':
snyk_cmd = [
"snyk iac test",
target
]
test_deps = [target]
else:
fail("Snyk test_type should be one of oss, container, or iac.")
if (len(extra_opts) > 0):
snyk_cmd.append(extra_opts)
if mode == 'info':
snyk_cmd.append("|| true")
snyk_cmd = " ".join(snyk_cmd)
if trigger == 'manual':
trigger_string = TRIGGER_MODE_MANUAL
auto_bool = False
elif trigger == 'auto':
trigger_string = TRIGGER_MODE_AUTO
auto_bool = True
else:
fail("Snyk trigger should be one of manual or auto")
local_resource(
name,
deps = test_deps,
cmd = snyk_cmd,
auto_init = auto_bool,
trigger_mode = trigger_string
)