refactor(backend/api): extract SourcePolicyService (Step 4 — file 7 of 18)

compliance/api/source_policy_router.py (580 LOC) -> 253 LOC thin routes
+ 453-line SourcePolicyService + 83-line schemas file. Manages allowed
data sources, operations matrix, PII rules, blocked-content log,
audit trail, and dashboard stats/report.

Single-service split. ORM-based (uses compliance.db.source_policy_models).

Date-string parsing extracted to a module-level _parse_iso_optional
helper so the audit + blocked-content list endpoints share it instead
of duplicating try/except blocks.

Legacy test compat: SourceCreate, SourceUpdate, SourceResponse,
PIIRuleCreate, PIIRuleUpdate, OperationUpdate, _log_audit re-exported
from compliance.api.source_policy_router via __all__.

Verified:
  - 208/208 pytest pass (173 core + 35 source policy)
  - OpenAPI 360/484 unchanged
  - mypy compliance/ -> Success on 132 source files
  - source_policy_router.py 580 -> 253 LOC
  - Hard-cap violations: 12 -> 11

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sharang Parnerkar
2026-04-07 19:58:02 +02:00
parent b850368ec9
commit 7107a31496
5 changed files with 740 additions and 469 deletions

View File

@@ -47999,7 +47999,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response List Blocked Content Api V1 Admin Blocked Content Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48029,7 +48033,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Get Compliance Report Api V1 Admin Compliance Report Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48049,7 +48057,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Get Operations Matrix Api V1 Admin Operations Matrix Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48090,7 +48102,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Update Operation Api V1 Admin Operations Operation Id Put",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48138,7 +48154,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response List Pii Rules Api V1 Admin Pii Rules Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48176,7 +48196,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Create Pii Rule Api V1 Admin Pii Rules Post",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48217,7 +48241,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Delete Pii Rule Api V1 Admin Pii Rules Rule Id Delete",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48266,7 +48294,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Update Pii Rule Api V1 Admin Pii Rules Rule Id Put",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48369,7 +48401,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Get Policy Audit Api V1 Admin Policy Audit Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48399,7 +48435,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Get Policy Stats Api V1 Admin Policy Stats Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48463,7 +48503,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response List Sources Api V1 Admin Sources Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48501,7 +48545,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Create Source Api V1 Admin Sources Post",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48542,7 +48590,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Delete Source Api V1 Admin Sources Source Id Delete",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48581,7 +48633,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Get Source Api V1 Admin Sources Source Id Get",
"type": "object"
}
}
},
"description": "Successful Response"
@@ -48630,7 +48686,11 @@
"200": {
"content": {
"application/json": {
"schema": {}
"schema": {
"additionalProperties": true,
"title": "Response Update Source Api V1 Admin Sources Source Id Put",
"type": "object"
}
}
},
"description": "Successful Response"