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