Skip to content

Commit e84e563

Browse files
Linting
1 parent d17d377 commit e84e563

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

detection_rules/rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ def get_packaged_integrations(
14701470
# if both exist, rule tags are only used if defined in definitions for non-dataset packages
14711471
# of machine learning analytic packages
14721472

1473-
rule_integrations = meta.get("integration") or []
1473+
rule_integrations: str | list[str] = meta.get("integration") or []
14741474
for integration in rule_integrations:
14751475
ineligible_integrations = [
14761476
*definitions.NON_DATASET_PACKAGES,

detection_rules/rule_validators.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,13 @@ def log(val: str) -> None:
801801
print(f"{rule_id}:", val)
802802

803803
stack_version = ""
804-
kibana_details = kibana_client.get("/api/status")
804+
kibana_details: dict[str, Any] = kibana_client.get("/api/status", {}) # type: ignore[reportUnknownVariableType]
805+
if "version" not in kibana_details:
806+
raise ValueError("Failed to retrieve Kibana details.")
805807
stack_version = str(kibana_details["version"]["number"])
806-
807808
log(f"Validating against {stack_version} stack")
808809

809-
indices_str, indices = utils.get_esql_query_indices(contents.data.query)
810+
indices_str, indices = utils.get_esql_query_indices(contents.data.query) # type: ignore[reportUnknownVariableType]
810811
log(f"Extracted indices from query: {', '.join(indices)}")
811812

812813
# Get mappings for all matching existing index templates
@@ -820,10 +821,10 @@ def log(val: str) -> None:
820821
full_index_str = self.create_remote_indices(elastic_client, existing_mappings, index_lookup, log)
821822

822823
# Replace all sources with the test indices
823-
query = contents.data.query
824-
query = query.replace(indices_str, full_index_str)
824+
query = contents.data.query # type: ignore[reportUnknownVariableType]
825+
query = query.replace(indices_str, full_index_str) # type: ignore[reportUnknownVariableType]
825826

826-
query_columns = self.execute_query_against_indices(elastic_client, query, full_index_str, log)
827+
query_columns = self.execute_query_against_indices(elastic_client, query, full_index_str, log) # type: ignore[reportUnknownVariableType]
827828

828829
# Validation all fields (columns) are either dynamic fields or correctly mapped
829830
# against the combined mapping of all the indices

detection_rules/utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -553,18 +553,18 @@ def convert_to_nested_schema(flat_schemas: dict[str, str]) -> dict[str, Any]:
553553
current_level = nested_schema
554554

555555
for part in parts[:-1]:
556-
current_level = current_level.setdefault(part, {}).setdefault("properties", {})
556+
current_level = current_level.setdefault(part, {}).setdefault("properties", {}) # type: ignore[reportUnknownVariableType]
557557

558558
current_level[parts[-1]] = {"type": value}
559559

560-
return nested_schema
560+
return nested_schema # type: ignore[reportUnknownVariableType]
561561

562562

563563
def combine_dicts(dest: dict[Any, Any], src: dict[Any, Any]) -> None:
564564
"""Combine two dictionaries recursively."""
565565
for k, v in src.items():
566566
if k in dest and isinstance(dest[k], dict) and isinstance(v, dict):
567-
combine_dicts(dest[k], v)
567+
combine_dicts(dest[k], v) # type: ignore[reportUnknownVariableType]
568568
else:
569569
dest[k] = v
570570

@@ -585,12 +585,12 @@ def flat_schema_to_index_mapping(flat_schema: dict[str, str]) -> dict[str, Any]:
585585
current_level = result
586586

587587
for part in parts[:-1]:
588-
node = current_level.setdefault(part, {})
588+
node = current_level.setdefault(part, {}) # type: ignore[reportUnknownVariableType]
589589

590590
if "type" in node and node["type"] not in ("nested", "object"):
591-
current_level = node.setdefault("fields", {})
591+
current_level = node.setdefault("fields", {}) # type: ignore[reportUnknownVariableType]
592592
else:
593-
current_level = node.setdefault("properties", {})
593+
current_level = node.setdefault("properties", {}) # type: ignore[reportUnknownVariableType]
594594

595595
leaf_key = parts[-1]
596596
current_level[leaf_key] = {"type": field_type}
@@ -604,16 +604,16 @@ def flat_schema_to_index_mapping(flat_schema: dict[str, str]) -> dict[str, Any]:
604604
if field_type == "alias":
605605
current_level[leaf_key]["path"] = "@timestamp"
606606

607-
return result
607+
return result # type: ignore[reportUnknownVariableType]
608608

609609

610610
def get_column_from_index_mapping_schema(keys: list[str], current_schema: dict[str, Any] | None) -> str | None:
611611
"""Recursively traverse the schema to find the type of the column."""
612612
key = keys[0]
613613
if not current_schema:
614614
return None
615-
column = current_schema.get(key) or {}
616-
column_type = column.get("type") if column else None
615+
column = current_schema.get(key) or {} # type: ignore[reportUnknownVariableType]
616+
column_type = column.get("type") if column else None # type: ignore[reportUnknownVariableType]
617617
if not column_type and len(keys) > 1:
618-
return get_column_from_index_mapping_schema(keys[1:], current_schema=column.get("properties"))
619-
return column_type
618+
return get_column_from_index_mapping_schema(keys[1:], current_schema=column.get("properties")) # type: ignore[reportUnknownVariableType]
619+
return column_type # type: ignore[reportUnknownVariableType]

tests/test_rules_remote.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
import unittest
77

8+
from elasticsearch import BadRequestError
9+
810
from detection_rules.misc import get_default_config, get_elasticsearch_client, get_kibana_client, getdefault
911
from detection_rules.rule_validators import ESQLValidator
10-
from elasticsearch import BadRequestError
1112

1213
from .base import BaseRuleTest
1314

0 commit comments

Comments
 (0)