Skip to content

Commit 7356b98

Browse files
authored
Bugfix added sink_support to push scans (#455)
1 parent 87ce07a commit 7356b98

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

robusta_krr/core/models/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Config(pd.BaseSettings):
6464
publish_scan_url: Optional[str] = pd.Field(None)
6565
start_time: Optional[str] = pd.Field(None)
6666
scan_id: Optional[str] = pd.Field(None)
67+
named_sinks: Optional[list[str]] = pd.Field(None)
6768

6869
# Output Settings
6970
file_output: Optional[str] = pd.Field(None)

robusta_krr/core/runner.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
import warnings
88
from concurrent.futures import ThreadPoolExecutor
9-
from typing import Optional, Union
9+
from typing import Optional, Union, List
1010
from datetime import timedelta, datetime
1111
from prometrix import PrometheusNotFound
1212
from rich.console import Console
@@ -110,7 +110,7 @@ def _process_result(self, result: Result) -> None:
110110

111111
Formatter = settings.Formatter
112112

113-
self._send_result(settings.publish_scan_url, settings.start_time, settings.scan_id, result)
113+
self._send_result(settings.publish_scan_url, settings.start_time, settings.scan_id, settings.named_sinks, result)
114114
formatted = result.format(Formatter)
115115
rich = getattr(Formatter, "__rich_console__", False)
116116

@@ -520,15 +520,15 @@ async def run(self) -> int:
520520
else:
521521
return 0 # Exit with success
522522

523-
def _send_result(self, url: str, start_time: datetime, scan_id: str, result: Result):
523+
def _send_result(self, url: str, start_time: datetime, scan_id: str,named_sinks: Optional[List[str]], result: Result):
524524
result_dict = json.loads(result.json(indent=2))
525-
_send_scan_payload(url, scan_id, start_time, result_dict, is_error=False)
525+
_send_scan_payload(url, scan_id, start_time, result_dict, named_sinks, is_error=False)
526526

527-
def publish_input_error(url: str, scan_id: str, start_time: str, error: str):
528-
_send_scan_payload(url, scan_id, start_time, error, is_error=True)
527+
def publish_input_error(url: str, scan_id: str, start_time: str, error: str, named_sinks: Optional[List[str]]):
528+
_send_scan_payload(url, scan_id, start_time, error, named_sinks, is_error=True)
529529

530530
def publish_error(error: str):
531-
_send_scan_payload(settings.publish_scan_url, settings.scan_id, settings.start_time, error, is_error=True)
531+
_send_scan_payload(settings.publish_scan_url, settings.scan_id, settings.start_time, error, settings.named_sinks, is_error=True)
532532

533533
@retry(
534534
stop=stop_after_attempt(3),
@@ -549,13 +549,14 @@ def _send_scan_payload(
549549
scan_id: str,
550550
start_time: Union[str, datetime],
551551
result_data: Union[str, dict],
552+
named_sinks: Optional[List[str]],
552553
is_error: bool = False
553554
):
554555
if not url or not scan_id or not start_time:
555556
logger.debug(f"Missing required parameters: url={bool(url)}, scan_id={bool(scan_id)}, start_time={bool(start_time)}")
556557
return
557558

558-
logger.debug(f"Preparing to send scan payload. scan_id={scan_id}, is_error={is_error}")
559+
logger.debug(f"Preparing to send scan payload. scan_id={scan_id}, to sink {named_sinks}, is_error={is_error}")
559560

560561
headers = {"Content-Type": "application/json"}
561562

@@ -572,6 +573,8 @@ def _send_scan_payload(
572573
"start_time": start_time,
573574
}
574575
}
576+
if named_sinks:
577+
action_request["sinks"] = named_sinks
575578

576579
try:
577580
_post_scan_request(url, headers, action_request, scan_id, is_error)

robusta_krr/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ def run_strategy(
308308
help="A UUID scan identifier",
309309
rich_help_panel="Publish Scan Settings",
310310
),
311+
named_sinks: Optional[List[str]] = typer.Option(
312+
None,
313+
"--named_sinks",
314+
help="A list of sinks to send the scan to",
315+
rich_help_panel="Publish Scan Settings",
316+
),
311317
**strategy_args,
312318
) -> None:
313319
f"""Run KRR using the `{_strategy_name}` strategy"""
@@ -359,11 +365,12 @@ def run_strategy(
359365
publish_scan_url=publish_scan_url,
360366
start_time=start_time,
361367
scan_id=scan_id,
368+
named_sinks=named_sinks,
362369
)
363370
Config.set_config(config)
364371
except ValidationError as e:
365372
logger.exception("Error occured while parsing arguments")
366-
publish_input_error( publish_scan_url, start_time, scan_id, str(e))
373+
publish_input_error( publish_scan_url, scan_id, start_time, str(e), named_sinks)
367374
else:
368375
runner = Runner()
369376
exit_code = asyncio.run(runner.run())

0 commit comments

Comments
 (0)