-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_archivers.py
77 lines (64 loc) · 2.08 KB
/
validate_archivers.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Check archive configurations
"""
import argparse
import json
parser = argparse.ArgumentParser(
description='Validating the archiver fields')
parser.add_argument(
'config_file', action='store', help='config.json')
# parser.add_argument(
# 'ref_file', action='store', help='archivers_refs.json')
args = parser.parse_args()
archivers_refs = {
"bitbucket": {
"required": [],
"optional": []
},
"failer": {
"required": ["fail", "retry"],
"optional": []
},
"http": {
"required": ["_url"],
"optional": ["op", "headers", "bind", "retry-policy"]
},
"kafka": {
"required": ["topic", "server"],
"optional": []
},
"rabbitmq": {
"required": ["_url"],
"optional": ["exchange", "routing-key", "connection-lifetime", "retry-policy"]
},
"syslog": {
"required": [],
"optional": ["ident", "facility", "priority"]
}
}
def check(config_archive, archiver_name):
"""Validates each defined archiver."""
try:
required = archivers_refs[archiver_name]['required']
all_keys = required + archivers_refs[archiver_name]['optional']
except KeyError:
print("'{}' is not a valid archiver name".format(archiver_name))
exit(1)
for each_key in required:
if each_key not in config_archive['data'].keys():
print("'{}' archiver must include '{}' key"
.format(archiver_name, each_key))
exit(1)
for each_key in config_archive['data'].keys():
if each_key not in all_keys:
print("'{}' archiver includes invalid key '{}'"
.format(archiver_name, each_key))
exit(1)
config = json.loads(open(args.config_file, 'r').read())
# archivers_refs = json.loads(open(args.ref_file, 'r').read())
# Checks if archives is defined in config file
if 'archives' not in config:
exit(0)
archivers = config['archives']
for archive in archivers.values():
check(archive, archive['archiver'])