diff --git a/app/routes/api.py b/app/routes/api.py index 3858cfb..ae09efd 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -2,7 +2,7 @@ import json from fastapi import APIRouter, Depends, HTTPException, Request from app.auth import get_current_agent from app.scopes import has_scope_access, ALL_SCOPES -from app.models import get_rule, get_all_rules, get_all_ports, add_audit_log, set_rule +from app.models import get_rule, get_all_rules, get_all_ports, add_audit_log, set_rule, filter_content_for_agent router = APIRouter(prefix="/api") @@ -21,7 +21,7 @@ async def get_scope_rules(scope: str, request: Request, agent: str = Depends(get if not rule: raise HTTPException(status_code=404, detail="Scope not found") - return rule + return filter_content_for_agent(rule, agent) @router.get("/ports") async def get_ports_registry(request: Request, agent: str = Depends(get_current_agent)): @@ -42,10 +42,10 @@ async def search_rules(q: str, request: Request, agent: str = Depends(get_curren for scope in ALL_SCOPES: if has_scope_access(agent, scope): - content = all_rules.get(scope, {}) + scope_content = filter_content_for_agent(all_rules.get(scope, {}), agent) # Basic string matching in JSON serialization - if q.lower() in json.dumps(content).lower(): - results[scope] = content + if q.lower() in json.dumps(scope_content).lower(): + results[scope] = scope_content return results @@ -70,6 +70,6 @@ async def get_agent_context(request: Request, agent: str = Depends(get_current_a result = {} for scope in ALL_SCOPES: if has_scope_access(agent, scope): - result[scope] = all_rules.get(scope, {}) + result[scope] = filter_content_for_agent(all_rules.get(scope, {}), agent) ports = await get_all_ports() return {"agent": agent, "scopes": result, "ports": ports}