1+ """This class is used to validate the config"""
2+
13import logging
24
3- ''' This class is used to validate the config
4- '''
5+
56class Schema :
67 def _validate (self ):
78 pass
89
910 def __hyphen_to_underscore (self , k ):
10- return k .replace ('-' , '_' )
11+ return k .replace ("-" , "_" )
1112
1213 def _populate (self , data , definition ):
1314 try :
14- for ( k , v ) in data .items ():
15+ for k , v in data .items ():
1516 k = self .__hyphen_to_underscore (k )
1617 if k in definition :
1718 vtype = definition [k ]
@@ -30,59 +31,59 @@ def _populate(self, data, definition):
3031
3132 def _assert_non_empty (self , * attrs ):
3233 for attr in attrs :
33- assert len (getattr (self , attr )) > 0 , "{}.{} must not be empty" .format (type (self ).__name__ , attr )
34+ assert len (getattr (self , attr )) > 0 , "{}.{} must not be empty" .format (
35+ type (self ).__name__ , attr
36+ )
3437
3538 def _assert_non_null (self , * attrs ):
3639 for attr in attrs :
37- assert getattr (self , attr ) is not None , "{}.{} must not be None" .format (type (self ).__name__ , attr )
40+ assert getattr (self , attr ) is not None , "{}.{} must not be None" .format (
41+ type (self ).__name__ , attr
42+ )
3843
3944
4045class InterceptQuerySettings (Schema ):
4146 def __init__ (self , data ):
4247 self .plugin = None
4348 self .function = None
4449
45- self ._populate (data , {
46- 'plugin' : str ,
47- 'function' : str
48- })
50+ self ._populate (data , {"plugin" : str , "function" : str })
4951
5052 def _validate (self ):
51- self ._assert_non_null (' plugin' , ' function' )
52- self ._assert_non_empty (' plugin' , ' function' )
53+ self ._assert_non_null (" plugin" , " function" )
54+ self ._assert_non_empty (" plugin" , " function" )
5355
5456
5557class InterceptCommandSettings (Schema ):
5658 def __init__ (self , data ):
5759 self .queries = []
5860 self .connects = None
5961
60- self ._populate (data , {
61- 'queries' : [InterceptQuerySettings ],
62- 'connects' : str
63- })
62+ self ._populate (data , {"queries" : [InterceptQuerySettings ], "connects" : str })
6463
6564
6665class InterceptResponseSettings (Schema ):
6766 def __init__ (self , data ):
6867 self .parameter_responses = []
6968 self .connects = None
7069
71- self ._populate (data , {
72- 'parameter_status' : [InterceptQuerySettings ],
73- 'connects' : str
74- })
70+ self ._populate (
71+ data , {"parameter_status" : [InterceptQuerySettings ], "connects" : str }
72+ )
7573
7674
7775class InterceptSettings (Schema ):
7876 def __init__ (self , data ):
7977 self .commands = None
8078 self .responses = None
8179
82- self ._populate (data , {
83- 'commands' : InterceptCommandSettings ,
84- 'responses' : InterceptResponseSettings ,
85- })
80+ self ._populate (
81+ data ,
82+ {
83+ "commands" : InterceptCommandSettings ,
84+ "responses" : InterceptResponseSettings ,
85+ },
86+ )
8687
8788
8889class Connection (Schema ):
@@ -91,15 +92,11 @@ def __init__(self, data):
9192 self .host = None
9293 self .port = None
9394
94- self ._populate (data , {
95- 'name' : str ,
96- 'host' : str ,
97- 'port' : int
98- })
95+ self ._populate (data , {"name" : str , "host" : str , "port" : int })
9996
10097 def _validate (self ):
101- self ._assert_non_null (' name' , ' host' , ' port' )
102- self ._assert_non_empty (' name' )
98+ self ._assert_non_null (" name" , " host" , " port" )
99+ self ._assert_non_empty (" name" )
103100
104101
105102class InstanceSettings (Schema ):
@@ -108,15 +105,17 @@ def __init__(self, data):
108105 self .redirect = None
109106 self .intercept = None
110107
111- self ._populate (data , {
112- 'listen' : Connection ,
113- 'redirect' : Connection ,
114- 'intercept' : InterceptSettings
115- })
116-
108+ self ._populate (
109+ data ,
110+ {
111+ "listen" : Connection ,
112+ "redirect" : Connection ,
113+ "intercept" : InterceptSettings ,
114+ },
115+ )
117116
118117 def _validate (self ):
119- self ._assert_non_null (' listen' , ' redirect' )
118+ self ._assert_non_null (" listen" , " redirect" )
120119
121120
122121class Settings (Schema ):
@@ -125,15 +124,13 @@ def __init__(self, data):
125124 self .intercept_log = None
126125 self .general_log = None
127126
128- self ._populate (data , {
129- 'log_level' : str ,
130- 'intercept_log' : str ,
131- 'general_log' : str
132- })
127+ self ._populate (
128+ data , {"log_level" : str , "intercept_log" : str , "general_log" : str }
129+ )
133130
134131 def _validate (self ):
135- self ._assert_non_null (' log_level' , ' intercept_log' , ' general_log' )
136- self ._assert_non_empty (' log_level' , ' intercept_log' , ' general_log' )
132+ self ._assert_non_null (" log_level" , " intercept_log" , " general_log" )
133+ self ._assert_non_empty (" log_level" , " intercept_log" , " general_log" )
137134
138135
139136class Config (Schema ):
@@ -142,11 +139,10 @@ def __init__(self, data):
142139 self .settings = None
143140 self .instances = []
144141
145- self ._populate (data , {
146- 'plugins' : [str ],
147- 'settings' : Settings ,
148- 'instances' : [InstanceSettings ]
149- })
142+ self ._populate (
143+ data ,
144+ {"plugins" : [str ], "settings" : Settings , "instances" : [InstanceSettings ]},
145+ )
150146
151147 def _validate (self ):
152- self ._assert_non_empty (' instances' )
148+ self ._assert_non_empty (" instances" )
0 commit comments