Browse Source

[broken] Fixes validator issues + confspec call

broken nginx conf + absolute path in slim that is known only at build time
Yann Weber 8 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
         raise SettingsValidationError("A boolean was expected but got '%s' " % value)
171
         raise SettingsValidationError("A boolean was expected but got '%s' " % value)
172
     return bool(value)
172
     return bool(value)
173
 
173
 
174
+##@brief Validate a directory path
174
 def directory_val(value):
175
 def directory_val(value):
175
     res = SettingValidator('strip')(value)
176
     res = SettingValidator('strip')(value)
176
     if not os.path.isdir(res):
177
     if not os.path.isdir(res):
177
         raise SettingsValidationError("Folowing path don't exists or is not a directory : '%s'"%res)
178
         raise SettingsValidationError("Folowing path don't exists or is not a directory : '%s'"%res)
178
     return res
179
     return res
179
 
180
 
181
+##@brief Validate a loglevel value
180
 def loglevel_val(value):
182
 def loglevel_val(value):
181
     valids = ['DEBUG', 'INFO', 'SECURITY', 'ERROR', 'CRITICAL']
183
     valids = ['DEBUG', 'INFO', 'SECURITY', 'ERROR', 'CRITICAL']
182
     if value.upper() not in valids:
184
     if value.upper() not in valids:
184
                 "The value '%s' is not a valid loglevel" % value)
186
                 "The value '%s' is not a valid loglevel" % value)
185
     return value.upper()
187
     return value.upper()
186
 
188
 
189
+##@brief Validate a path
187
 def path_val(value):
190
 def path_val(value):
188
     if value is None or not os.path.exists(value):
191
     if value is None or not os.path.exists(value):
189
         raise SettingsValidationError(
192
         raise SettingsValidationError(
190
                 "path '%s' doesn't exists" % value)
193
                 "path '%s' doesn't exists" % value)
191
     return value
194
     return value
192
 
195
 
196
+##@brief Validate None
193
 def none_val(value):
197
 def none_val(value):
194
     if value is None:
198
     if value is None:
195
         return None
199
         return None
196
     raise SettingsValidationError("This settings cannot be set in configuration file")
200
     raise SettingsValidationError("This settings cannot be set in configuration file")
197
 
201
 
202
+##@brief Validate a string
198
 def str_val(value):
203
 def str_val(value):
199
     try:
204
     try:
200
         return str(value)
205
         return str(value)
201
     except Exception as e:
206
     except Exception as e:
202
         raise SettingsValidationError("Not able to convert value to string : " + str(e))
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
 def host_val(value):
217
 def host_val(value):
205
     if value == 'localhost':
218
     if value == 'localhost':
206
         return value
219
         return value
352
     emfield_val,
365
     emfield_val,
353
     'EmField name validator')
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
 SettingValidator.create_list_validator(
373
 SettingValidator.create_list_validator(
356
     'list',
374
     'list',
357
     SettingValidator('strip'),
375
     SettingValidator('strip'),

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

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

+ 1
- 1
progs/mass_deploy.sh View File

112
 do
112
 do
113
 	iname="${random_name}_$(printf "%05d" $i)"
113
 	iname="${random_name}_$(printf "%05d" $i)"
114
 	slim -n $iname -c
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
 	slim -n $iname -m
116
 	slim -n $iname -m
117
 
117
 
118
 	#Mongo db database creation
118
 	#Mongo db database creation

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

394
     include uwsgi_params;
394
     include uwsgi_params;
395
     
395
     
396
     location /static/ {
396
     location /static/ {
397
-        alias /lodel2/plugins/webui/templates/
397
+        alias /lodel2/plugins/webui/templates/;
398
     }
398
     }
399
 
399
 
400
 """
400
 """
455
     actions.add_argument('-m', '--make', metavar='TARGET', type=str,
455
     actions.add_argument('-m', '--make', metavar='TARGET', type=str,
456
         nargs="?", default='not',
456
         nargs="?", default='not',
457
         help='Run make for selected instances')
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
     actions.add_argument('--nginx-conf', action='store_const',
458
     actions.add_argument('--nginx-conf', action='store_const',
462
         default = False, const=True,
459
         default = False, const=True,
463
         help="Output a conf for nginx given selected instances")
460
         help="Output a conf for nginx given selected instances")
473
     confs.add_argument('--interface', type=str,
470
     confs.add_argument('--interface', type=str,
474
         help="Select wich interface to run. Possible values are \
471
         help="Select wich interface to run. Possible values are \
475
 'python' and 'web'")
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
     confs.add_argument('--listen-port', type=int,
476
     confs.add_argument('--listen-port', type=int,
477
         help="Select the port on wich the web interface will listen to")
477
         help="Select the port on wich the web interface will listen to")
478
     confs.add_argument('--listen-address', type=str,
478
     confs.add_argument('--listen-address', type=str,

Loading…
Cancel
Save