Skip to content

Commit 378abf0

Browse files
authored
Merge pull request #411 from splunk/ruff_updates
Bumping Ruff version
2 parents 3a5e654 + ad01e74 commit 378abf0

Some content is hidden

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

62 files changed

+228
-193
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
ff87bcaf1741e8ecf15cb8d401438592dfef3ba7 # Mass reformat with adoption of ruff
2+
9d96a56b763ece491a07441dbe26176777a1964c # Add I rules to ruff
3+
4eefa15b8afbb387b9fa5338dc45759e1915ef56 # Add E, W, and RUF

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- id: detect-private-key
99
- id: forbid-submodules
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.11.2
11+
rev: v0.12.5
1212
hooks:
1313
- id: ruff
1414
args: [ --fix ]

contentctl/actions/deploy_acs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from contentctl.objects.config import deploy_acs, StackType
2-
from requests import post
31
import pprint
42

3+
from requests import post
4+
5+
from contentctl.objects.config import StackType, deploy_acs
6+
57

68
class Deploy:
79
def execute(self, config: deploy_acs, appinspect_token: str) -> None:
@@ -33,7 +35,7 @@ def execute(self, config: deploy_acs, appinspect_token: str) -> None:
3335
raise Exception(f"Unsupported stack type: '{config.stack_type}'")
3436
except Exception as e:
3537
raise Exception(
36-
f"Error installing to stack '{config.splunk_cloud_stack}' (stack_type='{config.stack_type}') via ACS:\n{str(e)}"
38+
f"Error installing to stack '{config.splunk_cloud_stack}' (stack_type='{config.stack_type}') via ACS:\n{e!s}"
3739
)
3840

3941
try:

contentctl/actions/detection_testing/DetectionTestingManager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ def sigint_handler(signum, frame):
162162
print()
163163
print(f"[{error_type}]:")
164164
for error in errors[error_type]:
165-
print(f"\t{str(error)}")
165+
print(f"\t{error!s}")
166166
if isinstance(error, ExceptionGroup):
167167
for suberror in error.exceptions: # type: ignore
168-
print(f"\t\t{str(suberror)}") # type: ignore
168+
print(f"\t\t{suberror!s}") # type: ignore
169169
print()
170170

171171
return self.output_dto
@@ -208,7 +208,7 @@ def create_DetectionTestingInfrastructureObjects(self):
208208
except Exception as e:
209209
raise Exception(
210210
"Failed to pull docker container image "
211-
f"[{self.input_dto.config.container_settings.full_image_path}]: {str(e)}"
211+
f"[{self.input_dto.config.container_settings.full_image_path}]: {e!s}"
212212
)
213213

214214
already_staged_container_files = False

contentctl/actions/detection_testing/GitService.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def getChanges(self, target_branch: str) -> List[Detection]:
9999
updated_detections.add(detectionObject)
100100
else:
101101
raise Exception(
102-
f"Error getting detection object for file {str(decoded_path)}"
102+
f"Error getting detection object for file {decoded_path!s}"
103103
)
104104

