Skip to content

Commit 3388c69

Browse files
committed
ruff
1 parent e9b7dfe commit 3388c69

File tree

2 files changed

+79
-46
lines changed

2 files changed

+79
-46
lines changed

contentctl/actions/validate.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from contentctl.enrichments.cve_enrichment import CveEnrichment
55
from contentctl.helper.splunk_app import SplunkApp
66
from contentctl.helper.utils import Utils
7-
from contentctl.input.director import (Director, DirectorOutputDto,
8-
ValidationFailedError)
7+
from contentctl.input.director import Director, DirectorOutputDto, ValidationFailedError
98
from contentctl.objects.atomic import AtomicEnrichment
109
from contentctl.objects.config import validate
1110
from contentctl.objects.data_source import DataSource
@@ -33,12 +32,14 @@ def execute(self, input_dto: validate) -> DirectorOutputDto:
3332

3433
director = Director(director_output_dto)
3534
director.execute(input_dto)
36-
self.ensure_no_orphaned_files_in_lookups(input_dto.path, director_output_dto)
35+
self.ensure_no_orphaned_files_in_lookups(
36+
input_dto.path, director_output_dto
37+
)
3738
if input_dto.data_source_TA_validation:
3839
self.validate_latest_TA_information(director_output_dto.data_sources)
3940

4041
return director_output_dto
41-
42+
4243
except ValidationFailedError:
4344
# Just re-raise without additional output since we already formatted everything
4445
raise SystemExit(1)

contentctl/input/director.py

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,33 @@ def addContentToDictMappings(self, content: SecurityContentObject):
9393

9494

9595
class Colors:
96-
HEADER = '\033[95m'
97-
BLUE = '\033[94m'
98-
CYAN = '\033[96m'
99-
GREEN = '\033[92m'
100-
YELLOW = '\033[93m'
101-
RED = '\033[91m'
102-
BOLD = '\033[1m'
103-
UNDERLINE = '\033[4m'
104-
END = '\033[0m'
105-
MAGENTA = '\033[35m'
106-
BRIGHT_MAGENTA = '\033[95m'
96+
HEADER = "\033[95m"
97+
BLUE = "\033[94m"
98+
CYAN = "\033[96m"
99+
GREEN = "\033[92m"
100+
YELLOW = "\033[93m"
101+
RED = "\033[91m"
102+
BOLD = "\033[1m"
103+
UNDERLINE = "\033[4m"
104+
END = "\033[0m"
105+
MAGENTA = "\033[35m"
106+
BRIGHT_MAGENTA = "\033[95m"
107107

108108
# Add fallback symbols for Windows
109-
CHECK_MARK = '✓' if sys.platform != 'win32' else '*'
110-
WARNING = '⚠️' if sys.platform != 'win32' else '!'
111-
ERROR = '❌' if sys.platform != 'win32' else 'X'
112-
ARROW = '🎯' if sys.platform != 'win32' else '>'
113-
TOOLS = '🛠️' if sys.platform != 'win32' else '#'
114-
DOCS = '📚' if sys.platform != 'win32' else '?'
115-
BULB = '💡' if sys.platform != 'win32' else 'i'
116-
SEARCH = '🔍' if sys.platform != 'win32' else '@'
117-
ZAP = '⚡' if sys.platform != 'win32' else '!'
109+
CHECK_MARK = "✓" if sys.platform != "win32" else "*"
110+
WARNING = "⚠️" if sys.platform != "win32" else "!"
111+
ERROR = "❌" if sys.platform != "win32" else "X"
112+
ARROW = "🎯" if sys.platform != "win32" else ">"
113+
TOOLS = "🛠️" if sys.platform != "win32" else "#"
114+
DOCS = "📚" if sys.platform != "win32" else "?"
115+
BULB = "💡" if sys.platform != "win32" else "i"
116+
SEARCH = "🔍" if sys.platform != "win32" else "@"
117+
ZAP = "⚡" if sys.platform != "win32" else "!"
118118

119119

