Skip to content

Commit

Permalink
change syntax to make it compatible with python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenebriso committed Oct 21, 2019
1 parent 3176111 commit f25c58b
Show file tree
Hide file tree
Showing 79 changed files with 301 additions and 299 deletions.
18 changes: 9 additions & 9 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@
master_doc = 'index'

# General information about the project.
project = u'HubbleStack'
copyright = u'2018, Colton Myers, Christer Edwards'
author = u'Colton Myers, Christer Edwards'
project = 'HubbleStack'
copyright = '2018, Colton Myers, Christer Edwards'
author = 'Colton Myers, Christer Edwards'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'3.0.7'
version = '3.0.7'
# The full version, including alpha/beta/rc tags.
release = u'3.0.7-1'
release = '3.0.7-1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -140,8 +140,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'HubbleStack.tex', u'HubbleStack Documentation',
u'Colton Myers, Christer Edwards', 'manual'),
(master_doc, 'HubbleStack.tex', 'HubbleStack Documentation',
'Colton Myers, Christer Edwards', 'manual'),
]


Expand All @@ -150,7 +150,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'hubblestack', u'HubbleStack Documentation',
(master_doc, 'hubblestack', 'HubbleStack Documentation',
[author], 1)
]

Expand All @@ -161,7 +161,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'HubbleStack', u'HubbleStack Documentation',
(master_doc, 'HubbleStack', 'HubbleStack Documentation',
author, 'HubbleStack', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
6 changes: 3 additions & 3 deletions hubblestack/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""


from __future__ import print_function


# import lockfile
import argparse
Expand Down Expand Up @@ -310,7 +310,7 @@ def schedule():
schedule_config = __opts__.get('schedule', {})
if 'user_schedule' in __opts__ and isinstance(__opts__['user_schedule'], dict):
schedule_config.update(__opts__['user_schedule'])
for jobname, jobdata in schedule_config.iteritems():
for jobname, jobdata in schedule_config.items():
# Error handling galore
if not jobdata or not isinstance(jobdata, dict):
log.error('Scheduled job {0} does not have valid data'.format(jobname))
Expand Down Expand Up @@ -813,7 +813,7 @@ def emit_to_syslog(grains_to_emit):
for grain in grains_to_emit:
if grain in __grains__:
if bool(__grains__[grain]) and isinstance(__grains__[grain], dict):
for key, value in __grains__[grain].iteritems():
for key, value in __grains__[grain].items():
syslog_list.append('{0}={1}'.format(key, value))
else:
syslog_list.append('{0}={1}'.format(grain, __grains__[grain]))
Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/audit/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
True/False. Whether to use multiline flag for regex matching with
match_output_regex set to True. Defaults to True.
"""
from __future__ import absolute_import


import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/fdg/curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
a system, we don't want an attacker to be able to send that data to arbitrary
endpoints.
"""
from __future__ import absolute_import

import logging
import requests

Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/fdg/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This fdg module allows for grepping against files and strings
"""
from __future__ import absolute_import

import logging
import os.path

Expand Down
6 changes: 3 additions & 3 deletions hubblestack/extmods/fdg/osquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This fdg module allows for running osquery queries
"""
from __future__ import absolute_import

import json
import logging
import os
Expand Down Expand Up @@ -91,8 +91,8 @@ def _osquery(query_sql, osquery_path=None, args=None):
if res['retcode'] == 0:
ret = json.loads(res['stdout'])
for result in ret:
for key, value in result.iteritems():
if value and isinstance(value, basestring) and value.startswith('__JSONIFY__'):
for key, value in result.items():
if value and isinstance(value, str) and value.startswith('__JSONIFY__'):
result[key] = json.loads(value[len('__JSONIFY__'):])
return True, ret
return False, res['stdout']
14 changes: 7 additions & 7 deletions hubblestack/extmods/fdg/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
This module primarily processes and properly format
the data outputted by a module to serve it to another module.
"""
from __future__ import absolute_import


import logging
import re
Expand Down Expand Up @@ -72,9 +72,9 @@ def _filter_dict(dct,
not equal to 2.
"""
ret = dct
for comp, value in filter_rules.iteritems():
for comp, value in filter_rules.items():
try:
ret = {key: val for key, val in ret.iteritems()
ret = {key: val for key, val in ret.items()
if (filter_values and _compare(comp, val, value)) or
(not filter_values and _compare(comp, key, value))}
except ArgumentValueError:
Expand Down Expand Up @@ -174,7 +174,7 @@ def _filter(seq,
LOG.error("``filter_rules`` should be of type dict")
return None
ret = seq
for comp, value in filter_rules.iteritems():
for comp, value in filter_rules.items():
try:
ret = [x for x in ret if _compare(comp, x, value)]
except ArgumentValueError:
Expand Down Expand Up @@ -428,7 +428,7 @@ def dict_to_list(starting_dict=None, update_chained=True, chained=None, chained_
except (AttributeError, ValueError, TypeError):
LOG.error("Invalid arguments type.", exc_info=True)
return False, None
ret = [(key, value) for key, value in chained.iteritems()]
ret = [(key, value) for key, value in chained.items()]
status = bool(ret)

return status, ret
Expand Down Expand Up @@ -482,7 +482,7 @@ def _dict_convert_none(dictionary):
LOG.error("Invalid argument type - should be dict")
return None
updated_dict = {}
for key, value in dictionary.iteritems():
for key, value in dictionary.items():
if value == '':
updated_dict[key] = None
elif isinstance(value, dict):
Expand Down Expand Up @@ -594,7 +594,7 @@ def _sterilize_dict(dictionary):
LOG.error("Invalid argument type - should be dict")
return None
updated_dict = {}
for key, value in dictionary.iteritems():
for key, value in dictionary.items():
if isinstance(value, dict):
updated_dict[key] = _sterilize_dict(value)
elif isinstance(value, (set, list, tuple)):
Expand Down
4 changes: 2 additions & 2 deletions hubblestack/extmods/fdg/process_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
processes, with various options for filtering
"""

from __future__ import absolute_import

import logging


Expand Down Expand Up @@ -45,7 +45,7 @@ def _convert_to_str(process_data):
ret = []
try:
for process in process_data:
str_process = {str(name): str(val) for name, val in process.iteritems()}
str_process = {str(name): str(val) for name, val in process.items()}
ret.append(str_process)
except (TypeError, AttributeError):
LOG.error('Invalid argument type; must be list of dicts.', exc_info=True)
Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/fdg/readfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This fdg module allows for reading in the contents of files, with various
options for format and filtering.
"""
from __future__ import absolute_import


import json as _json
import logging
Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/fdg/time_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
NTP servers for differences bigger than 15 minutes.
'''

from __future__ import absolute_import

import logging
import salt.utils.platform

Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/fileserver/azurefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"""

# Import python libs
from __future__ import absolute_import

from distutils.version import LooseVersion
import base64
import json
Expand Down
4 changes: 2 additions & 2 deletions hubblestack/extmods/fileserver/s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"""

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import datetime
import os
import time
Expand Down Expand Up @@ -683,7 +683,7 @@ def _get_file():
path_style=s3_key_kwargs['path_style'],
https_enable=s3_key_kwargs['https_enable'])
if ret:
for header_name, header_value in ret['headers'].items():
for header_name, header_value in list(ret['headers'].items()):
header_name = header_name.strip()
header_value = header_value.strip()
if six.text_type(header_name).lower() == 'last-modified':
Expand Down
6 changes: 3 additions & 3 deletions hubblestack/extmods/grains/cloud_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _get_aws_details():
r = requests.get('http://169.254.169.254/latest/meta-data/local-hostname', timeout=3, proxies=proxies)
if r.status_code == requests.codes.ok:
aws_extra['cloud_private_hostname'] = r.text
for key in aws_extra.keys():
for key in list(aws_extra.keys()):
if not aws_extra[key]:
aws_extra.pop(key)

Expand Down Expand Up @@ -123,7 +123,7 @@ def _get_azure_details():
grain_name_mac = "cloud_interface_{0}_mac_address".format(counter)
azure_extra[grain_name_mac] = value['macAddress']

for key in azure_extra.keys():
for key in list(azure_extra.keys()):
if not azure_extra[key]:
azure_extra.pop(key)

Expand Down Expand Up @@ -194,7 +194,7 @@ def _get_gcp_details():
external_ips_list = [ item['externalIp'] for item in value['accessConfigs'] if 'externalIp' in item ]
gcp_extra[grain_name_accessconfig_external_ips] = ','.join(external_ips_list)

for key in gcp_extra.keys():
for key in list(gcp_extra.keys()):
if not gcp_extra[key]:
gcp_extra.pop(key)

Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/grains/configgrains.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def configgrains():

grains_to_make = __salt__['config.get']('config_to_grains', default=[])
for grain in grains_to_make:
for k, v in grain.iteritems():
for k, v in grain.items():
grain_value = __salt__['config.get'](v, default=None)
if grain_value:
grains[k] = grain_value
Expand Down
2 changes: 1 addition & 1 deletion hubblestack/extmods/grains/default_gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ip6_gw: True # True/False if default ipv6 gateway
ip_gw: True # True if either of the above is True, False otherwise
"""
from __future__ import absolute_import


import logging

Expand Down
6 changes: 3 additions & 3 deletions hubblestack/extmods/grains/fqdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def dest_ip():
# Fallback to "best guess"
filtered_interfaces = {}
# filter out empty, lo, and docker0
for interface, ips in interfaces.iteritems():
for interface, ips in interfaces.items():
if not ips:
continue
if interface in ('lo', 'docker0'):
Expand All @@ -64,13 +64,13 @@ def dest_ip():
if ip != '127.0.0.1':
return {'local_ip4': ip}
# Use .*0 if present
for interface, ips in filtered_interfaces.iteritems():
for interface, ips in filtered_interfaces.items():
if '0' in interface:
for ip in ips:
if ip != '127.0.0.1':
return {'local_ip4': ip}
# Use whatever isn't 127.0.0.1
for interface, ips in filtered_interfaces.iteritems():
for interface, ips in filtered_interfaces.items():
for ip in ips:
if ip != '127.0.0.1':
return {'local_ip4': ip}
Expand Down
10 changes: 5 additions & 5 deletions hubblestack/extmods/modules/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
it was a success or a failure, and ``data_dict`` is a dictionary of any
information that should be added to the check's data dictionary in the return.
"""
from __future__ import absolute_import


import fnmatch
import logging
Expand Down Expand Up @@ -197,7 +197,7 @@ def audit(audit_files=None,
succinct_ret = {'Success': [],
'Failure': [],
'Skipped': []}
for success_type, checks in ret.iteritems():
for success_type, checks in ret.items():
for check in checks:
succinct_ret[success_type].append({check['tag']: check.get('description', '<no description>')})

Expand Down Expand Up @@ -278,7 +278,7 @@ def _get_top_data(topfile):

ret = []

for match, data in topdata.iteritems():
for match, data in topdata.items():
if __salt__['match.compound'](match):
ret.extend(data)

Expand Down Expand Up @@ -348,10 +348,10 @@ def _run_audit(ret, audit_data, tags, labels, audit_file):
:return:
Returns the updated ``ret`` object
"""
for audit_id, data in audit_data.iteritems():
for audit_id, data in audit_data.items():
LOG.debug('Executing audit id {0} in audit file {1}'.format(audit_id, audit_file))
try:
module = data.keys()[0]
module = list(data.keys())[0]
data = data[module]
if not isinstance(data, dict):
LOG.error('Audit data with id {0} from file {1} not formatted '
Expand Down
4 changes: 2 additions & 2 deletions hubblestack/extmods/modules/conf_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _filter_config(opts_to_log, remove_dots=True):
patterns_to_filter = ["password", "token", "passphrase", "privkey", "keyid", "s3.key"]
filtered_conf = _remove_sensitive_info(opts_to_log, patterns_to_filter)
if remove_dots:
for key in filtered_conf.keys():
for key in list(filtered_conf.keys()):
if '.' in key:
filtered_conf[key.replace('.', '_')] = filtered_conf.pop(key)
return filtered_conf
Expand All @@ -76,7 +76,7 @@ def _remove_sensitive_info(obj, patterns_to_filter):
if isinstance(obj, dict):
obj = {
key: _remove_sensitive_info(value, patterns_to_filter)
for key, value in obj.iteritems()
for key, value in obj.items()
if not any(patt in key for patt in patterns_to_filter)}
elif isinstance(obj, list):
obj = [_remove_sensitive_info(item, patterns_to_filter) for item in obj]
Expand Down
Loading

0 comments on commit f25c58b

Please sign in to comment.