Skip to content

Commit fb4cb45

Browse files
committed
Add some validator to supported_ta field
1 parent 3e95c17 commit fb4cb45

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

contentctl/actions/validate.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

22
import pathlib
3+
4+
import urllib3.util
35
from contentctl.input.director import Director, DirectorOutputDto
46
from contentctl.objects.config import validate
57
from contentctl.enrichments.attack_enrichment import AttackEnrichment
@@ -89,19 +91,19 @@ def validate_latest_TA_information(self, data_sources: list[DataSource]) -> int:
8991
print("----------------------")
9092
for data_source in data_sources:
9193
for supported_TA in data_source.supported_TA:
92-
ta_identifier = (supported_TA["name"], supported_TA["version"])
94+
ta_identifier = (supported_TA.name, supported_TA.version)
9395
if ta_identifier in validated_TAs:
9496
continue
95-
if "url" in supported_TA:
97+
if supported_TA.url is not None:
9698
validated_TAs.append(ta_identifier)
97-
uid = int(supported_TA["url"].rstrip('/').split("/")[-1])
99+
uid = int(str(supported_TA.url).rstrip('/').split("/")[-1])
98100
try:
99101
splunk_app = SplunkApp(app_uid=uid)
100-
if splunk_app.latest_version != supported_TA["version"]:
101-
raise Exception(f"Version mismatch for TA {supported_TA['name']}: "
102+
if splunk_app.latest_version != supported_TA.version:
103+
raise Exception(f"Version mismatch for TA {supported_TA.name}: "
102104
f"Latest version on Splunkbase is {splunk_app.latest_version}, "
103-
f"but version {supported_TA['version']} is specified in the data source {data_source.name}.")
105+
f"but version {supported_TA.version} is specified in the data source {data_source.name}.")
104106
except Exception as e:
105-
print(f"Error processing TA {supported_TA['name']}: {str(e)}")
107+
print(f"Error processing TA {supported_TA.version}: {str(e)}")
106108
error_occurred = True
107109
return 1 if error_occurred else 0

contentctl/objects/data_source.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
from __future__ import annotations
22
from typing import Optional, Any
3-
from pydantic import Field, FilePath, model_serializer
3+
from pydantic import Field, HttpUrl, model_serializer, BaseModel
44
from contentctl.objects.security_content_object import SecurityContentObject
55
from contentctl.objects.event_source import EventSource
66

7+
8+
class TA(BaseModel):
9+
name: str
10+
url: HttpUrl | None = None
11+
version: str
712
class DataSource(SecurityContentObject):
813
source: str = Field(...)
914
sourcetype: str = Field(...)
1015
separator: Optional[str] = None
1116
configuration: Optional[str] = None
12-
supported_TA: Optional[list] = None
17+
supported_TA: list[TA] = []
1318
fields: Optional[list] = None
1419
field_mappings: Optional[list] = None
1520
convert_to_log_source: Optional[list] = None

0 commit comments

Comments
 (0)