120120
class ValidationFailedError(Exception):
121-
"""Custom exception for validation failures that already have formatted output"""
121+
"""Custom exception for validation failures that already have formatted output."""
122+
122123
def __init__(self, message: str):
123124
self.message = message
124125
super().__init__(message)
@@ -144,8 +145,9 @@ def execute(self, input_dto: validate) -> None:
144145
self.createSecurityContent(SecurityContentType.detections)
145146
self.createSecurityContent(SecurityContentType.dashboards)
146147

147-
from contentctl.objects.abstract_security_content_objects.detection_abstract import \
148-
MISSING_SOURCES
148+
from contentctl.objects.abstract_security_content_objects.detection_abstract import (
149+
MISSING_SOURCES,
150+
)
149151

150152
if len(MISSING_SOURCES) > 0:
151153
missing_sources_string = "\n 🟡 ".join(sorted(list(MISSING_SOURCES)))
@@ -289,41 +291,59 @@ def createSecurityContent(self, contentType: SecurityContentType) -> None:
289291
if len(validation_errors) > 0:
290292
print("\n") # Clean separation
291293
print(f"{Colors.BOLD}{Colors.BRIGHT_MAGENTA}{'═' * 60}{Colors.END}")
292-
print(f"{Colors.BOLD}{Colors.BRIGHT_MAGENTA}{Colors.BLUE}{f'{Colors.SEARCH} Content Validation Summary':^60}{Colors.BRIGHT_MAGENTA}{Colors.END}")
294+
print(
295+
f"{Colors.BOLD}{Colors.BRIGHT_MAGENTA}{Colors.BLUE}{f'{Colors.SEARCH} Content Validation Summary':^60}{Colors.BRIGHT_MAGENTA}{Colors.END}"
296+
)
293297
print(f"{Colors.BOLD}{Colors.BRIGHT_MAGENTA}{'═' * 60}{Colors.END}\n")
294298

295-
print(f"{Colors.BOLD}{Colors.GREEN}✨ Validation Completed{Colors.END} – Issues detected in {Colors.RED}{Colors.BOLD}{len(validation_errors)}{Colors.END} files.\n")
299+
print(
300+
f"{Colors.BOLD}{Colors.GREEN}✨ Validation Completed{Colors.END} – Issues detected in {Colors.RED}{Colors.BOLD}{len(validation_errors)}{Colors.END} files.\n"
301+
)
296302

297303
for index, entry in enumerate(validation_errors, 1):
298304
file_path, error = entry
299305
width = max(70, len(str(file_path)) + 15)
300-
306+
301307
# File header with numbered emoji
302308
number_emoji = f"{index}️⃣"
303309
print(f"{Colors.YELLOW}{'━' * width}{Colors.END}")
304-
print(f"{Colors.YELLOW}{Colors.BOLD} {number_emoji} File: {Colors.CYAN}{file_path}{Colors.END}{' ' * (width - len(str(file_path)) - 12)}{Colors.YELLOW}{Colors.END}")
310+
print(
311+
f"{Colors.YELLOW}{Colors.BOLD} {number_emoji} File: {Colors.CYAN}{file_path}{Colors.END}{' ' * (width - len(str(file_path)) - 12)}{Colors.YELLOW}{Colors.END}"
312+
)
305313
print(f"{Colors.YELLOW}{'━' * width}{Colors.END}")
306-
307-
print(f" {Colors.RED}{Colors.BOLD}{Colors.ZAP} Validation Issues:{Colors.END}")
314+
315+
print(
316+
f" {Colors.RED}{Colors.BOLD}{Colors.ZAP} Validation Issues:{Colors.END}"
317+
)
308318

