Skip to content

Commit aecfbff

Browse files
committed
Merge branch 'main' into feature/integrations-pt1-integrations
# By Mihir Vala (9) and Isha Shree (2) # Via Mihir Vala (2) and GitHub (1) * main: chore: fix unit tests chore: minor refactoring and formatting chore: added docs in README and CLI. Added changelog. Updated project version. chore: added client integration tests chore: fixed unit tests chore: case integration tests fix chore: fixed unit tests chore: refactoring and improvements chore: fixed unnessary changes Addressing comments Adding new APIs in cli # Conflicts: # README.md # api_module_mapping.md
2 parents 1a55e95 + 35b10ff commit aecfbff

14 files changed

Lines changed: 694 additions & 5 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.40.0] - 2026-04-06
9+
### Added
10+
- Parser validation methods
11+
- `trigger_github_checks()` - Trigger GitHub checks for a parser against an associated pull request
12+
- `get_analysis_report()` - Retrieve a completed parser analysis report
13+
- CLI support for parser validation commands
14+
- `secops log-type trigger-checks` - Trigger parser validation checks for a PR
15+
- `secops log-type get-analysis-report` - Get details of a specific analysis report
16+
817
## [0.39.0] - 2026-04-02
918
### Updated
1019
- Refactored Chronicle modules to use centralized `chronicle_request` and `chronicle_paginated_request` helper functions for improved code consistency and maintainability

CLI.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,22 @@ Error messages are detailed and help identify issues:
696696
- Size limit violations
697697
- API-specific errors
698698

699+
#### Parser Validation
700+
701+
You can trigger and retrieve analysis reports for parsers associated with GitHub pull requests.
702+
703+
Trigger GitHub checks for a parser:
704+
705+
```bash
706+
secops log-type trigger-checks --log-type "WINDOWS_AD" --associated-pr "owner/repo/pull/123"
707+
```
708+
709+
Get a parser analysis report:
710+
711+
```bash
712+
secops log-type get-analysis-report --log-type "WINDOWS_AD" --parser-id "pa_12345" --report-id "report_12345"
713+
```
714+
699715
### Parser Extension Management
700716

701717
Parser extensions provide a flexible way to extend the capabilities of existing default (or custom) parsers without replacing them.

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from tests.chronicle.test_rule_integration import chronicle
2-
31
# Google SecOps SDK for Python
42

