Skip to content

Commit 3d42bca

Browse files
committed
remove unnecessary conversion to list
1 parent 5880645 commit 3d42bca

File tree

17 files changed

+42
-39
lines changed

17 files changed

+42
-39
lines changed

hubblestack/extmods/fileserver/s3fs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def _get_file():
683683
path_style=s3_key_kwargs['path_style'],
684684
https_enable=s3_key_kwargs['https_enable'])
685685
if ret:
686-
for header_name, header_value in list(ret['headers'].items()):
686+
for header_name, header_value in ret['headers'].items():
687687
header_name = header_name.strip()
688688
header_value = header_value.strip()
689689
if six.text_type(header_name).lower() == 'last-modified':

hubblestack/extmods/grains/cloud_details.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _get_aws_details():
7070
r = requests.get('http://169.254.169.254/latest/meta-data/local-hostname', headers=aws_token_header, timeout=3, proxies=proxies)
7171
if r.status_code == requests.codes.ok:
7272
aws_extra['cloud_private_hostname'] = r.text
73-
for key in list(aws_extra.keys()):
73+
for key in aws_extra.keys():
7474
if not aws_extra[key]:
7575
aws_extra.pop(key)
7676

hubblestack/extmods/modules/conf_publisher.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99

1010
log = logging.getLogger(__name__)
1111

12+
1213
def get_splunk_options(**kwargs):
1314
if not kwargs:
1415
kwargs['sourcetype'] = 'hubble_osquery'
1516
if '_nick' not in kwargs or not isinstance(kwargs['_nick'], dict):
1617
kwargs['_nick'] = {'sourcetype_nebula': 'sourcetype'}
1718
return gso(**kwargs)
1819

19-
def publish(report_directly_to_splunk=True, remove_dots=True, *args):
2020

21+
def publish(report_directly_to_splunk=True, remove_dots=True, *args):
2122
"""
2223
Publishes config to splunk at an interval defined in schedule
2324
@@ -44,7 +45,7 @@ def publish(report_directly_to_splunk=True, remove_dots=True, *args):
4445
opts_to_log.pop('grains')
4546
else:
4647
for arg in args:
47-
if arg in __opts__:
48+
if arg in __opts__:
4849
opts_to_log[arg] = __opts__[arg]
4950

5051
filtered_conf = hubblestack.log.filter_logs(opts_to_log, remove_dots=remove_dots)
@@ -63,7 +64,7 @@ def _filter_config(opts_to_log, remove_dots=True):
6364
patterns_to_filter = ["password", "token", "passphrase", "privkey", "keyid", "s3.key"]
6465
filtered_conf = _remove_sensitive_info(opts_to_log, patterns_to_filter)
6566
if remove_dots:
66-
for key in list(filtered_conf.keys()):
67+
for key in filtered_conf.keys():
6768
if '.' in key:
6869
filtered_conf[key.replace('.', '_')] = filtered_conf.pop(key)
6970
return filtered_conf

hubblestack/extmods/modules/hubble.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def _run_audit(configs, tags, debug, labels, **kwargs):
333333
for failure_index in reversed(sorted(set(failures_to_remove))):
334334
results['Failure'].pop(failure_index)
335335

336-
for key in list(results.keys()):
336+
for key in results.keys():
337337
if not results[key]:
338338
results.pop(key)
339339

@@ -581,7 +581,7 @@ def _clean_up_results(results, show_success):
581581
if show_success was not passed, adding an error message if
582582
results is empty
583583
"""
584-
for key in list(results.keys()):
584+
for key in results.keys():
585585
if not results[key]:
586586
results.pop(key)
587587