309319
if isinstance(error, ValidationError):
310320
for err in error.errors():
311321
error_msg = err.get("msg", "")
312322
if "https://errors.pydantic.dev" in error_msg:
313323
continue
314-
324+
315325
# Clean error categorization
316326
if "Field required" in error_msg:
317-
print(f" {Colors.YELLOW}{Colors.WARNING} Field Required: {err.get('loc', [''])[0]}{Colors.END}")
327+
print(
328+
f" {Colors.YELLOW}{Colors.WARNING} Field Required: {err.get('loc', [''])[0]}{Colors.END}"
329+
)
318330
elif "Input should be" in error_msg:
319-
print(f" {Colors.MAGENTA}{Colors.ARROW} Invalid Value for {err.get('loc', [''])[0]}{Colors.END}")
331+
print(
332+
f" {Colors.MAGENTA}{Colors.ARROW} Invalid Value for {err.get('loc', [''])[0]}{Colors.END}"
333+
)
320334
if "permitted values:" in error_msg:
321-
options = error_msg.split("permitted values:")[-1].strip()
335+
options = error_msg.split("permitted values:")[
336+
-1
337+
].strip()
322338
print(f" Valid options: {options}")
323339
elif "Extra inputs" in error_msg:
324-
print(f" {Colors.BLUE}❌ Unexpected Field: {err.get('loc', [''])[0]}{Colors.END}")
340+
print(
341+
f" {Colors.BLUE}❌ Unexpected Field: {err.get('loc', [''])[0]}{Colors.END}"
342+
)
325343
elif "Failed to find" in error_msg:
326-
print(f" {Colors.RED}🔍 Missing Reference: {error_msg}{Colors.END}")
344+
print(
345+
f" {Colors.RED}🔍 Missing Reference: {error_msg}{Colors.END}"
346+
)
327347
else:
328348
print(f" {Colors.RED}{error_msg}{Colors.END}")
329349
else:
@@ -333,14 +353,26 @@ def createSecurityContent(self, contentType: SecurityContentType) -> None:
333353
# Clean footer with next steps
334354
max_width = max(60, max(len(str(e[0])) + 15 for e in validation_errors))
335355
print(f"{Colors.BOLD}{Colors.CYAN}{'═' * max_width}{Colors.END}")
336-
print(f"{Colors.BOLD}{Colors.CYAN}{Colors.BLUE}{'🎯 Next Steps':^{max_width}}{Colors.CYAN}{Colors.END}")
356+
print(
357+
f"{Colors.BOLD}{Colors.CYAN}{Colors.BLUE}{'🎯 Next Steps':^{max_width}}{Colors.CYAN}{Colors.END}"
358+
)
337359
print(f"{Colors.BOLD}{Colors.CYAN}{'═' * max_width}{Colors.END}\n")
338360

339-
print(f"{Colors.GREEN}{Colors.TOOLS} Fix the validation issues in the listed files{Colors.END}")
340-
print(f"{Colors.YELLOW}{Colors.DOCS} Check the documentation: {Colors.UNDERLINE}https://github.com/splunk/contentctl{Colors.END}")
341-
print(f"{Colors.BLUE}{Colors.BULB} Use --verbose for detailed error information{Colors.END}\n")
342-
343-
raise ValidationFailedError(f"Validation failed with {len(validation_errors)} error(s)")
361+
print(
362+
f"{Colors.GREEN}{Colors.TOOLS} Fix the validation issues in the listed files{Colors.END}"
363+
)
364+
print(
365+
f"{Colors.YELLOW}{Colors.DOCS} Check the documentation: {Colors.UNDERLINE}https://github.com/splunk/contentctl{Colors.END}"
366+
)
367+
print(
368+
f"{Colors.BLUE}{Colors.BULB} Use --verbose for detailed error information{Colors.END}\n"
369+
)
370+
371+
raise ValidationFailedError(
372+
f"Validation failed with {len(validation_errors)} error(s)"
373+
)
344374

345375
# Success case
346-
print(f"\r{f'{contentType.name.upper()} Progress'.rjust(23)}: [{progress_percent:3.0f}%]... {Colors.GREEN}{Colors.CHECK_MARK} Done!{Colors.END}")
376+
print(
377+
f"\r{f'{contentType.name.upper()} Progress'.rjust(23)}: [{progress_percent:3.0f}%]... {Colors.GREEN}{Colors.CHECK_MARK} Done!{Colors.END}"
378+
)

0 commit comments

Comments
 (0)