53
[![PyPI version](https://img.shields.io/pypi/v/secops.svg)](https://pypi.org/project/secops/)
@@ -1901,6 +1899,28 @@ This workflow is useful for:
19011899
- Debugging parsing issues
19021900

19031901
### Parser Extension
1902+
### Parser Validation
1903+
1904+
Trigger and retrieve analysis reports for parsers associated with GitHub pull requests:
1905+
1906+
```python
1907+
# Trigger GitHub checks for a parser against a PR
1908+
response = chronicle.trigger_github_checks(
1909+
associated_pr="owner/repo/pull/123",
1910+
log_type="WINDOWS_AD"
1911+
)
1912+
print(f"Triggered checks: {response}")
1913+
1914+
# Retrieve the analysis report
1915+
report = chronicle.get_analysis_report(
1916+
log_type="WINDOWS_AD",
1917+
parser_id="pa_1234567890",
1918+
report_id="report_0987654321"
1919+
)
1920+
print(f"Analysis report: {report}")
1921+
```
1922+
1923+
## Parser Extension
19041924

19051925
Parser extensions provide a flexible way to extend the capabilities of existing default (or custom) parsers without replacing them. The extensions let you customize the parser pipeline by adding new parsing logic, extracting and transforming fields, and updating or removing UDM field mappings.
19061926

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "secops"
7-
version = "0.39.0"
7+
version = "0.40.0"
88
description = "Python SDK for wrapping the Google SecOps API for common use cases"
99
readme = "README.md"
1010
requires-python = ">=3.10"

src/secops/chronicle/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def execute_bulk_assign(
173173
Raises:
174174
APIError: If the API request fails
175175
"""
176-
body = {"casesIds": case_ids, "username": username}
176+
body = {"casesIds": case_ids, "userName": username}
177177

178178
return chronicle_request(
179179
client,

src/secops/chronicle/client.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@
351351
create_watchlist as _create_watchlist,
352352
update_watchlist as _update_watchlist,
353353
)
354+
from secops.chronicle.parser import (
355+
get_analysis_report as _get_analysis_report,
356+
trigger_github_checks as _trigger_github_checks,
357+
)
354358
from secops.exceptions import SecOpsError
355359
from secops.chronicle.soar import SOARService
356360

@@ -783,6 +787,59 @@ def update_watchlist(
783787
update_mask,
784788
)
785789

790+
def get_analysis_report(
791+
self,
792+
log_type: str,
793+
parser_id: str,
794+
report_id: str,
795+
timeout: int = 60,
796+
) -> dict[str, Any]:
797+
"""Get a parser analysis report.
798+
Args:
799+
log_type: Log type of the parser.
800+
parser_id: The ID of the parser.
801+
report_id: The ID of the analysis report.
802+
timeout: Optional timeout in seconds (default: 60).
803+
Returns:
804+
Dictionary containing the analysis report.
805+
Raises:
806+
APIError: If the API request fails.
807+
"""
808+
return _get_analysis_report(
809+
self,
810+
log_type=log_type,
811+
parser_id=parser_id,
812+
report_id=report_id,
813+
timeout=timeout,
814+
)
815+
816+
def trigger_github_checks(
817+
self,
818+
associated_pr: str,
819+
log_type: str,
820+
timeout: int = 60,
821+
) -> dict[str, Any]:
822+
"""Trigger GitHub checks for a parser.
823+
824+
Args:
825+
associated_pr: The PR string (e.g., "owner/repo/pull/123").
826+
log_type: The string name of the LogType enum.
827+
timeout: Optional request timeout in seconds (default: 60).
828+
829+
Returns:
830+
Dictionary containing the response details.
831+
832+
Raises:
833+
SecOpsError: If modules or client stub are not available.
834+
APIError: If the API request fails.
835+
"""
836+
return _trigger_github_checks(
837+
self,
838+
associated_pr=associated_pr,
839+
log_type=log_type,
840+
timeout=timeout,
841+
)
842+
786843
def get_stats(
787844
self,
788845
query: str,

src/secops/chronicle/parser.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
import base64
1818
import json
19+
import logging
1920
from typing import Any
2021

22+
from secops.chronicle.models import APIVersion
2123
from secops.chronicle.utils.format_utils import remove_none_values
2224
from secops.chronicle.utils.request_utils import (
2325
chronicle_paginated_request,
2426
chronicle_request,
2527
)
28+
from secops.exceptions import APIError, SecOpsError
2629

2730
# Constants for size limits
2831
MAX_LOG_SIZE = 10 * 1024 * 1024 # 10MB per log
@@ -433,3 +436,121 @@ def run_parser(
433436
print(f"Warning: Failed to parse statedump: {e}")
434437

435438
return result
439+
440+
441+
def trigger_github_checks(
442+
client: "ChronicleClient",
443+
associated_pr: str,
444+
log_type: str,
445+
timeout: int = 60,
446+
) -> dict[str, Any]:
447+
"""Trigger GitHub checks for a parser.
448+
449+
Args:
450+
client: ChronicleClient instance
451+
associated_pr: The PR string (e.g., "owner/repo/pull/123").
452+
log_type: The string name of the LogType enum.
453+
timeout: Optional request timeout in seconds (default: 60).
454+
455+
Returns:
456+
Dictionary containing the response details.
457+
458+
Raises:
459+
SecOpsError: If input is invalid.
460+
APIError: If the API request fails.
461+
"""
462+
463+
if not isinstance(log_type, str) or len(log_type.strip()) < 2:
464+
raise SecOpsError("log_type must be a valid string of length >= 2")
465+
466+
if not isinstance(associated_pr, str) or not associated_pr.strip():
467+
raise SecOpsError("associated_pr must be a non-empty string")
468+
469+
pr_parts = associated_pr.split("/")
470+
if len(pr_parts) != 4 or pr_parts[2] != "pull" or not pr_parts[3].isdigit():
471+
raise SecOpsError(
472+
"associated_pr must be in the format 'owner/repo/pull/<number>'"
473+
)
474+
if not isinstance(timeout, int) or timeout < 0:
475+
raise SecOpsError("timeout must be a non-negative integer")
476+
477+
try:
478+
parsers = list_parsers(client, log_type=log_type)
479+
except APIError as e:
480+
raise APIError(
481+
f"Failed to fetch parsers for log type {log_type}: {e}"
482+
) from e
483+
484+
if not parsers:
485+
logging.info(
486+
"No parsers found for log type %s. Using fallback parser ID.",
487+
log_type,
488+
)
489+
parser_name = f"logTypes/{log_type}/parsers/-"
490+
else:
491+
if len(parsers) > 1:
492+
logging.warning(
493+
"Multiple parsers found for log type %s. Using the first one.",
494+
log_type,
495+
)
496+
parser_name = parsers[0]["name"]
497+
498+
endpoint_path = f"{parser_name}:runAnalysis"
499+
payload = {
500+
"report_type": "GITHUB_PARSER_VALIDATION",
501+
"pull_request": associated_pr,
502+
}
503+
504+
return chronicle_request(
505+
client=client,
506+
method="POST",
507+
api_version="v1alpha",
508+
endpoint_path=endpoint_path,
509+
json=payload,
510+
timeout=timeout,
511+
)
512+
513+
514+
def get_analysis_report(
515+
client: "ChronicleClient",
516+
log_type: str,
517+
parser_id: str,
518+
report_id: str,
519+
timeout: int = 60,
520+
) -> dict[str, Any]:
521+
"""Get a parser analysis report.
522+
523+
Args:
524+
client: ChronicleClient instance
525+
log_type: Log type of the parser.
526+
parser_id: The ID of the parser.
527+
report_id: The ID of the analysis report.
528+
timeout: Optional timeout in seconds (default: 60).
529+
530+
Returns:
531+
Dictionary containing the analysis report.
532+
533+
Raises:
534+
SecOpsError: If input is invalid.
535+
APIError: If the API request fails.
536+
"""
537+
if not isinstance(log_type, str) or not log_type.strip():
538+
raise SecOpsError("log_type must be a non-empty string")
539+
if not isinstance(parser_id, str) or not parser_id.strip():
540+
raise SecOpsError("parser_id must be a non-empty string")
541+
if not isinstance(report_id, str) or not report_id.strip():
542+
raise SecOpsError("report_id must be a non-empty string")
543+
if not isinstance(timeout, int) or timeout < 0:
544+
raise SecOpsError("timeout must be a non-negative integer")
545+
546+
endpoint_path = (
547+
f"logTypes/{log_type}/parsers/{parser_id}/analysisReports/{report_id}"
548+
)
549+
550+
return chronicle_request(
551+
client=client,
552+
method="GET",
553+
api_version=APIVersion.V1ALPHA,
554+
endpoint_path=endpoint_path,
555+
timeout=timeout,
556+
)

src/secops/cli/cli_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from secops.cli.commands.investigation import setup_investigation_command
2727
from secops.cli.commands.iocs import setup_iocs_command
2828
from secops.cli.commands.log import setup_log_command
29+
from secops.cli.commands.log_type import setup_log_type_commands
2930
from secops.cli.commands.log_processing import (
3031
setup_log_processing_command,
3132
)
@@ -171,6 +172,7 @@ def build_parser() -> argparse.ArgumentParser:
171172
setup_investigation_command(subparsers)
172173
setup_iocs_command(subparsers)
173174
setup_log_command(subparsers)
175+
setup_log_type_commands(subparsers)
174176
setup_log_processing_command(subparsers)
175177
setup_parser_command(subparsers)
176178
setup_parser_extension_command(subparsers)

0 commit comments

Comments
 (0)