Passed
Push — master ( 5668a3...07978c )
by Konrad
08:41
created

db_sync_tool.utility.validation.check()   A

Complexity

Conditions 4

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 21
rs 9.5
c 0
b 0
f 0
cc 4
nop 1
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
91
    output.message(
92
        output.Subject.LOCAL,
93
        f'Validating configuration',
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
94
        True
95
    )
96
    v = validators.Draft7Validator(schema)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "v" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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)',
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
110
                do_print=False
111
            )
112
        )
113