Skip to content

Commit 1adfafe

Browse files
committed
refactor(csv): 미사용 CSV 엔드포인트 제거 + 대시보드 패널 기본값 회귀 수정
CSV 다운로드 일원화 정리 1단계. - /fleet/hosts, /zabbix/hosts 의 format=csv 브랜치 삭제 — 프런트 소비자 0, 자산 CSV 는 /assets?format=csv 로 일원화됨(중복 제거). JSON 응답은 유지. - fix: 대시보드 'PC 자산 현황' 패널 추가 시 DEFAULT_USER_DASHBOARD_PREFERENCES ["sections"] 에 fleet_status 기본값 누락 → /dashboard/preferences KeyError 회귀 수정.
1 parent 0d8ccd2 commit 1adfafe

2 files changed

Lines changed: 7 additions & 40 deletions

File tree

src/mori_soc/api/routes/sources.py

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,57 +53,23 @@ def _session_role(request: Request) -> str | None:
5353

5454
# ── Fleet 전용 API ───────────────────────────────────────────────────────
5555
@app.get("/fleet/hosts", tags=["Fleet"])
56-
def fleet_hosts_get(format: str = "json") -> Any:
57-
"""Fleet(PC 자산) 전용 호스트 목록 API."""
56+
def fleet_hosts_get() -> Any:
57+
"""Fleet(PC 자산) 전용 호스트 목록 API (JSON). CSV 는 /assets?format=csv 로 일원화."""
5858
try:
5959
payload = build_assets_payload(get_query_service(), owners=asset_owners, plans=action_plans, vuln_actions=vuln_actions)
6060
except Exception as exc:
6161
raise HTTPException(status_code=503, detail=f"fleet hosts unavailable: {exc}") from exc
62-
fleet_data = payload.get("fleet", {})
63-
if format == "csv":
64-
import io, csv as csv_mod
65-
buf = io.StringIO()
66-
hosts = fleet_data.get("hosts", [])
67-
if hosts:
68-
_fleet_header_map = {"hostname": "호스트명", "asset_type": "자산유형", "platform": "플랫폼", "primary_ip": "IP주소", "status": "상태", "risk_score": "위험점수", "last_seen_at": "최종확인일시", "owner": "담당자", "team": "팀"}
69-
fieldnames = list(_fleet_header_map.keys())
70-
writer = csv_mod.DictWriter(buf, fieldnames=fieldnames, extrasaction="ignore")
71-
writer.writerow(_fleet_header_map)
72-
writer.writerows(hosts)
73-
timestamp = datetime.now(tz=timezone.utc).strftime("%Y%m%dT%H%M%SZ")
74-
return StreamingResponse(
75-
iter([buf.getvalue()]),
76-
media_type="text/csv; charset=utf-8",
77-
headers={"Content-Disposition": f'attachment; filename="mori-fleet-hosts-{timestamp}.csv"'},
78-
)
79-
return {"source": "fleet", **fleet_data}
62+
return {"source": "fleet", **payload.get("fleet", {})}
8063

8164
# ── Zabbix 전용 API ──────────────────────────────────────────────────────
8265
@app.get("/zabbix/hosts", tags=["Zabbix"])
83-
def zabbix_hosts_get(format: str = "json") -> Any:
84-
"""Zabbix(서버 자산) 전용 호스트 목록 API."""
66+
def zabbix_hosts_get() -> Any:
67+
"""Zabbix(서버 자산) 전용 호스트 목록 API (JSON). CSV 는 /assets?format=csv 로 일원화."""
8568
try:
8669
payload = build_assets_payload(get_query_service(), owners=asset_owners, plans=action_plans, vuln_actions=vuln_actions)
8770
except Exception as exc:
8871
raise HTTPException(status_code=503, detail=f"zabbix hosts unavailable: {exc}") from exc
89-
zabbix_data = payload.get("zabbix", {})
90-
if format == "csv":
91-
import io, csv as csv_mod
92-
buf = io.StringIO()
93-
hosts = zabbix_data.get("hosts", [])
94-
if hosts:
95-
_zabbix_header_map = {"hostname": "호스트명", "category": "분류", "importance": "중요도", "primary_ip": "IP주소", "status": "상태", "latest_metric": "최근메트릭", "latest_value": "최근값", "owner": "담당자", "team": "팀"}
96-
fieldnames = list(_zabbix_header_map.keys())
97-
writer = csv_mod.DictWriter(buf, fieldnames=fieldnames, extrasaction="ignore")
98-
writer.writerow(_zabbix_header_map)
99-
writer.writerows(hosts)
100-
timestamp = datetime.now(tz=timezone.utc).strftime("%Y%m%dT%H%M%SZ")
101-
return StreamingResponse(
102-
iter([buf.getvalue()]),
103-
media_type="text/csv; charset=utf-8",
104-
headers={"Content-Disposition": f'attachment; filename="mori-zabbix-hosts-{timestamp}.csv"'},
105-
)
106-
return {"source": "zabbix", **zabbix_data}
72+
return {"source": "zabbix", **payload.get("zabbix", {})}
10773

10874
# ── Trivy 전용 API ───────────────────────────────────────────────────────
10975
@app.get("/trivy/vulnerabilities", tags=["Trivy"])

src/mori_soc/api/templates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"sections": {
7272
"security_hero": True,
7373
"infra_status": True,
74+
"fleet_status": True,
7475
"source_coverage": False,
7576
"latest_status": False,
7677
"risk_summary": True,

0 commit comments

Comments
 (0)