24
24
import signal
25
25
26
26
from flask import Blueprint , request
27
+ import re
27
28
from freeseer import settings , logging
28
29
from freeseer .framework .config .exceptions import InvalidOptionValueError
29
30
from freeseer .framework .config .profile import ProfileDoesNotExist , ProfileAlreadyExists
@@ -90,19 +91,19 @@ def map_plugin_category(plugin_type):
90
91
return category
91
92
92
93
93
- def update_config (config , changes ):
94
+ def update_config (config , data ):
94
95
"""
95
- Helper to update Config instances with request data.
96
+ Updates given Config instance with request data.
96
97
"""
97
- for key , value in changes .items ():
98
+ for key , value in data .items ():
98
99
try :
99
100
opt_instance = config .options [key ]
100
101
value = opt_instance .decode (value )
101
102
setattr (config , key , value )
102
103
except KeyError :
103
104
raise HTTPError ('Invalid Option: {}' .format (key ), 400 )
104
105
except InvalidOptionValueError :
105
- raise HTTPError ('Invalid Value: {}' .format (value ), 400 )
106
+ raise HTTPError ('Invalid Value {} for option {} ' .format (value , key ), 400 )
106
107
config .save ()
107
108
108
109
@@ -172,7 +173,11 @@ def create_profile():
172
173
"""
173
174
Create new profile under 'name' specified in request arg.
174
175
"""
176
+ pattern = '^\w+$'
175
177
profile_name = request .form ['name' ]
178
+ if not re .match (pattern , profile_name ):
179
+ raise HTTPError ('Invalid Profile Name: {}' .format (profile_name ), 400 )
180
+
176
181
try :
177
182
settings .profile_manager .create (profile_name )
178
183
except ProfileAlreadyExists :
@@ -237,8 +242,6 @@ def modify_general_configuration(profile):
237
242
changes = request .form
238
243
update_config (profile_configuration , changes )
239
244
return ''
240
-
241
-
242
245
#
243
246
# General Configuration Endpoints
244
247
#
@@ -278,8 +281,6 @@ def modify_recording_configuration(profile):
278
281
changes = request .form
279
282
update_config (profile_configuration , changes )
280
283
return ''
281
-
282
-
283
284
#
284
285
# End recording configuration endpoints.
285
286
#
@@ -300,15 +301,15 @@ def list_plugin_category(profile, category):
300
301
return {
301
302
'plugins' : [plugin .name for plugin in plugin_infos ]
302
303
}
303
-
304
-
305
304
#
306
305
# End of plugin category endpoints.
307
306
#
308
307
309
308
#
310
309
# Plugin endpoints.
311
310
#
311
+
312
+
312
313
@configuration .route ('/profiles/<string:profile>/recording/<string:category>/<string:plugin>' , methods = ['GET' ])
313
314
@http_response (200 )
314
315
def list_plugin_instances (profile , category , plugin ):
@@ -360,7 +361,6 @@ def modify_plugin_instance(profile, category, plugin, id):
360
361
changes = request .form
361
362
update_config (plugin_object .config , changes )
362
363
return ''
363
-
364
364
#
365
365
# End of plugin endpoints.
366
366
#
0 commit comments