def load_toml_rest_api_config(filename):
"""Returns a RestApiConfig created by loading a TOML file from the
filesystem.
"""
if not os.path.exists(filename):
LOGGER.info(
"Skipping rest api loading from non-existent config file: %s",
filename)
return RestApiConfig()
LOGGER.info("Loading rest api information from config: %s", filename)
try:
with open(filename) as fd:
raw_config = fd.read()
except IOError as e:
raise RestApiConfigurationError(
"Unable to load rest api configuration file: {}".format(str(e)))
toml_config = toml.loads(raw_config)
invalid_keys = set(toml_config.keys()).difference(
['bind', 'connect', 'timeout', 'opentsdb_db', 'opentsdb_url',
'opentsdb_username', 'opentsdb_password'])
if invalid_keys:
raise RestApiConfigurationError(
"Invalid keys in rest api config: {}".format(
", ".join(sorted(list(invalid_keys)))))
config = RestApiConfig(
bind=toml_config.get("bind", None),
connect=toml_config.get('connect', None),
timeout=toml_config.get('timeout', None),
opentsdb_url=toml_config.get('opentsdb_url', None),
opentsdb_db=toml_config.get('opentsdb_db', None),
opentsdb_username=toml_config.get('opentsdb_username', None),
opentsdb_password=toml_config.get('opentsdb_password', None),
)
return config
评论列表
文章目录