Skip to content

Commit

Permalink
get boolean values in a proper way (#224)
Browse files Browse the repository at this point in the history
* get boolean values in a proper way

* fix tests
  • Loading branch information
afeena authored Jan 30, 2018
1 parent ba2f2ad commit 29d8a34
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bin/tanner
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
logger.Logger.create_logger(debug_log_file_name, error_log_file_name, __package__)
print("Debug logs will be stored in", debug_log_file_name)
print("Error logs will be stored in", error_log_file_name)
if TannerConfig.get('LOCALLOG', 'enabled') == True:
if TannerConfig.get('LOCALLOG', 'enabled') is True:
print("Data logs will be stored in", TannerConfig.get('LOCALLOG', 'PATH'))
tanner = server.TannerServer()
tanner.start()
Expand Down
37 changes: 27 additions & 10 deletions tanner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
'PHPOX': {'host': '0.0.0.0', 'port': 8088},
'REDIS': {'host': 'localhost', 'port': 6379, 'poolsize': 80, 'timeout': 1},
'EMULATORS': {'root_dir': '/opt/tanner'},
'EMULATOR_ENABLED': {'sqli': True, 'rfi': True, 'lfi': True, 'xss': True, 'cmd_exec': True, 'php_code_injection': True, "crlf":True},
'SQLI': {'type':'SQLITE', 'db_name': 'tanner_db', 'host':'localhost', 'user':'root', 'password':'user_pass'},
'EMULATOR_ENABLED': {'sqli': True, 'rfi': True, 'lfi': True, 'xss': True, 'cmd_exec': True,
'php_code_injection': True, "crlf": True},
'SQLI': {'type': 'SQLITE', 'db_name': 'tanner_db', 'host': 'localhost', 'user': 'root',
'password': 'user_pass'},
'DOCKER': {'host_image': 'busybox:latest'},
'LOGGER': {'log_debug': '/opt/tanner/tanner.log', 'log_err': '/opt/tanner/tanner.err'},
'MONGO': {'enabled': False, 'URI': 'mongodb://localhost'},
'HPFEEDS': {'enabled': False, 'HOST': 'localhost', 'PORT': 10000, 'IDENT': '', 'SECRET': '', 'CHANNEL': 'tanner.events'},
'HPFEEDS': {'enabled': False, 'HOST': 'localhost', 'PORT': 10000, 'IDENT': '', 'SECRET': '',
'CHANNEL': 'tanner.events'},
'LOCALLOG': {'enabled': False, 'PATH': '/tmp/tanner_report.json'},
'CLEANLOG': {'enabled': False}
}
Expand All @@ -39,25 +42,39 @@ def set_config(config_path):

@staticmethod
def get(section, value):
res = None
if TannerConfig.config is not None:
try:
convert_type = type(config_template[section][value])
res = convert_type(TannerConfig.config.get(section, value))
convert_type = type(config_template[section][value])
if convert_type is bool:
res = TannerConfig.config.getboolean(section, value)
else:
res = convert_type(TannerConfig.config.get(section, value))
except (configparser.NoOptionError, configparser.NoSectionError):
LOGGER.warning("Error in config, default value will be used. Section: %s Value: %s", section, value)
res = config_template[section][value]
return res

else:
return config_template[section][value]
res = config_template[section][value]
return res

@staticmethod
def get_section(section):
res = {}
if TannerConfig.config is not None:
try:
res = TannerConfig.config[section]
sec = TannerConfig.config[section]
for k, v in sec.items():
convert_type = type(config_template[section][k])
if convert_type is bool:
res[k] = TannerConfig.config[section].getboolean(k)
else:
res[k] = convert_type(v)
except (configparser.NoOptionError, configparser.NoSectionError):
LOGGER.warning("Error in config, default value will be used. Section: %s Value: %s", section)
res = config_template[section]
return res

else:
return config_template[section]
res = config_template[section]

return res
8 changes: 6 additions & 2 deletions tanner/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ def test_get_when_file_exists(self):
config.TannerConfig.config = self.cfg
for section in self.d:
for value, assertion_data in self.d[section].items():
data = config.TannerConfig.get(section, value)
convert_type = type(data)

convert_type = type(self.d[section][value])
if convert_type is bool:
data = config.TannerConfig.config.getboolean(section, value)
else:
data = config.TannerConfig.config.get(section, value)
self.assertEqual(data, convert_type(assertion_data))

def test_get_when_file_dont_exists(self):
Expand Down

0 comments on commit 29d8a34

Please sign in to comment.