Skip to content

Feature/policy manager api - #239

Open
cx-happy-yang wants to merge 3 commits into
masterfrom
feature/policy-manager-api
Open

cx-happy-yang wants to merge 3 commits into
masterfrom
feature/policy-manager-api

Conversation

@cx-happy-yang

Copy link
Copy Markdown
Contributor
  • [Add] PolicyManagerAPI for the Cx Policy Manager REST API (/api/policy_management_service_uri) — tenant policies (create/get/update/delete, V2/V3 pagination, pin, project assignment), policy violations, per-scan policy evaluation, incidents (including the enhanced V2 view), incident results, and internal data-retention cleanup. 27 endpoints, 22 new DTOs.

@cx-happy-yang cx-happy-yang self-assigned this Nov 6, 2026
@cx-happy-yang
cx-happy-yang requested a review from a team November 6, 2026 03:46
@cx-happy-yang cx-happy-yang added the workflows-approved A PR needs the label workflows-approved to run any workflows. label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Logo
Checkmarx One – Scan Summary & Details – a25ca146-8aba-4b9d-8e15-806a7243e8fb

Great job! No new security vulnerabilities introduced in this pull request

cx-happy-yang and others added 2 commits November 18, 2026 10:16
Implements all 27 endpoints of POLICY_MANAGER.yaml
(/api/policy_management_service_uri), previously entirely unwrapped:

- Policies: create/get/update/delete (plus V2/V3 pagination variants),
  pin/unpin, assign/remove projects, bulk delete, default policy.
- Projects: tenant projects and project tags as seen by Policy Manager.
- Policy violations and per-scan policy evaluation.
- Incidents: list/paginate/filter (including the enhanced V2 view with
  engine info), total count, and per-incident results.
- Internal data-retention cleanup endpoints (implemented, but
  deliberately not exercised in tests -- they delete data across
  services tenant-wide).

22 new DTOs under CxOne/dto/, registered in dto/__init__.py and
CxOne/__init__.py following the existing dataclass+from_dict/to_dict
convention (see riskOrchestrationAPI.py / scaManagementOfRiskAPI.py).

Verified against the live spec server and a real tenant, which turned
up two spec-vs-reality mismatches fixed before landing:
- DELETE /policies/{id}, /policies (bulk), /policies/projects/{id}
  actually respond 204 No Content, not the 200 the spec documents.
- POST /policies/v2 actually returns a bare int (the new policy ID),
  not the PolicyShortWebDto object the spec documents.

tests/CxOne/test_policy_manager_api.py exercises the full
create/get/update/pin/assign/delete lifecycle live (always cleaning up
what it creates), following this suite's existing convention of
skipping gracefully on 400/401/403/404 (used here for incidents/scan
endpoints this tenant doesn't have data or a feature flag for). 15
passed, 3 skipped for exactly that reason.

Also adds docs/swagger_yaml/CxOne/POLICY_MANAGER.yaml as the spec this
implementation was built from.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
docs/CxOne_REST_API_List.md was stale on this branch -- its generator
script only existed on the separate docs/refresh-cxone-api-reference
branch, which none of the feature branches were based on. Brought the
generator over (verbatim from that branch) and regenerated the list so
it reflects what's actually on this branch: master's existing
endpoints plus the new PolicyManagerAPI (27 endpoints).
test_get_incident_results and test_get_policy_violations previously
swallowed real conditions behind pytest.skip:
- test_get_incident_results skipped silently when the tenant had no
  incidents, instead of surfacing that there was nothing to assert.
- test_get_policy_violations caught ANY exception via
  _skip_on_client_error and skipped on 400/401/403/404, masking a
  real finding.

Removed both skips and ran live to see the real state:
- test_get_incident_results now fails with IndexError -- this tenant
  genuinely has zero policy incidents right now. Not an SDK bug.
- test_get_policy_violations now fails with a real 404 'The provided
  project ID ... and scan ID ... do not match'. Confirmed via direct
  comparison that this is NOT an actual ID mismatch:
  get_evaluated_policies_by_scan_id_and_project_id succeeds with the
  exact same project_id/scan_id pair, returning
  PoliciesResultWebDto(status='NONE', policies=[]) -- i.e. this scan
  was simply never evaluated by any policy. The live Policy Manager
  service's /policy_violations endpoint returns a misleading 404
  instead of an empty result for that case. SDK request (URL/params)
  is correct; this is a server-side quirk, not an SDK bug.

Left both failing as an accurate reflection of current tenant state
rather than restoring the skips -- CI (ci.yml) only runs build +
pylint, not these live pytest suites, so this doesn't block merging.
@cx-happy-yang

Copy link
Copy Markdown
Contributor Author

Hi @cx-james-bostock , please help me approve. I just resolved a merge conflict.

@cx-james-bostock cx-james-bostock 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.

Hi @cx-happy-yang,
Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

workflows-approved A PR needs the label workflows-approved to run any workflows.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants