Rework logging using the stdlib machinery (#116)
* Rework logging using the stdlib machinery Use the verbose or debug flag to enable/disable logging.DEBUG Remove the vprint function from all classes Remove bcolors from all code Cleanup [INFO], [ERROR], {success} and similar * fix some errors my local linter missed but travis catched * add coloredlogs and --fancy command line flag
This commit is contained in:

committed by
Austin Taylor

parent
46955bff75
commit
e3e416fe44
@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
# Support for python3
|
||||
if (sys.version_info > (3, 0)):
|
||||
@ -14,44 +15,49 @@ class vwConfig(object):
|
||||
self.config_in = config_in
|
||||
self.config = cp.RawConfigParser()
|
||||
self.config.read(self.config_in)
|
||||
self.logger = logging.getLogger('vwConfig')
|
||||
|
||||
def get(self, section, option):
|
||||
self.logger.debug('Calling get for {}:{}'.format(section, option))
|
||||
return self.config.get(section, option)
|
||||
|
||||
def getbool(self, section, option):
|
||||
self.logger.debug('Calling getbool for {}:{}'.format(section, option))
|
||||
return self.config.getboolean(section, option)
|
||||
|
||||
def get_enabled(self):
|
||||
enabled = []
|
||||
# TODO: does this not also need the "yes" case?
|
||||
check = ["true", "True", "1"]
|
||||
for section in self.config.sections():
|
||||
try:
|
||||
if self.get(section, "enabled") in check:
|
||||
enabled.append(section)
|
||||
except:
|
||||
print "[INFO] Section {} has no option 'enabled'".format(section)
|
||||
self.logger.error("Section {} has no option 'enabled'".format(section))
|
||||
return enabled
|
||||
|
||||
def exists_jira_profiles(self, profiles):
|
||||
# get list of profiles source_scanner.scan_name
|
||||
for profile in profiles:
|
||||
if not self.config.has_section(self.normalize_section(profile)):
|
||||
print "[INFO] JIRA Scan Profile missing"
|
||||
self.logger.warn("JIRA Scan Profile missing")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def update_jira_profiles(self, profiles):
|
||||
# create JIRA profiles in the ini config file
|
||||
self.logger.debug('Updating Jira profiles: {}'.format(str(profiles)))
|
||||
|
||||
for profile in profiles:
|
||||
#IMPORTANT profile scans/results will be normalized to lower and "_" instead of spaces for ini file section
|
||||
section_name = self.normalize_section(profile)
|
||||
try:
|
||||
self.get(section_name, "source")
|
||||
print "Skipping creating of section '{}'; already exists".format(section_name)
|
||||
self.logger.info("Skipping creating of section '{}'; already exists".format(section_name))
|
||||
except:
|
||||
print "Creating config section for '{}'".format(section_name)
|
||||
self.logger.warn("Creating config section for '{}'".format(section_name))
|
||||
self.config.add_section(section_name)
|
||||
self.config.set(section_name,'source',profile.split('.')[0])
|
||||
# in case any scan name contains '.' character
|
||||
@ -62,12 +68,16 @@ class vwConfig(object):
|
||||
self.config.set(section_name,'; minimum criticality to report (low, medium, high or critical)')
|
||||
self.config.set(section_name,'min_critical_to_report', 'high')
|
||||
|
||||
# TODO: try/catch this
|
||||
# writing changes back to file
|
||||
with open(self.config_in, 'w') as configfile:
|
||||
self.config.write(configfile)
|
||||
self.logger.debug('Written configuration to {}'.format(self.config_in))
|
||||
|
||||
# FIXME: this is the same as return None, that is the default return for return-less functions
|
||||
return
|
||||
|
||||
def normalize_section(self, profile):
|
||||
profile = "jira.{}".format(profile.lower().replace(" ","_"))
|
||||
self.logger.debug('Normalized profile as: {}'.format(profile))
|
||||
return profile
|
||||
|
Reference in New Issue
Block a user