Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _load_builtins(self, filtering, profile):
'''loads up builtin functions, so they can be filtered.'''
class Wrapper(object):
def __init__(self, name, plugin):
self.name = name
self.plugin = plugin
extman = extension_loader.MANAGER
blacklist = profile.get('blacklist')
if not blacklist: # not overridden by legacy data
blacklist = {}
for node, tests in extman.blacklist.items():
values = [t for t in tests if t['id'] in filtering]
if values:
blacklist[node] = values
if not blacklist:
return []
# this dresses up the blacklist to look like a plugin, but
# the '_checks' data comes from the blacklist information.
# the '_config' is the filtered blacklist data set.
blacklisting.blacklist._test_id = "B001"
blacklisting.blacklist._checks = blacklist.keys()
def test_get_config_settings(self):
config = {}
for plugin in extension_loader.MANAGER.plugins:
function = plugin.plugin
if hasattr(plugin.plugin, '_takes_config'):
module = importlib.import_module(function.__module__)
config[plugin.name] = module.gen_config(
function._takes_config)
settings = config_generator.get_config_settings()
self.assertEqual(yaml.safe_dump(config, default_flow_style=False),
settings)
tests = args.tests.split(',') if args.tests else []
for skip in skips:
if not extension_loader.MANAGER.check_id(skip):
raise RuntimeError('unknown ID in skips: %s' % skip)
for test in tests:
if not extension_loader.MANAGER.check_id(test):
raise RuntimeError('unknown ID in tests: %s' % test)
tpl = "# {0} : {1}"
test_list = [tpl.format(t.plugin._test_id, t.name)
for t in extension_loader.MANAGER.plugins]
others = [tpl.format(k, v['name']) for k, v in six.iteritems(
extension_loader.MANAGER.blacklist_by_id)]
test_list.extend(others)
test_list.sort()
contents = template.format(
cli=" ".join(sys.argv),
settings=yaml_settings,
test_list="\n".join(test_list),
skip='skips: ' + str(skips) if skips else 'skips:',
test='tests: ' + str(tests) if tests else 'tests:')
f.write(contents)
except IOError:
LOG.error("Unable to open %s for writing", args.output_file)
except Exception as e:
LOG.error("Error: %s", e)
def extract_flake8_bandit() -> Dict[str, str]:
from bandit.core.extension_loader import MANAGER
codes = dict()
for blacklist in MANAGER.blacklist.values():
for check in blacklist:
code = check['id'].replace('B', 'S')
codes[code] = check['message']
for plugin in MANAGER.plugins:
code = plugin.plugin._test_id.replace('B', 'S')
codes[code] = plugin.name.replace('_', ' ')
return codes
def extract_flake8_bandit() -> Dict[str, str]:
from bandit.core.extension_loader import MANAGER
codes = dict()
for blacklist in MANAGER.blacklist.values():
for check in blacklist:
code = check['id'].replace('B', 'S')
codes[code] = check['message']
for plugin in MANAGER.plugins:
code = plugin.plugin._test_id.replace('B', 'S')
codes[code] = plugin.name.replace('_', ' ')
return codes