hubblestack/extmods/modules/pulsar.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,18 @@ def _wrapped(val):
558558
the_list = []
559559
for e in excludes:
560560
if isinstance(e,dict):
561-
if list(e.values())[0].get('regex'):
562-
r = list(e.keys())[0]
561+
first_val = list(e.values())[0]
562+
first_key = list(e.keys())[0]
563+
if first_val.get('regex'):
564+
r = first_key
563565
try:
564566
c = re.compile(r)
565567
the_list.append(re_wrapper(c))
566568
except Exception as e:
567-
log.warn('Failed to compile regex "%s": %s', r,e)
569+
log.warning('Failed to compile regex "%s": %s', r, e)
568570
continue
569571
else:
570-
e = list(e.keys())[0]
572+
e = first_key
571573
if '*' in e:
572574
the_list.append(fn_wrapper(e))
573575
else:
@@ -576,7 +578,7 @@ def _wrapped(val):
576578
# finally, wrap the whole decision set in a decision wrapper
577579
def _final(val):
578580
for i in the_list:
579-
if i( val ):
581+
if i(val):
580582
return True
581583
return False
582584
return _final
@@ -972,7 +974,7 @@ def _dict_update(dest, upd, recursive_update=True, merge_lists=False):
972974
return dest
973975
else:
974976
try:
975-
for k in list(upd.keys()):
977+
for k in upd.keys():
976978
dest[k] = upd[k]
977979
except AttributeError:
978980
# this mapping is not a dict

hubblestack/extmods/returners/graylog_nebula_return.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def returner(ret):
5353

