remove the unused code

This commit is contained in:
rzeta-10 2026-04-04 19:00:43 +05:30
parent 467568ed26
commit af8ff6cdd5
2 changed files with 14 additions and 40 deletions

View file

@ -162,25 +162,6 @@ class AktoGuardrail(CustomGuardrail):
return body
@staticmethod
def build_response_body(
inputs: GenericGuardrailAPIInputs,
request_data: Optional[dict] = None,
) -> Dict[str, Any]:
"""Build the LLM response body, preferring the actual model response if available."""
model_response = request_data.get("response") if request_data else None
if model_response is not None and hasattr(model_response, "model_dump"):
return model_response.model_dump()
texts = inputs.get("texts", [])
if texts:
return {
"choices": [
{"message": {"content": t, "role": "assistant"}} for t in texts
]
}
return {}
@staticmethod
def build_tag_metadata(request_data: dict) -> Dict[str, str]:
"""Build tag/metadata dict with user_id and team_id for Akto tracking."""
@ -201,23 +182,17 @@ class AktoGuardrail(CustomGuardrail):
self,
inputs: GenericGuardrailAPIInputs,
request_data: dict,
*,
status_code: int = 200,
include_response: bool = False,
) -> Dict[str, Any]:
"""Build the MIRRORING payload for Akto's HTTP proxy endpoint."""
"""Build the MIRRORING payload for Akto's guardrail validation endpoint.
Response headers and payload are empty — the guardrail only sends
the request for validation, not the response.
"""
request_path = self.extract_request_path(request_data)
request_headers = self.build_request_headers(request_data)
request_body = self.build_request_body(inputs, request_data)
tag = self.build_tag_metadata(request_data)
response_payload = json.dumps({})
response_headers: Dict[str, str] = {}
if include_response:
response_body = self.build_response_body(inputs, request_data)
response_payload = json.dumps(response_body)
response_headers = {"content-type": "application/json"}
# Extract client IP from proxy headers
ip = ""
proxy_req = request_data.get("proxy_server_request", {})
@ -236,16 +211,16 @@ class AktoGuardrail(CustomGuardrail):
return {
"path": request_path,
"requestHeaders": json.dumps(request_headers),
"responseHeaders": json.dumps(response_headers),
"responseHeaders": json.dumps({}),
"method": "POST",
"requestPayload": json.dumps(request_body),
"responsePayload": response_payload,
"responsePayload": json.dumps({}),
"ip": ip,
"destIp": "127.0.0.1",
"time": str(int(datetime.now().timestamp() * 1000)),
"statusCode": str(status_code),
"statusCode": "200",
"type": "HTTP/1.1",
"status": str(status_code),
"status": "200",
"akto_account_id": self.akto_account_id,
"akto_vxlan_id": self.akto_vxlan_id,
"is_pending": "false",

View file

@ -181,14 +181,13 @@ def test_build_akto_payload(akto_validate, sample_inputs, sample_request_data):
assert len(payload["time"]) >= 13
def test_build_akto_payload_with_response(
def test_build_akto_payload_response_always_empty(
akto_validate, sample_inputs, sample_request_data
):
payload = akto_validate.build_akto_payload(
sample_inputs, sample_request_data, include_response=True
)
resp_body = json.loads(payload["responsePayload"])
assert "choices" in resp_body
payload = akto_validate.build_akto_payload(sample_inputs, sample_request_data)
assert payload["responsePayload"] == json.dumps({})
assert payload["responseHeaders"] == json.dumps({})
assert payload["statusCode"] == "200"
def test_build_akto_payload_custom_ids(sample_request_data):