-
Notifications
You must be signed in to change notification settings - Fork 0
/
presubmit.py
executable file
·48 lines (38 loc) · 1.4 KB
/
presubmit.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
#!/usr/bin/env python3
"""
DNSControl presubmit script
Run before submitting, hence the pre prefix...
"""
class TestFailureError(Exception):
"""Raised when Presubmit test case failed"""
pass
import json
import sys
def check_credentials_for_secrets():
"""check_credentials_for_secrets ensures only environment variables are present
in creds.json
:rasies:
TestFailureError: If any key within a credential provider does not start with a $ indicating it is not an environment variable
"""
creds_file="creds.json"
with open(creds_file, "r") as creds:
creds_data = json.load(creds)
for provider in creds_data:
if not all(i == '$' for i in [n[:1] for n in creds_data[provider].values()]):
raise TestFailureError(
"""check_credentials_for_secrets failed.
Ensure credential values are all environtment
variables beginning with '$'""")
def main():
print("Running Presubmit Checks...")
# List of check functions to run, easily amended, just add function name
presubmit_checks = [
check_credentials_for_secrets,
]
# Run each check in the list
[check() for check in presubmit_checks]
# If a check failed then it should raise an exception, else pass.
print("No Errors Raise, must have passed")
sys.exit()
if __name__ == "__main__":
main()