5454
for opts in opts_list:
5555
for query in ret['return']:
56-
for query_name, value in list(query.items()):
56+
for query_name, value in query.items():
5757
for query_data in value['data']:
5858
args = {'query': query_name,
5959
'job_id': ret['jid'],

hubblestack/files/hubblestack_nova/misc.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def check_duplicate_uids(reason=''):
449449
"""
450450
uids = _execute_shell_command("cat /etc/passwd | cut -f3 -d\":\"", python_shell=True).strip()
451451
uids = uids.split('\n') if uids != "" else []
452-
duplicate_uids = [k for k, v in list(Counter(uids).items()) if v > 1]
452+
duplicate_uids = [k for k, v in Counter(uids).items() if v > 1]
453453
if duplicate_uids is None or duplicate_uids == []:
454454
return True
455455
return str(duplicate_uids)
@@ -461,7 +461,7 @@ def check_duplicate_gids(reason=''):
461461
"""
462462
gids = _execute_shell_command("cat /etc/group | cut -f3 -d\":\"", python_shell=True).strip()
463463
gids = gids.split('\n') if gids != "" else []
464-
duplicate_gids = [k for k, v in list(Counter(gids).items()) if v > 1]
464+
duplicate_gids = [k for k, v in Counter(gids).items() if v > 1]
465465
if duplicate_gids is None or duplicate_gids == []:
466466
return True
467467
return str(duplicate_gids)
@@ -473,7 +473,7 @@ def check_duplicate_unames(reason=''):
473473
"""
474474
unames = _execute_shell_command("cat /etc/passwd | cut -f1 -d\":\"", python_shell=True).strip()
475475
unames = unames.split('\n') if unames != "" else []
476-
duplicate_unames = [k for k, v in list(Counter(unames).items()) if v > 1]
476+
duplicate_unames = [k for k, v in Counter(unames).items() if v > 1]
477477
if duplicate_unames is None or duplicate_unames == []:
478478
return True
479479
return str(duplicate_unames)
@@ -485,7 +485,7 @@ def check_duplicate_gnames(reason=''):
485485
"""
486486
gnames = _execute_shell_command("cat /etc/group | cut -f1 -d\":\"", python_shell=True).strip()
487487
gnames = gnames.split('\n') if gnames != "" else []
488-
duplicate_gnames = [k for k, v in list(Counter(gnames).items()) if v > 1]
488+
duplicate_gnames = [k for k, v in Counter(gnames).items() if v > 1]
489489
if duplicate_gnames is None or duplicate_gnames == []:
490490
return True
491491
return str(duplicate_gnames)

hubblestack/files/hubblestack_nova/oval_scanner.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def audit(data_list, tags, labels, debug=False, **kwargs):
9090

9191
def parse_impact_report(report, local_pkgs, hubble_format, impacted_pkgs=[]):
9292
"""Parse into Hubble friendly format"""
93-
for key, value in list(report.items()):
93+
for key, value in report.items():
9494
pkg_desc = 'Vulnerable Package(s): '
9595
for pkg in value['installed']:
9696
pkg_desc += '{0}-{1}, '.format(pkg['name'], pkg['version'])
@@ -125,7 +125,7 @@ def get_impact_report(vulns, local_pkgs, distro_name):
125125
def build_impact(vulns, local_pkgs, distro_name, result={}):
126126
"""Build impacts based on pkg comparisons"""
127127
logging.debug('build_impact')
128-
for data in list(vulns.values()):
128+
for data in vulns.values():
129129
for pkg in data['pkg']:
130130
name = pkg['name']
131131
ver = pkg['version']
@@ -152,7 +152,7 @@ def build_impact(vulns, local_pkgs, distro_name, result={}):
152152
def build_impact_report(impact, report={}):
153153
"""Build a report based on impacts"""
154154
logging.debug('build_impact_report')
155-
for adv, detail in list(impact.items()):
155+
for adv, detail in impact.items():
156156
if adv not in report:
157157
report[adv] = {
158158
'updated_pkg': [],
@@ -187,7 +187,7 @@ def create_vulns(oval_and_maps, vulns={}):
187187
logging.debug('create_vulns')
188188
id_maps = oval_and_maps[0]
189189
oval = oval_and_maps[1]
190-
for definition, data in list(id_maps.items()):
190+
for definition, data in id_maps.items():
191191
if definition in oval['definitions']:
192192
vulns[definition] = oval['definitions'][definition]
193193
vulns[definition]['pkg'] = []
@@ -217,7 +217,7 @@ def create_vulns(oval_and_maps, vulns={}):
217217
def map_oval_ids(oval, id_maps={}):
218218
"""For every test, grab only tests with both state and obj references"""
219219
logging.debug('map_oval_ids')
220-
for definition, data in list(oval['definitions'].items()):
220+
for definition, data in oval['definitions'].items():
221221
id_maps[definition] = {'objects': []}
222222
objects = id_maps[definition]['objects']
223223
tests = data['tests']

hubblestack/files/hubblestack_nova/stat_nova.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def audit(data_list, tags, labels, debug=False, **kwargs):
112112
if e in tag_data:
113113
expected[e] = tag_data[e]
114114

115-
if 'allow_more_strict' in list(expected.keys()) and 'mode' not in list(expected.keys()):
115+
if 'allow_more_strict' in expected.keys() and 'mode' not in expected.keys():
116116
reason_dict = {}
117117
reason = "'allow_more_strict' tag can't be specified without 'mode' tag." \
118118
" Seems like a bug in hubble profile."
@@ -129,7 +129,7 @@ def audit(data_list, tags, labels, debug=False, **kwargs):
129129
if not salt_ret:
130130
if not expected:
131131
ret['Success'].append(tag_data)
132-
elif 'match_on_file_missing' in list(expected.keys()) and expected['match_on_file_missing']:
132+
elif 'match_on_file_missing' in expected.keys() and expected['match_on_file_missing']:
133133
ret['Success'].append(tag_data)
134134
else:
135135
tag_data['failure_reason'] = "Could not get access any file at '{0}'. " \
@@ -140,7 +140,7 @@ def audit(data_list, tags, labels, debug=False, **kwargs):
140140

141141
passed = True
142142
reason_dict = {}
143-
for e in list(expected.keys()):
143+
for e in expected.keys():
144144
if e == 'allow_more_strict' or e == 'match_on_file_missing':
145145
continue
146146
r = salt_ret[e]
@@ -149,7 +149,7 @@ def audit(data_list, tags, labels, debug=False, **kwargs):
149149
if r != '0':
150150
r = r[1:]
151151
allow_more_strict = False
152-
if 'allow_more_strict' in list(expected.keys()):
152+
if 'allow_more_strict' in expected.keys():
153153
allow_more_strict = expected['allow_more_strict']
154154
if not isinstance(allow_more_strict, bool):
155155
passed = False

hubblestack/files/hubblestack_nova/vulners_scanner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,5 @@ def _process_vulners(vulners):
139139

140140
return [{'tag': 'Vulnerable package: {0}'.format(pkg),
141141
'vulnerabilities': packages[pkg],
142-
'description': ', '.join(list(packages[pkg].keys()))}
142+
'description': ', '.join(packages[pkg].keys())}
143143
for pkg in packages]

hubblestack/files/hubblestack_nova/win_reg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def audit(data_list, tags, labels, debug=False, **kwargs):
9999
current = _find_option_value_in_reg(reg_dict['hive'], reg_dict['key'], reg_dict['value'])
100100
if isinstance(current, dict):
101101
tag_data['value_found'] = current
102-
if any(x is False for x in list(current.values())):
102+
if any(x is False for x in current.values()):
103103
ret['Failure'].append(tag_data)
104104
else:
105105
answer_list = []

hubblestack/hec/opt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _get_splunk_options(space, modality, **kw):
9898
else:
9999
final_opts[j] = opt[k]
100100

101-
if REQUIRED in list(final_opts.values()):
101+
if REQUIRED in final_opts.values():
102102
raise Exception('{0} must be specified in the {1} configs!'.format(req, space))
103103
ret.append(final_opts)
104104

hubblestack/log.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def filter_logs(opts_to_log, remove_dots=True):
207207
"""
208208
filtered_conf = _remove_sensitive_info(opts_to_log, PATTERNS_TO_FILTER)
209209
if remove_dots:
210-
for key in list(filtered_conf.keys()):
210+
for key in filtered_conf.keys():
211211
if '.' in key:
212212
filtered_conf[key.replace('.', '_')] = filtered_conf.pop(key)
213213
return filtered_conf

hubblestack/status.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def get_hubble_status_opt(name, require_type=None):
9090
return opts
9191

9292

93+
9394
def get_hubble_or_salt_opt(name):
9495
"""return the option specified by name found in __opts__ or __opts__['hubble'] """
9596
if name in __opts__:
@@ -100,6 +101,7 @@ def get_hubble_or_salt_opt(name):
100101
return None
101102

102103

104+
103105
class HubbleStatusResourceNotFound(Exception):
104106
""" Exception caused by trying to mark() a counter that wasn't explicitly defined
105107
"""
@@ -411,9 +413,7 @@ def inner(*a, **kw):
411413
ret = func(*a, **kw)
412414
stat_handle.fin()
413415
return ret
414-
415416
return inner
416-
417417
if invoke:
418418
return decorator(invoke)
419419
return decorator

tests/unittests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,4 @@ def pytest_sessionfinish(session, exitstatus):
240240
import subprocess
241241
p = subprocess.Popen(['chown', '-R', pcmf, sources_dir])
242242
p.communicate()
243-
print(('\nchowned back files to {}'.format(pcmf)))
243+
print('\nchowned back files to {}'.format(pcmf))

tests/unittests/test_counters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def __enter__(self):
133133
max_buckets = self.kwargs.pop('max_buckets', 1e3)
134134
namespace = self.kwargs.pop('namespace', 'x')
135135
if self.kwargs:
136-
raise ValueError('unknown arguments: {}', ', '.join(list(self.kwargs.keys())))
136+
raise ValueError('unknown arguments: {}', ', '.join(self.kwargs.keys()))
137137
opts = dict(bucket_len=bucket_len, max_buckets=max_buckets)
138138

139139
# setup hubble_status

utils/win_yaml_updater.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def ItemAdder(title, server, key, tag, match, vtype, desc,):
2828
print("There is more than 1 pdf in the folder")
2929
truefile = False
3030
while not truefile:
31-
filename = eval(input('Path to PDF: '))
31+
filename = input('Path to PDF: ')
3232
if os.path.isfile(filename):
3333
truefile = True
3434
else:
@@ -38,7 +38,7 @@ def ItemAdder(title, server, key, tag, match, vtype, desc,):
3838
else:
3939
truefile = False
4040
while not truefile:
41-
filename = eval(input('Path to PDF: '))
41+
filename = input('Path to PDF: ')
4242
if os.path.isfile(filename):
4343
truefile = True
4444
else:
@@ -80,7 +80,7 @@ def ItemAdder(title, server, key, tag, match, vtype, desc,):
8080
print("There is more than 1 pdf in the folder")
8181
truefile = False
8282
while not truefile:
83-
yamlname = eval(input('Path to YAML: '))
83+
yamlname = input('Path to YAML: ')
8484
if os.path.isfile(filename):
8585
truefile = True
8686
else:
@@ -90,7 +90,7 @@ def ItemAdder(title, server, key, tag, match, vtype, desc,):
9090
else:
9191
truefile = False
9292
while not truefile:
93-
yamlname = eval(input('Path to yaml: '))
93+
yamlname = input('Path to yaml: ')
9494
if os.path.isfile(filename):
9595
truefile = True
9696
else:

0 commit comments

Comments
 (0)