Skip to content

Commit 1419f1d

Browse files
committed
ESC step 4: move internal mods to internal named dirs
1 parent 0de7693 commit 1419f1d

File tree

135 files changed

+637
-3039
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+637
-3039
lines changed
File renamed without changes.

hubblestack/extmods/hubble_mods/bexpr.py hubblestack/audit/bexpr.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@
170170
"""
171171
import logging
172172

173-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
174-
from hubblestack.extmods.module_runner.runner import Caller
175-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
173+
import hubblestack.module_runner.runner_utils as runner_utils
174+
from hubblestack.module_runner.runner import Caller
175+
from hubblestack.exceptions import HubbleCheckValidationError
176176
from pyparsing import infixNotation, opAssoc, Keyword, Word, alphas, ParserElement
177177

178178
log = logging.getLogger(__name__)

hubblestack/extmods/hubble_mods/command_line_parser.py hubblestack/audit/command_line_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@
246246
import logging
247247
import re
248248

249-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
250-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
249+
import hubblestack.module_runner.runner_utils as runner_utils
250+
from hubblestack.exceptions import HubbleCheckValidationError
251251

252252
open_bracket_list = ["[", "{", "("]
253253
close_bracket_list = ["]", "}", ")"]

hubblestack/extmods/hubble_mods/curl.py hubblestack/audit/curl.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@
224224
import logging
225225
import requests
226226

227-
import hubblestack.extmods.module_runner.runner_factory as runner_factory
228-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
229-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
230-
from salt.exceptions import CommandExecutionError
227+
import hubblestack.module_runner.runner_factory as runner_factory
228+
import hubblestack.module_runner.runner_utils as runner_utils
229+
from hubblestack.exceptions import HubbleCheckValidationError
230+
from hubblestack.exceptions import CommandExecutionError
231231

232232
log = logging.getLogger(__name__)
233233

hubblestack/extmods/hubble_mods/fdg.py hubblestack/audit/fdg.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@
180180
"""
181181
import logging
182182

183-
import hubblestack.extmods.module_runner.runner_factory as runner_factory
184-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
185-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
183+
import hubblestack.module_runner.runner_factory as runner_factory
184+
import hubblestack.module_runner.runner_utils as runner_utils
185+
from hubblestack.exceptions import HubbleCheckValidationError
186186

187187
log = logging.getLogger(__name__)
188188

hubblestack/extmods/hubble_mods/grep.py hubblestack/audit/grep.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@
189189
import os
190190
import logging
191191

192-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
193-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
194-
from salt.exceptions import CommandExecutionError
192+
import hubblestack.module_runner.runner_utils as runner_utils
193+
from hubblestack.exceptions import HubbleCheckValidationError, CommandExecutionError
195194

196195
log = logging.getLogger(__name__)
197196

@@ -356,7 +355,7 @@ def _grep(path,
356355
cmd += [path]
357356

358357
try:
359-
ret = __salt__['cmd.run_all'](cmd, python_shell=False, ignore_retcode=True, stdin=string)
358+
ret = __mods__['cmd.run_all'](cmd, python_shell=False, ignore_retcode=True, stdin=string)
360359
except (IOError, OSError) as exc:
361360
raise CommandExecutionError(exc.strerror)
362361

hubblestack/extmods/hubble_mods/misc.py hubblestack/audit/misc.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@
250250

251251
import re
252252

253-
from salt.exceptions import CommandExecutionError
253+
from hubblestack.exceptions import CommandExecutionError
254254
from collections import Counter
255255

256-
import hubblestack.extmods.module_runner.comparator
257-
from hubblestack.extmods.module_runner.runner import Caller
258-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
259-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
260-
import hubblestack.extmods.hubble_mods.grep as grep_module
256+
import hubblestack.module_runner.comparator
257+
from hubblestack.module_runner.runner import Caller
258+
import hubblestack.module_runner.runner_utils as runner_utils
259+
from hubblestack.exceptions import HubbleCheckValidationError
260+
import hubblestack.audit.grep as grep_module
261261

262262
log = logging.getLogger(__name__)
263263

@@ -424,7 +424,7 @@ def _system_account_non_login(block_id, block_dict, extra_args=None):
424424
if user.strip() != "":
425425
users_list.append(user.strip())
426426
result = []
427-
cmd = __salt__["cmd.run_all"]('egrep -v "^\+" /etc/passwd ')
427+
cmd = __mods__["cmd.run_all"]('egrep -v "^\+" /etc/passwd ')
428428
for line in cmd['stdout'].split('\n'):
429429
tokens = line.split(':')
430430
if tokens[0] not in users_list and int(tokens[2]) < int(max_system_uid) and tokens[6] not in ( non_login_shell , "/bin/false" ):
@@ -567,7 +567,7 @@ def _check_directory_files_permission(block_id, block_dict, extra_args=None):
567567
return True if bad_permission_files == [] else str(bad_permission_files)
568568

569569
def _compare_file_stats(block_id, path, permission):
570-
path_details = __salt__['file.stats'](path)
570+
path_details = __mods__['file.stats'](path)
571571

572572
comparator_args = {
573573
"type": "file_permission",
@@ -576,7 +576,7 @@ def _compare_file_stats(block_id, path, permission):
576576
}
577577
}
578578

