1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: future_fstrings -*- |
3
|
|
|
|
4
|
|
|
""" |
5
|
|
|
Validation script |
6
|
|
|
""" |
7
|
|
|
|
8
|
|
|
import sys |
9
|
|
|
from jsonschema import validators |
10
|
|
|
from db_sync_tool.utility import output |
11
|
|
|
|
12
|
|
|
# |
13
|
|
|
# GLOBALS |
14
|
|
|
# |
15
|
|
|
schema = { |
16
|
|
|
"type": "object", |
17
|
|
|
"properties": { |
18
|
|
|
"type": {"enum": ['TYPO3', 'Symfony', 'Drupal', 'Wordpress', 'Laravel']}, |
19
|
|
|
"log_file": {"type": "string"}, |
20
|
|
|
"ignore_table": {"type": "array"}, |
21
|
|
|
"target": { |
22
|
|
|
"type": "object", |
23
|
|
|
"properties": { |
24
|
|
|
"name": {"type": "string"}, |
25
|
|
|
"host": {"type": "string", "format": "hostname"}, |
26
|
|
|
"user": {"type": "string"}, |
27
|
|
|
"password": {"type": "string"}, |
28
|
|
|
"path": {"type": "string"}, |
29
|
|
|
"ssh_key": {"type": "string"}, |
30
|
|
|
"port": {"type": "number"}, |
31
|
|
|
"dump_dir": {"type": "string"}, |
32
|
|
|
"after_dump": {"type": "string"}, |
33
|
|
|
"db": { |
34
|
|
|
"type": "object", |
35
|
|
|
"properties": { |
36
|
|
|
"name": {"type": "string"}, |
37
|
|
|
"host": {"type": "string", "format": "hostname"}, |
38
|
|
|
"user": {"type": "string"}, |
39
|
|
|
"password": {"type": "string"}, |
40
|
|
|
"port": {"type": "number"}, |
41
|
|
|
} |
42
|
|
|
}, |
43
|
|
|
"script": { |
44
|
|
|
"type": "object", |
45
|
|
|
"properties": { |
46
|
|
|
"before": {"type": "string"}, |
47
|
|
|
"after": {"type": "string"}, |
48
|
|
|
"error": {"type": "string"}, |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
}, |
53
|
|
|
"origin": { |
54
|
|
|
"type": "object", |
55
|
|
|
"properties": { |
56
|
|
|
"name": {"type": "string"}, |
57
|
|
|
"host": {"type": "string", "format": "hostname"}, |
58
|
|
|
"user": {"type": "string"}, |
59
|
|
|
"password": {"type": "string"}, |
60
|
|
|
"path": {"type": "string"}, |
61
|
|
|
"ssh_key": {"type": "string"}, |
62
|
|
|
"port": {"type": "number"}, |
63
|
|
|
"dump_dir": {"type": "string"}, |
64
|
|
|
"after_dump": {"type": "string"}, |
65
|
|
|
"db": { |
66
|
|
|
"type": "object", |
67
|
|
|
"properties": { |
68
|
|
|
"name": {"type": "string"}, |
69
|
|
|
"host": {"type": "string", "format": "hostname"}, |
70
|
|
|
"user": {"type": "string"}, |
71
|
|
|
"password": {"type": "string"}, |
72
|
|
|
"port": {"type": "number"}, |
73
|
|
|
} |
74
|
|
|
}, |
75
|
|
|
"script": { |
76
|
|
|
"type": "object", |
77
|
|
|
"properties": { |
78
|
|
|
"before": {"type": "string"}, |
79
|
|
|
"after": {"type": "string"}, |
80
|
|
|
"error": {"type": "string"}, |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
}, |
85
|
|
|
}, |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
# |
90
|
|
|
# FUNCTIONS |
91
|
|
|
# |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
def check(config): |
|
|
|
|
95
|
|
|
output.message( |
96
|
|
|
output.Subject.LOCAL, |
97
|
|
|
'Validating configuration', |
98
|
|
|
True |
99
|
|
|
) |
100
|
|
|
v = validators.Draft7Validator(schema) |
|
|
|
|
101
|
|
|
errors = sorted(v.iter_errors(config), key=lambda e: e.path) |
102
|
|
|
|
103
|
|
|
for error in errors: |
104
|
|
|
output.message( |
105
|
|
|
output.Subject.ERROR, |
106
|
|
|
f'{error.message}', |
107
|
|
|
True |
108
|
|
|
) |
109
|
|
|
if errors: |
110
|
|
|
sys.exit( |
111
|
|
|
output.message( |
112
|
|
|
output.Subject.ERROR, |
113
|
|
|
'Validation error(s)', |
114
|
|
|
do_print=False |
115
|
|
|
) |
116
|
|
|
) |
117
|
|
|
|