-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate AquaSec fetch directly into pipeline #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
227087d
Migrate AquaSec fetch directly into pipeline, removing SARIF intermed…
tmikula-dev 9026ff7
CodeRabbit comments implementation.
tmikula-dev b61d9ea
Improving the notification sender logging.
tmikula-dev b9e4484
Merge branch 'master' into feature/migrating-aquasec-repo
tmikula-dev 9bf6e27
config.py bug fix finally
tmikula-dev 7193167
config.py bug fix finally
tmikula-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # | ||
| # Copyright 2026 ABSA Group Limited | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| """Parse AquaSec Night Scan JSON output into Alert dataclasses.""" | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from security.alerts.models import Alert, AlertDetails, AlertMetadata, LoadedAlerts, RuleDetails | ||
| from security.constants import LOGGING_PREFIX, SEVERITY_MAP | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _map_severity(numeric_severity: int) -> str: | ||
| """Map numeric AquaSec severity to lowercase string.""" | ||
| return SEVERITY_MAP.get(numeric_severity, "unknown") | ||
|
|
||
|
|
||
| def _format_bullet_list(items: list[str] | None) -> str: | ||
| """Format a list of strings as a Markdown bullet list.""" | ||
| if not items: | ||
| return "" | ||
| return "\n".join(f"- {item}" for item in items) | ||
|
|
||
|
|
||
| def _parse_item(item: dict[str, Any], repo: str) -> Alert: | ||
| """Map a single AquaSec JSON item to an Alert dataclass.""" | ||
| extra = item.get("extraData") or {} | ||
| severity_str = _map_severity(item.get("severity", 0)) | ||
| references_raw = extra.get("references") | ||
| references_list = references_raw if isinstance(references_raw, list) else [] | ||
|
|
||
| metadata = AlertMetadata( | ||
| alert_number=0, | ||
| state="open", | ||
| created_at=item.get("first_seen", ""), | ||
| updated_at=item.get("scan_date", ""), | ||
| url="", | ||
| alert_url="", | ||
| rule_id=item.get("avd_id", ""), | ||
| rule_name=item.get("category", ""), | ||
| rule_description=item.get("title", ""), | ||
| severity=severity_str, | ||
| confidence="", | ||
| tags=[], | ||
| help_uri=references_list[0] if references_list else "", | ||
| tool="AquaSec", | ||
| tool_version="", | ||
| ref="", | ||
| commit_sha="", | ||
| instance_url=None, | ||
| classifications=[], | ||
| file=item.get("target_file", ""), | ||
| start_line=item.get("target_start_line") or None, | ||
| end_line=item.get("target_end_line") or None, | ||
| ) | ||
|
|
||
| alert_details = AlertDetails( | ||
| alert_hash=item.get("result_hash", ""), | ||
| artifact=item.get("target_file", ""), | ||
| type=item.get("category", ""), | ||
| vulnerability=item.get("avd_id", ""), | ||
| severity=severity_str.upper(), | ||
| repository=item.get("repository_full_name", ""), | ||
| reachable=str(item.get("reachable", False)), | ||
| scan_date=item.get("scan_date", ""), | ||
| first_seen=item.get("first_seen", ""), | ||
| scm_file=item.get("scm_file", ""), | ||
| installed_version=item.get("installed_version", ""), | ||
| start_line=str(item.get("target_start_line", "") or ""), | ||
| end_line=str(item.get("target_end_line", "") or ""), | ||
| message=item.get("message", ""), | ||
| ) | ||
|
|
||
| owasp_list = extra.get("owasp") | ||
|
|
||
| rule_details = RuleDetails( | ||
| type=item.get("category", ""), | ||
| severity=severity_str.upper(), | ||
| cwe=extra.get("cwe", ""), | ||
| fixed_version=item.get("fixed_version", ""), | ||
| published_date=item.get("published_date", ""), | ||
| package_name=item.get("package_name", ""), | ||
| category=extra.get("category", ""), | ||
| impact=extra.get("impact", ""), | ||
| confidence=extra.get("confidence", ""), | ||
| likelihood=extra.get("likelihood", ""), | ||
| remediation=extra.get("remediation", ""), | ||
| owasp=_format_bullet_list(owasp_list) if isinstance(owasp_list, list) else str(owasp_list or ""), | ||
| references=( | ||
| _format_bullet_list(references_list) if isinstance(references_list, list) else str(references_list or "") | ||
| ), | ||
| ) | ||
|
|
||
| return Alert(metadata=metadata, alert_details=alert_details, rule_details=rule_details, repo=repo) | ||
|
|
||
|
|
||
| class AquaSecParser: | ||
| """Parses AquaSec scan results into typed Alert objects.""" | ||
|
|
||
| def __init__(self, repo: str) -> None: | ||
| self.repo = repo | ||
|
|
||
| def parse(self, data: dict[str, Any]) -> LoadedAlerts: | ||
| """Parse AquaSec scan response dict and return LoadedAlerts. | ||
|
|
||
| Args: | ||
| data: AquaSec API response dict with 'total' and 'data' keys. | ||
|
|
||
| Returns: | ||
| LoadedAlerts with all parsed alerts indexed by position. | ||
| """ | ||
| items = data.get("data", []) | ||
| logger.info("%sLoaded %d findings from AquaSec response", LOGGING_PREFIX, len(items)) | ||
|
|
||
| open_by_number: dict[int, Alert] = {} | ||
| for idx, item in enumerate(items, start=1): | ||
| alert = _parse_item(item, self.repo) | ||
| alert.metadata.alert_number = idx | ||
| open_by_number[idx] = alert | ||
|
|
||
| logger.info("%sParsed %d alerts for repo %s", LOGGING_PREFIX, len(open_by_number), self.repo) | ||
| return LoadedAlerts(repo_full=self.repo, open_by_number=open_by_number) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.