feat(pan-cortex-xdr-intel): implement Cortex XDR API client with advanced authentication (#7184) - #7309
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/7183-pan-cortex-xdr-intel-settings-runtime #7309 +/- ##
===================================================================================
+ Coverage 85.67% 86.52% +0.85%
===================================================================================
Files 9 12 +3
Lines 691 757 +66
===================================================================================
+ Hits 592 655 +63
- Misses 99 102 +3
📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
294ea67 to
71827f6
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements the Cortex XDR low-level API client for the stream/pan-cortex-xdr-intel connector, including Advanced API key authentication, typed request/response models, and unit tests to validate request shapes and error behavior.
Changes:
- Implement
CortexXdrClienton top ofconnectors_sdk.BaseClientApi, including per-request Advanced auth header generation and upsert/delete indicator methods. - Add Pydantic models (
IndicatorData,IndicatorFilters), adatetime_to_utchelper, and typed client exceptions. - Add unit tests for auth header generation, payload serialization, and error propagation; wire the connector to inject the helper’s logger into the client.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| stream/pan-cortex-xdr-intel/src/cortex_xdr_client/client.py | Implements the API client, auth header generation, and upsert/delete methods with error wrapping. |
| stream/pan-cortex-xdr-intel/src/cortex_xdr_client/models.py | Adds Pydantic request-body models and datetime serialization for API payloads. |
| stream/pan-cortex-xdr-intel/src/cortex_xdr_client/utils.py | Adds a helper to normalize datetimes to UTC prior to serialization. |
| stream/pan-cortex-xdr-intel/src/cortex_xdr_client/exceptions.py | Introduces typed client exceptions for validation and API failures. |
| stream/pan-cortex-xdr-intel/src/connector/connector.py | Injects the connector helper logger into the client for consistent logging. |
| stream/pan-cortex-xdr-intel/tests/tests_cortex_xdr_client/test_client.py | Adds unit tests for auth headers, request payloads, and error propagation/logging. |
| stream/pan-cortex-xdr-intel/tests/test_main.py | Extends main wiring test to assert logger injection into the client. |
Suppressed comments (2)
stream/pan-cortex-xdr-intel/src/cortex_xdr_client/client.py:139
- This
logger.error(msg, dict)call has the same stdliblogging.Loggerincompatibility as inupsert_indicator(extra positional args without%placeholders can raiseTypeError).
except ValidationError as err:
self.logger.error("Invalid request's body", {"error": str(err)})
raise CortexXdrRequestBodyError("Invalid request's body") from err
stream/pan-cortex-xdr-intel/src/cortex_xdr_client/client.py:155
- Same as
upsert_indicator: malformed JSON in a successfulapplication/jsonresponse currently raisesValueErrorfromBaseClientApi._parse_response()and will bypass thisApiClientErrorwrapper. Also,logger.error(msg, dict)is not stdlib-logger safe and can raiseTypeError, masking the real error.
except ApiClientError as err:
self.logger.error(
"Error while fetching Cortex XDR API", {"error": str(err)}
)
raise CortexXdrApiError("Error while fetching Cortex XDR API") from err
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
392bcac to
92140ad
Compare
92140ad to
4fe921a
Compare
…r upsert/delete Add the concrete CortexXdrClient implementation built on connectors_sdk.BaseClientApi: - Advanced API key authentication (per-request nonce/timestamp/hash headers) - session_headers for Content-Type/Accept - upsert_indicator/delete_indicator, validated and serialized via new Pydantic models (models.py) and a datetime_to_utc helper (utils.py) - typed client exceptions (exceptions.py) wrapping SDK/validation errors
Cover CortexXdrClient's init/session headers, Advanced auth header generation (shape, hash correctness, freshness), upsert_indicator/delete_indicator request payload shapes, per-request auth headers, error wrapping into CortexXdrApiError/CortexXdrRequestBodyError, and the overridable logger attribute.
move misplaced parenthesis Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
4fe921a to
e43b814
Compare
Proposed changes
CortexXdrClient(src/cortex_xdr_client/client.py) on top ofconnectors_sdk.BaseClientApi, with Advanced API key authentication (x-xdr-auth-id,x-xdr-timestamp,x-xdr-nonce,Authorizationheaders, freshly generated per request to prevent replay attacks)upsert_indicator/delete_indicatormethods, request bodies validated and serialized via new Pydantic models (models.py) and adatetime_to_utchelper (utils.py)exceptions.py):CortexXdrRequestBodyErrorandCortexXdrApiError, wrapping SDK/validation errorshelper.connector_loggerfor consistent, structured client logging, via setter injection after construction, keepingCortexXdrClient's 3-parameter constructor frozen (per the feat(pan-cortex-xdr-intel): bootstrap bare skeleton and freeze concrete class contracts #7182 contract)Related issues
Checklist
Further comments
This PR is stacked on top of #7292 and #7293, and targets
feat/2690-pan-cortex-xdr-intel-new-connectoras its base branch, notmaster, following the same pattern as its predecessors.CortexXdrClient's 3-parameter constructor (api_base_url,api_key_id,api_key) remains frozen and unchanged from #7182.While implementing this client, a pre-existing bug was found in
connectors_sdk.BaseClientApi._parse_response(it does not wrap malformed JSON body errors forapplication/jsonresponses). This is out of scope here and tracked separately in #7299 to be fixed upstream in the SDK.