forked from EmpireProject/Empire
-
-
Notifications
You must be signed in to change notification settings - Fork 576
/
listener_template_api.py
49 lines (39 loc) · 1.36 KB
/
listener_template_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from fastapi import Depends, HTTPException
from empire.server.api.api_router import APIRouter
from empire.server.api.jwt_auth import get_current_active_user
from empire.server.api.v2.listener.listener_dto import (
ListenerTemplate,
ListenerTemplates,
domain_to_dto_template,
)
from empire.server.api.v2.shared_dto import BadRequestResponse, NotFoundResponse
from empire.server.server import main
listener_template_service = main.listenertemplatesv2
router = APIRouter(
prefix="/api/v2/listener-templates",
tags=["listener-templates"],
responses={
404: {"description": "Not found", "model": NotFoundResponse},
400: {"description": "Bad request", "model": BadRequestResponse},
},
dependencies=[Depends(get_current_active_user)],
)
@router.get(
"/",
response_model=ListenerTemplates,
)
async def get_listener_templates():
templates = [
domain_to_dto_template(x[1], x[0])
for x in listener_template_service.get_listener_templates().items()
]
return {"records": templates}
@router.get(
"/{uid}",
response_model=ListenerTemplate,
)
async def get_listener_template(uid: str):
template = listener_template_service.get_listener_template(uid)
if not template:
raise HTTPException(status_code=404, detail="Listener template not found")
return domain_to_dto_template(template, uid)