Skip to content

feat(pan-cortex-xdr-intel): implement Cortex XDR API client with advanced authentication (#7184) - #7309

Open
Pauline Eustachy (Powlinett) wants to merge 3 commits into
feat/7183-pan-cortex-xdr-intel-settings-runtimefrom
feat/7184-pan-cortex-xdr-intel-api-client
Open

feat(pan-cortex-xdr-intel): implement Cortex XDR API client with advanced authentication (#7184)#7309
Pauline Eustachy (Powlinett) wants to merge 3 commits into
feat/7183-pan-cortex-xdr-intel-settings-runtimefrom
feat/7184-pan-cortex-xdr-intel-api-client

Conversation

@Powlinett

@Powlinett Pauline Eustachy (Powlinett) commented Aug 18, 2026

Copy link
Copy Markdown
Member

Proposed changes

  • Implement CortexXdrClient (src/cortex_xdr_client/client.py) on top of connectors_sdk.BaseClientApi, with Advanced API key authentication (x-xdr-auth-id, x-xdr-timestamp, x-xdr-nonce, Authorization headers, freshly generated per request to prevent replay attacks)
  • Add upsert_indicator/delete_indicator methods, request bodies validated and serialized via new Pydantic models (models.py) and a datetime_to_utc helper (utils.py)
  • Add typed client exceptions (exceptions.py): CortexXdrRequestBodyError and CortexXdrApiError, wrapping SDK/validation errors
  • Reuse the connector's own helper.connector_logger for consistent, structured client logging, via setter injection after construction, keeping CortexXdrClient's 3-parameter constructor frozen (per the feat(pan-cortex-xdr-intel): bootstrap bare skeleton and freeze concrete class contracts #7182 contract)
  • Add unit tests covering auth header generation (shape, hash correctness, freshness), request payload shapes, and error propagation

Related issues

Checklist

  • I consider the submitted work as finished
  • I have signed my commits using GPG key.
  • I tested the code for its functionality using different use cases
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality

Further comments

This PR is stacked on top of #7292 and #7293, and targets feat/2690-pan-cortex-xdr-intel-new-connector as its base branch, not master, 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 for application/json responses). This is out of scope here and tracked separately in #7299 to be fixed upstream in the SDK.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 5 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...n-cortex-xdr-intel/src/cortex_xdr_client/client.py 90.69% 4 Missing ⚠️
...an-cortex-xdr-intel/src/cortex_xdr_client/utils.py 80.00% 1 Missing ⚠️
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     
Files with missing lines Coverage Δ
...rtex-xdr-intel/src/cortex_xdr_client/exceptions.py 100.00% <100.00%> (ø)
...n-cortex-xdr-intel/src/cortex_xdr_client/models.py 100.00% <100.00%> (ø)
...an-cortex-xdr-intel/src/cortex_xdr_client/utils.py 80.00% <80.00%> (ø)
...n-cortex-xdr-intel/src/cortex_xdr_client/client.py 90.90% <90.69%> (+10.90%) ⬆️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Powlinett
Pauline Eustachy (Powlinett) changed the base branch from feat/2690-pan-cortex-xdr-intel-new-connector to feat/7183-pan-cortex-xdr-intel-settings-runtime August 18, 2026 08:56
Copilot AI lite review requested due to automatic review settings August 18, 2026 09:08
@Powlinett
Pauline Eustachy (Powlinett) force-pushed the feat/7184-pan-cortex-xdr-intel-api-client branch from 294ea67 to 71827f6 Compare August 18, 2026 09:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CortexXdrClient on top of connectors_sdk.BaseClientApi, including per-request Advanced auth header generation and upsert/delete indicator methods.
  • Add Pydantic models (IndicatorData, IndicatorFilters), a datetime_to_utc helper, 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 stdlib logging.Logger incompatibility as in upsert_indicator (extra positional args without % placeholders can raise TypeError).
        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 successful application/json response currently raises ValueError from BaseClientApi._parse_response() and will bypass this ApiClientError wrapper. Also, logger.error(msg, dict) is not stdlib-logger safe and can raise TypeError, 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.

Comment thread stream/pan-cortex-xdr-intel/src/cortex_xdr_client/client.py
Comment thread stream/pan-cortex-xdr-intel/src/cortex_xdr_client/client.py Outdated
Comment thread stream/pan-cortex-xdr-intel/src/cortex_xdr_client/client.py
@Powlinett
Pauline Eustachy (Powlinett) force-pushed the feat/7184-pan-cortex-xdr-intel-api-client branch 2 times, most recently from 392bcac to 92140ad Compare August 18, 2026 12:05
@Powlinett
Pauline Eustachy (Powlinett) force-pushed the feat/7184-pan-cortex-xdr-intel-api-client branch from 92140ad to 4fe921a Compare August 18, 2026 12:17
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(pan-cortex-xdr-intel): implement Cortex XDR client with advanced auth in src/api_client

3 participants