-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.py
49 lines (38 loc) · 1.64 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import yaml
from StringIO import StringIO
from werkzeug.exceptions import BadRequest
from yandextank.config_converter.converter import ConversionError
from yandextank.core.consoleworker import load_core_base_cfg, load_local_base_cfgs, convert_ini
from yandextank.validator.validator import TankConfig
def response(full_cfg, errors):
return {'config': full_cfg, 'errors': errors}
def get_validation_result(cfg):
config, errors, configinitial = TankConfig([load_core_base_cfg()] +
load_local_base_cfgs() +
[cfg],
with_dynamic_options=False).validate()
return response(configinitial, errors)
def validate_config(config, fmt):
if fmt == 'ini':
stream = StringIO(str(config.read()))
config.close()
try:
return get_validation_result(convert_ini(stream))
except ConversionError as e:
return response({}, [e.message])
except Exception as e:
logging.error('Exception during reading Tank config', exc_info=True)
raise BadRequest('{}'.format(e))
else:
try:
return get_validation_result(yaml.load(config))
except Exception as e:
logging.error('Exception during reading Tank config', exc_info=True)
raise BadRequest('{}'.format(e))
def validate_config_json(config):
try:
return get_validation_result(config)
except Exception as e:
logging.error('Exception during reading Tank config', exc_info=True)
raise BadRequest('{}'.format(e))