Browse Source

[broken] Fixes validator issues + confspec call

broken nginx conf + absolute path in slim that is known only at build time
Yann Weber 7 years ago
parent
commit
58b88b0b97
4 changed files with 25 additions and 5 deletions
  1. 18
    0
      lodel/settings/validator.py
  2. 2
    0
      plugins/webui/confspec.py
  3. 1
    1
      progs/mass_deploy.sh
  4. 4
    4
      progs/slim/slim.py

+ 18
- 0
lodel/settings/validator.py View File

@@ -171,12 +171,14 @@ def boolean_val(value):
171 171
         raise SettingsValidationError("A boolean was expected but got '%s' " % value)
172 172
     return bool(value)
173 173
 
174
+##@brief Validate a directory path
174 175
 def directory_val(value):
175 176
     res = SettingValidator('strip')(value)
176 177
     if not os.path.isdir(res):
177 178
         raise SettingsValidationError("Folowing path don't exists or is not a directory : '%s'"%res)
178 179
     return res
179 180
 
181
+##@brief Validate a loglevel value
180 182
 def loglevel_val(value):
181 183
     valids = ['DEBUG', 'INFO', 'SECURITY', 'ERROR', 'CRITICAL']
182 184
     if value.upper() not in valids:
@@ -184,23 +186,34 @@ def loglevel_val(value):
184 186
                 "The value '%s' is not a valid loglevel" % value)
185 187
     return value.upper()
186 188
 
189
+##@brief Validate a path
187 190
 def path_val(value):
188 191
     if value is None or not os.path.exists(value):
189 192
         raise SettingsValidationError(
190 193
                 "path '%s' doesn't exists" % value)
191 194
     return value
192 195
 
196
+##@brief Validate None
193 197
 def none_val(value):
194 198
     if value is None:
195 199
         return None
196 200
     raise SettingsValidationError("This settings cannot be set in configuration file")
197 201
 
202
+##@brief Validate a string
198 203
 def str_val(value):
199 204
     try:
200 205
         return str(value)
201 206
     except Exception as e:
202 207
         raise SettingsValidationError("Not able to convert value to string : " + str(e))
203 208
 
209
+##@brief Validate using a regex
210
+def regex_val(value, pattern):
211
+    if re.match(pattern, value) is None:
212
+        raise SettingsValidationError("The value '%s' is not validated by : \
213
+r\"%s\"" %(value, pattern))
214
+    return value
215
+
216
+##@brief Validate a hostname (ipv4 or ipv6)
204 217
 def host_val(value):
205 218
     if value == 'localhost':
206 219
         return value
@@ -352,6 +365,11 @@ SettingValidator.register_validator(
352 365
     emfield_val,
353 366
     'EmField name validator')
354 367
 
368
+SettingValidator.register_validator(
369
+    'regex',
370
+    regex_val,
371
+    'RegEx name validator (take re as argument)')
372
+
355 373
 SettingValidator.create_list_validator(
356 374
     'list',
357 375
     SettingValidator('strip'),

+ 2
- 0
plugins/webui/confspec.py View File

@@ -8,6 +8,8 @@ CONFSPEC = {
8 8
                             SettingValidator('dummy')),
9 9
         'listen_port': (    '9090',
10 10
                             SettingValidator('int')),
11
+        'static_url': (     'http://127.0.0.1/static/',
12
+                            SettingValidator('regex', pattern =  r'^https?://[^/].*$')),
11 13
         'virtualenv': (None,
12 14
                        SettingValidator('path', none_is_valid=True)),
13 15
         'uwsgicmd': ('/usr/bin/uwsgi', SettingValidator('dummy')),

+ 1
- 1
progs/mass_deploy.sh View File

@@ -112,7 +112,7 @@ for i in $(seq $ninstance)
112 112
 do
113 113
 	iname="${random_name}_$(printf "%05d" $i)"
114 114
 	slim -n $iname -c
115
-	slim -n $iname -s --interface web
115
+	slim -n $iname -s --interface web --static-url 'http://127.0.0.1/static'
116 116
 	slim -n $iname -m
117 117
 
118 118
 	#Mongo db database creation

+ 4
- 4
progs/slim/slim.py View File

@@ -394,7 +394,7 @@ server {
394 394
     include uwsgi_params;
395 395
     
396 396
     location /static/ {
397
-        alias /lodel2/plugins/webui/templates/
397
+        alias /lodel2/plugins/webui/templates/;
398 398
     }
399 399
 
400 400
 """
@@ -455,9 +455,6 @@ def get_parser():
455 455
     actions.add_argument('-m', '--make', metavar='TARGET', type=str,
456 456
         nargs="?", default='not',
457 457
         help='Run make for selected instances')
458
-    actions.add_argument('-t', '--static_url', type=str, nargs="?", 
459
-	default='http://127.0.0.1/static/', metavar='static_url',
460
-	help='Set an url for static documents')
461 458
     actions.add_argument('--nginx-conf', action='store_const',
462 459
         default = False, const=True,
463 460
         help="Output a conf for nginx given selected instances")
@@ -473,6 +470,9 @@ to 1 instance")
473 470
     confs.add_argument('--interface', type=str,
474 471
         help="Select wich interface to run. Possible values are \
475 472
 'python' and 'web'")
473
+    confs.add_argument('-t', '--static-url', type=str, nargs="?", 
474
+	default='http://127.0.0.1/static/', metavar='URL',
475
+	help='Set an url for static documents')
476 476
     confs.add_argument('--listen-port', type=int,
477 477
         help="Select the port on wich the web interface will listen to")
478 478
     confs.add_argument('--listen-address', type=str,

Loading…
Cancel
Save