-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidate_inputs.py
62 lines (47 loc) · 1.65 KB
/
validate_inputs.py
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
58
59
60
61
import os
import json
import sys
def validate_inputs(inputs):
errors = []
if 'TOKEN' not in inputs or not inputs['TOKEN']:
errors.append("Token is required.")
if 'TENANT_ID' not in inputs or not inputs['TENANT_ID']:
errors.append("Tenant ID is required.")
if 'IMAGE' not in inputs or not inputs['IMAGE']:
errors.append("Image name is required.")
if 'SEVERITY' in inputs:
valid_severities = {'UNKNOWN', 'LOW', 'MEDIUM', 'HIGH', 'CRITICAL'}
severity = inputs['SEVERITY'].upper()
for s in severity.split(','):
if s not in valid_severities:
errors.append("Invalid severity level provided.")
if 'CODE' in inputs:
code = inputs['CODE']
if code not in {'0', '1'}:
errors.append("Invalid code value provided.")
if 'LABEL' not in inputs or not inputs['LABEL']:
errors.append("label is required.")
return errors
def main():
inputs = {
'DOCKERFILE_CONTEXT': os.getenv('DOCKERFILE_CONTEXT', ''),
'ENDPOINT': os.getenv('ENDPOINT', ''),
'TOKEN': os.getenv('TOKEN', ''),
'TENANT_ID': os.getenv('TENANT_ID', ''),
'IMAGE': os.getenv('IMAGE', ''),
'TAG': os.getenv('TAG', ''),
'SEVERITY': os.getenv('SEVERITY', ''),
'CODE': os.getenv('CODE', ''),
'LABEL': os.getenv('LABEL', '')
}
errors = validate_inputs(inputs)
if errors:
print("Input validation failed:")
for error in errors:
print(f"- {error}")
sys.exit(1)
else:
print("Input validation passed.")
sys.exit(0)
if __name__ == "__main__":
main()