579-
ret_status, ret_val = hubblestack.extmods.module_runner.comparator.run(
579+
ret_status, ret_val = hubblestack.module_runner.comparator.run(
580580
block_id, comparator_args, path_details.get('mode'))
581581
return True if ret_status else path_details.get('mode')
582582

@@ -603,13 +603,13 @@ def _check_service_status(block_id, block_dict, extra_args=None):
603603
service_name = runner_utils.get_param_for_module(block_id, block_dict, 'service_name')
604604
state = runner_utils.get_param_for_module(block_id, block_dict, 'state')
605605

606-
all_services = __salt__['cmd.run']('systemctl list-unit-files')
606+
all_services = __mods__['cmd.run']('systemctl list-unit-files')
607607
if re.search(service_name, all_services, re.M):
608-
output = __salt__['cmd.retcode']('systemctl is-enabled ' + service_name, ignore_retcode=True)
608+
output = __mods__['cmd.retcode']('systemctl is-enabled ' + service_name, ignore_retcode=True)
609609
if (state == "disabled" and str(output) == "1") or (state == "enabled" and str(output) == "0"):
610610
return True
611611
else:
612-
return __salt__['cmd.run_stdout']('systemctl is-enabled ' + service_name, ignore_retcode=True)
612+
return __mods__['cmd.run_stdout']('systemctl is-enabled ' + service_name, ignore_retcode=True)
613613
else:
614614
if state == "disabled":
615615
return True
@@ -665,7 +665,7 @@ def _check_users_home_directory_permissions(block_id, block_dict, extra_args=Non
665665
users_list.append(user.strip())
666666

667667
users_dirs = []
668-
cmd = __salt__["cmd.run_all"]('egrep -v "^\+" /etc/passwd ')
668+
cmd = __mods__["cmd.run_all"]('egrep -v "^\+" /etc/passwd ')
669669
for line in cmd['stdout'].split('\n'):
670670
tokens = line.split(':')
671671
if tokens[0] not in users_list and 'nologin' not in tokens[6] and 'false' not in tokens[6]:
@@ -712,7 +712,7 @@ def _check_users_own_their_home(block_id, block_dict, extra_args=None):
712712
error += ["Either home directory " + user_uid_dir[2] + " of user " + user_uid_dir[0] + " is invalid or does not exist."]
713713
elif int(user_uid_dir[1]) >= max_system_uid and user_uid_dir[0] != "nfsnobody" and 'nologin' not in user_uid_dir[3] \
714714
and 'false' not in user_uid_dir[3]:
715-
owner = __salt__['cmd.run']("stat -L -c \"%U\" \"" + user_uid_dir[2] + "\"")
715+
owner = __mods__['cmd.run']("stat -L -c \"%U\" \"" + user_uid_dir[2] + "\"")
716716
if owner != user_uid_dir[0]:
717717
error += ["The home directory " + user_uid_dir[2] + " of user " + user_uid_dir[0] + " is owned by " + owner]
718718
else:
@@ -737,7 +737,7 @@ def _check_users_dot_files(block_id, block_dict, extra_args):
737737
dot_files = dot_files.split('\n') if dot_files != "" else []
738738
for dot_file in dot_files:
739739
if os.path.isfile(dot_file):
740-
path_details = __salt__['file.stats'](dot_file)
740+
path_details = __mods__['file.stats'](dot_file)
741741
given_permission = path_details.get('mode')
742742
file_permission = given_permission[-3:]
743743
if file_permission[1] in ["2", "3", "6", "7"]:
@@ -1031,7 +1031,7 @@ def _check_sshd_parameters(block_id, block_dict, extra_args=None):
10311031
values = runner_utils.get_param_for_module(block_id, block_dict, 'values')
10321032
comparetype = runner_utils.get_param_for_module(block_id, block_dict, 'comparetype', 'regex')
10331033

1034-
output = __salt__['cmd.run']('sshd -T')
1034+
output = __mods__['cmd.run']('sshd -T')
10351035
if comparetype == 'only':
10361036
if not values:
10371037
return "You need to provide values for comparetype 'only'."
@@ -1079,5 +1079,5 @@ def _execute_shell_command(cmd, python_shell=False):
10791079
"""
10801080
This function will execute passed command in /bin/shell
10811081
"""
1082-
return __salt__['cmd.run'](cmd, python_shell=python_shell, shell='/bin/bash', ignore_retcode=True)
1082+
return __mods__['cmd.run'](cmd, python_shell=python_shell, shell='/bin/bash', ignore_retcode=True)
10831083

hubblestack/extmods/hubble_mods/osquery.py hubblestack/audit/osquery.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@
186186
import logging
187187
import os
188188

189-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
190-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
189+
import hubblestack.module_runner.runner_utils as runner_utils
190+
from hubblestack.exceptions import HubbleCheckValidationError
191191

192192
log = logging.getLogger(__name__)
193193

@@ -309,7 +309,7 @@ def _osquery(block_id, query, osquery_path=None, args=None, cast_to_string=None)
309309
cmd.extend(args)
310310

311311
# Run the command
312-
res = __salt__['cmd.run_all'](cmd, timeout=10000, python_shell=False)
312+
res = __mods__['cmd.run_all'](cmd, timeout=10000, python_shell=False)
313313
if res['retcode'] == 0:
314314
ret = json.loads(res['stdout'])
315315
for result in ret:

hubblestack/extmods/hubble_mods/pkg.py hubblestack/audit/pkg.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@
181181
import logging
182182
import fnmatch
183183

184-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
185-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
184+
import hubblestack.module_runner.runner_utils as runner_utils
185+
from hubblestack.exceptions import HubbleCheckValidationError
186186

187187
log = logging.getLogger(__name__)
188188

@@ -239,7 +239,7 @@ def execute(block_id, block_dict, extra_args=None):
239239
if not name:
240240
name = runner_utils.get_param_for_module(block_id, block_dict, 'name')
241241

242-
installed_pkgs_dict = __salt__['pkg.list_pkgs']()
242+
installed_pkgs_dict = __mods__['pkg.list_pkgs']()
243243
filtered_pkgs_list = fnmatch.filter(installed_pkgs_dict, name)
244244
result_dict = {}
245245
for package in filtered_pkgs_list:

hubblestack/extmods/hubble_mods/readfile.py hubblestack/audit/readfile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@
229229
import re
230230

231231
from hubblestack.utils.encoding import encode_base64
232-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
233-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
232+
import hubblestack.module_runner.runner_utils as runner_utils
233+
from hubblestack.exceptions import HubbleCheckValidationError
234234

235235
log = logging.getLogger(__name__)
236236

hubblestack/extmods/hubble_mods/service.py hubblestack/audit/service.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@
185185
import logging
186186
import fnmatch
187187

188-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
189-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
188+
import hubblestack.module_runner.runner_utils as runner_utils
189+
from hubblestack.exceptions import HubbleCheckValidationError
190190

191191
log = logging.getLogger(__name__)
192192

@@ -245,10 +245,10 @@ def execute(block_id, block_dict, extra_args=None):
245245
name = runner_utils.get_param_for_module(block_id, block_dict, 'name')
246246

247247
result = []
248-
matched_services = fnmatch.filter(__salt__['service.get_all'](), name)
248+
matched_services = fnmatch.filter(__mods__['service.get_all'](), name)
249249
for matched_service in matched_services:
250-
service_status = __salt__['service.status'](matched_service)
251-
is_enabled = __salt__['service.enabled'](matched_service)
250+
service_status = __mods__['service.status'](matched_service)
251+
is_enabled = __mods__['service.enabled'](matched_service)
252252
result.append({
253253
"name": matched_service,
254254
"running": service_status,

hubblestack/extmods/hubble_mods/ssl_certificate.py hubblestack/audit/ssl_certificate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@
217217
from datetime import datetime
218218
from socket import setdefaulttimeout
219219

220-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
221-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
220+
import hubblestack.module_runner.runner_utils as runner_utils
221+
from hubblestack.exceptions import HubbleCheckValidationError
222222

223223
log = logging.getLogger(__name__)
224224

hubblestack/extmods/hubble_mods/stat.py hubblestack/audit/stat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@
197197
import os
198198
import logging
199199

200-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
201-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
200+
import hubblestack.module_runner.runner_utils as runner_utils
201+
from hubblestack.exceptions import HubbleCheckValidationError
202202

203203
log = logging.getLogger(__name__)
204204

@@ -257,7 +257,7 @@ def execute(block_id, block_dict, extra_args=None):
257257
if not os.path.isfile(filepath):
258258
return runner_utils.prepare_negative_result_for_module(block_id, 'file_not_found')
259259

260-
stat_res = __salt__['file.stats'](filepath)
260+
stat_res = __mods__['file.stats'](filepath)
261261
return runner_utils.prepare_positive_result_for_module(block_id, stat_res)
262262

263263

hubblestack/extmods/hubble_mods/sysctl.py hubblestack/audit/sysctl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@
171171

172172
import logging
173173

174-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
175-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
174+
import hubblestack.module_runner.runner_utils as runner_utils
175+
from hubblestack.exceptions import HubbleCheckValidationError
176176

177177
log = logging.getLogger(__name__)
178178

@@ -229,7 +229,7 @@ def execute(block_id, block_dict, extra_args=None):
229229
if not name:
230230
name = runner_utils.get_param_for_module(block_id, block_dict, 'name')
231231

232-
sysctl_res = __salt__['sysctl.get'](name)
232+
sysctl_res = __mods__['sysctl.get'](name)
233233
result = {name: sysctl_res}
234234
if not sysctl_res or "No such file or directory" in sysctl_res:
235235
return runner_utils.prepare_negative_result_for_module(block_id, "Could not find attribute %s in the kernel" %(name))

hubblestack/extmods/hubble_mods/time_sync.py hubblestack/audit/time_sync.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@
201201

202202
import logging
203203

204-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
205-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
204+
import hubblestack.module_runner.runner_utils as runner_utils
205+
from hubblestack.exceptions import HubbleCheckValidationError
206206

207-
import salt.utils.platform
207+
import hubblestack.utils.platform
208208

209-
if not salt.utils.platform.is_windows():
209+
if not hubblestack.utils.platform.is_windows():
210210
import ntplib
211211
log = logging.getLogger(__name__)
212212

@@ -324,8 +324,8 @@ def _query_ntp_server(ntp_server):
324324
string containing the NTP server to query
325325
"""
326326
# use w32tm instead of ntplib
327-
if salt.utils.platform.is_windows():
328-
ret = __salt__['cmd.run']('w32tm /stripchart /computer:{0} /dataonly /samples:1'.format(
327+
if hubblestack.utils.platform.is_windows():
328+
ret = __mods__['cmd.run']('w32tm /stripchart /computer:{0} /dataonly /samples:1'.format(
329329
ntp_server))
330330
try:
331331
return float(ret.split('\n')[-1].split()[1][:-1])

hubblestack/extmods/hubble_mods/util.py hubblestack/audit/util.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,10 @@
263263
import logging
264264
import re
265265

266-
from salt.exceptions import ArgumentValueError
267266
from hubblestack.utils.encoding import encode_base64 as utils_encode_base64
268-
269-
from hubblestack.extmods.module_runner.runner import Caller
270-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
271-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
267+
from hubblestack.module_runner.runner import Caller
268+
import hubblestack.module_runner.runner_utils as runner_utils
269+
from hubblestack.exceptions import HubbleCheckValidationError, ArgumentValueError
272270

273271
log = logging.getLogger(__name__)
274272

hubblestack/extmods/hubble_mods/win_auditpol.py hubblestack/audit/win_auditpol.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@
169169

170170
import csv
171171
import logging
172-
import salt.utils.platform
172+
import hubblestack.utils.platform
173173

174-
import hubblestack.extmods.module_runner.runner_utils as runner_utils
175-
from hubblestack.utils.hubble_error import HubbleCheckValidationError
174+
import hubblestack.module_runner.runner_utils as runner_utils
175+
from hubblestack.exceptions import HubbleCheckValidationError
176176

177177
log = logging.getLogger(__name__)
178178

179179

180180
def __virtual__():
181-
if not salt.utils.platform.is_windows():
181+
if not hubblestack.utils.platform.is_windows():
182182
return False, 'This audit module only runs on windows'
183183
return True
184184

@@ -276,11 +276,11 @@ def _auditpol_import():
276276

277277
def _auditpol_export():
278278
try:
279-
dump = __salt__['cmd.run']('auditpol /get /category:* /r')
279+
dump = __mods__['cmd.run']('auditpol /get /category:* /r')
280280
if dump:
281281
dump = dump.split('\n')
282282
return dump
283283
else:
284284
log.error('Nothing was returned from the auditpol command.')
285285
except Exception:
286-
log.error('An error occurred running the auditpol command.')
286+
log.error('An error occurred running the auditpol command.')

0 commit comments

Comments
 (0)