105105
elif (
@@ -111,7 +111,7 @@ def getChanges(self, target_branch: str) -> List[Detection]:
111111
updated_macros.add(macroObject)
112112
else:
113113
raise Exception(
114-
f"Error getting macro object for file {str(decoded_path)}"
114+
f"Error getting macro object for file {decoded_path!s}"
115115
)
116116

117117
elif (
@@ -125,7 +125,7 @@ def getChanges(self, target_branch: str) -> List[Detection]:
125125
updated_datasources.add(datasourceObject)
126126
else:
127127
raise Exception(
128-
f"Error getting data source object for file {str(decoded_path)}"
128+
f"Error getting data source object for file {decoded_path!s}"
129129
)
130130

131131
elif decoded_path.is_relative_to(self.config.path / "lookups"):
@@ -172,7 +172,7 @@ def getChanges(self, target_branch: str) -> List[Detection]:
172172

173173
else:
174174
raise Exception(
175-
f"Detected a changed file in the lookups/ directory '{str(decoded_path)}'.\n"
175+
f"Detected a changed file in the lookups/ directory '{decoded_path!s}'.\n"
176176
"Only files ending in .csv, .yml, or .mlmodel are supported in this "
177177
"directory. This file must be removed from the lookups/ directory."
178178
)

contentctl/actions/detection_testing/generate_detection_coverage_badge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
try:
4848
results = parser.parse_args()
4949
except Exception as e:
50-
print(f"Error parsing arguments: {str(e)}")
50+
print(f"Error parsing arguments: {e!s}")
5151
exit(1)
5252

5353
try:
5454
summary_info = json.loads(results.input_summary_file.read())
5555
except Exception as e:
56-
print(f"Error loading {results.input_summary_file.name} JSON file: {str(e)}")
56+
print(f"Error loading {results.input_summary_file.name} JSON file: {e!s}")
5757
sys.exit(1)
5858

5959
if "summary" not in summary_info:
@@ -75,7 +75,7 @@
7575
RAW_BADGE_SVG.format(results.badge_string, "{:2.1f}%".format(pass_percent))
7676
)
7777
except Exception as e:
78-
print(f"Error generating badge: {str(e)}")
78+
print(f"Error generating badge: {e!s}")
7979
sys.exit(1)
8080

8181

contentctl/actions/detection_testing/infrastructures/DetectionTestingInfrastructure.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def setup(self):
197197
self.check_for_teardown()
198198

199199
except Exception as e:
200-
msg = f"[{self.get_name()}]: {str(e)}"
200+
msg = f"[{self.get_name()}]: {e!s}"
201201
self.finish()
202202
if isinstance(e, ExceptionGroup):
203203
raise ExceptionGroup(msg, e.exceptions) from e # type: ignore
@@ -310,7 +310,7 @@ def configure_hec(self):
310310
return
311311

312312
except Exception as e:
313-
raise (Exception(f"Failure creating HEC Endpoint: {str(e)}"))
313+
raise (Exception(f"Failure creating HEC Endpoint: {e!s}"))
314314

315315
def get_all_indexes(self) -> None:
316316
"""
@@ -327,7 +327,7 @@ def get_all_indexes(self) -> None:
327327
# Retrieve all available indexes on the splunk instance
328328
self.all_indexes_on_server = indexes
329329
except Exception as e:
330-
raise (Exception(f"Failure getting indexes: {str(e)}"))
330+
raise (Exception(f"Failure getting indexes: {e!s}"))
331331

332332
def get_conn(self) -> client.Service:
333333
try:
@@ -382,7 +382,7 @@ def connect_to_api(self, sleep_seconds: int = 5):
382382
pass
383383
except Exception as e:
384384
self.pbar.write(
385-
f"Error getting API connection (not quitting) '{type(e).__name__}': {str(e)}"
385+
f"Error getting API connection (not quitting) '{type(e).__name__}': {e!s}"
386386
)
387387

388388
for _ in range(sleep_seconds):
@@ -402,7 +402,7 @@ def create_replay_index(self):
402402
pass
403403
else:
404404
raise Exception(
405-
f"Error creating index {self.sync_obj.replay_index} - {str(e)}"
405+
f"Error creating index {self.sync_obj.replay_index} - {e!s}"
406406
)
407407

408408
def configure_imported_roles(
@@ -426,7 +426,7 @@ def configure_imported_roles(
426426
)
427427
return
428428
except Exception as e:
429-
msg = f"Error configuring roles: {str(e)}"
429+
msg = f"Error configuring roles: {e!s}"
430430
self.pbar.write(msg)
431431
raise Exception(msg) from e
432432

@@ -436,7 +436,7 @@ def configure_delete_indexes(self):
436436
self.get_conn().post(endpoint, value=";".join(self.all_indexes_on_server))
437437
except Exception as e:
438438
self.pbar.write(
439-
f"Error configuring deleteIndexesAllowed with '{self.all_indexes_on_server}': [{str(e)}]"
439+
f"Error configuring deleteIndexesAllowed with '{self.all_indexes_on_server}': [{e!s}]"
440440
)
441441

442442
def wait_for_conf_file(self, app_name: str, conf_file_name: str):
@@ -474,12 +474,12 @@ def configure_conf_file_datamodels(self, APP_NAME: str = "Splunk_SA_CIM"):
474474
parser.read(custom_acceleration_datamodels)
475475
if len(parser.keys()) > 1:
476476
self.pbar.write(
477-
f"Read {len(parser) - 1} custom datamodels from {str(custom_acceleration_datamodels)}!"
477+
f"Read {len(parser) - 1} custom datamodels from {custom_acceleration_datamodels!s}!"
478478
)
479479

480480
if not cim_acceleration_datamodels.is_file():
481481
self.pbar.write(
482-
f"******************************\nDATAMODEL ACCELERATION FILE {str(cim_acceleration_datamodels)} NOT "
482+
f"******************************\nDATAMODEL ACCELERATION FILE {cim_acceleration_datamodels!s} NOT "
483483
"FOUND. CIM DATAMODELS NOT ACCELERATED\n******************************\n"
484484
)
485485
else:
@@ -499,7 +499,7 @@ def configure_conf_file_datamodels(self, APP_NAME: str = "Splunk_SA_CIM"):
499499

500500
except Exception as e:
501501
self.pbar.write(
502-
f"Error creating the conf Datamodel {datamodel_name} key/value {name}/{value}: {str(e)}"
502+
f"Error creating the conf Datamodel {datamodel_name} key/value {name}/{value}: {e!s}"
503503
)
504504

505505
def execute(self):
@@ -528,9 +528,7 @@ def execute(self):
528528
self.finish()
529529
return
530530
except Exception as e:
531-
self.pbar.write(
532-
f"Error testing detection: {type(e).__name__}: {str(e)}"
533-
)
531+
self.pbar.write(f"Error testing detection: {type(e).__name__}: {e!s}")
534532
raise e
535533
finally:
536534
self.sync_obj.outputQueue.append(detection)
@@ -1365,7 +1363,7 @@ def delete_attack_data(self, attack_data_files: list[TestAttackData]):
13651363
except Exception as e:
13661364
raise (
13671365
Exception(
1368-
f"Trouble deleting data using the search {splunk_search}: {str(e)}"
1366+
f"Trouble deleting data using the search {splunk_search}: {e!s}"
13691367
)
13701368
)
13711369

@@ -1440,7 +1438,7 @@ def replay_attack_data_file(
14401438
except Exception as e:
14411439
raise (
14421440
Exception(
1443-
f"Could not download attack data file [{attack_data_file.data}]:{str(e)}"
1441+
f"Could not download attack data file [{attack_data_file.data}]:{e!s}"
14441442
)
14451443
)
14461444

@@ -1514,7 +1512,7 @@ def hec_raw_replay(
15141512
except Exception as e:
15151513
raise (
15161514
Exception(
1517-
f"There was an exception sending attack_data to HEC: {str(e)}"
1515+
f"There was an exception sending attack_data to HEC: {e!s}"
15181516
)
15191517
)
15201518

@@ -1558,7 +1556,7 @@ def hec_raw_replay(
15581556
)
15591557
)
15601558
except Exception as e:
1561-
raise (Exception(f"There was an exception in the post: {str(e)}"))
1559+
raise (Exception(f"There was an exception in the post: {e!s}"))
15621560

15631561
def status(self):
15641562
pass

contentctl/actions/detection_testing/infrastructures/DetectionTestingInfrastructureContainer.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import docker
2+
import docker.models.containers
3+
import docker.models.resource
4+
import docker.types
5+
16
from contentctl.actions.detection_testing.infrastructures.DetectionTestingInfrastructure import (
27
DetectionTestingInfrastructure,
38
)
49
from contentctl.objects.config import test
5-
import docker.models.resource
6-
import docker.models.containers
7-
import docker
8-
import docker.types
910

1011

1112
class DetectionTestingInfrastructureContainer(DetectionTestingInfrastructure):
@@ -34,7 +35,7 @@ def finish(self):
3435
self.removeContainer()
3536
pass
3637
except Exception as e:
37-
raise (Exception(f"Error removing container: {str(e)}"))
38+
raise (Exception(f"Error removing container: {e!s}"))
3839
super().finish()
3940

4041
def get_name(self) -> str:
@@ -46,7 +47,7 @@ def get_docker_client(self):
4647

4748
return c
4849
except Exception as e:
49-
raise (Exception(f"Failed to get docker client: {str(e)}"))
50+
raise (Exception(f"Failed to get docker client: {e!s}"))
5051

5152
def check_for_teardown(self):
5253
try:
@@ -56,7 +57,7 @@ def check_for_teardown(self):
5657
except Exception as e:
5758
if self.sync_obj.terminate is not True:
5859
self.pbar.write(
59-
f"Error: could not get container [{self.get_name()}]: {str(e)}"
60+
f"Error: could not get container [{self.get_name()}]: {e!s}"
6061
)
6162
self.sync_obj.terminate = True
6263
else:
@@ -175,6 +176,6 @@ def removeContainer(self, removeVolumes: bool = True, forceRemove: bool = True):
175176
except Exception as e:
176177
raise (
177178
Exception(
178-
f"Could not remove Docker Container [{self.get_name()}]: {str(e)}"
179+
f"Could not remove Docker Container [{self.get_name()}]: {e!s}"
179180
)
180181
)

contentctl/actions/detection_testing/progress_bar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import datetime
12
import time
23
from enum import StrEnum
4+
35
from tqdm import tqdm
4-
import datetime
56

67

78
class TestReportingType(StrEnum):

contentctl/actions/detection_testing/views/DetectionTestingViewCLI.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import time
2+
3+
import tqdm
4+
15
from contentctl.actions.detection_testing.views.DetectionTestingView import (
26
DetectionTestingView,
37
)
48

5-
import time
6-
import tqdm
7-
89

910
class DetectionTestingViewCLI(DetectionTestingView, arbitrary_types_allowed=True):
1011
pbar: tqdm.tqdm = None

0 commit comments

Comments
 (0)