2121from intelmq .lib import utils # type: ignore
2222from typing_extensions import Literal # Python 3.8+
2323
24- import intelmq_api .config
25- import intelmq_api .files as files
26- import intelmq_api .runctl as runctl
27- import intelmq_api .session as session
24+ import intelmq . app .config
25+ import intelmq . app . api .files as files
26+ import intelmq . app . api .runctl as runctl
27+ import intelmq . app . api .session as session
2828
29- from . dependencies import (api_config , cached_response , session_store ,
30- token_authorization )
29+ from intelmq . app . dependencies import (app_config , cached_response , session_store ,
30+ token_authorization )
3131from .models import TokenResponse
3232
33- api = APIRouter ()
33+ router = APIRouter ()
3434
3535
3636Levels = Literal ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" , "ALL" ]
@@ -48,11 +48,11 @@ def ID(id: str) -> str:
4848 return id
4949
5050
51- def runner (config : intelmq_api . config .Config = Depends (api_config )):
51+ def runner (config : intelmq . app . config .Config = Depends (app_config )):
5252 return runctl .RunIntelMQCtl (config .intelmq_ctl_cmd )
5353
5454
55- def file_access (config : intelmq_api . config .Config = Depends (api_config )):
55+ def file_access (config : intelmq . app . config .Config = Depends (app_config )):
5656 return files .FileAccess (config )
5757
5858
@@ -67,65 +67,71 @@ def render(self, content: runctl.JSONFile) -> bytes:
6767 return content
6868
6969
70- @api .get ("/api/botnet" , dependencies = [authorized ])
70+ @router .get ("/" )
71+ def api_base_url ():
72+ """Do not rename or delete!"""
73+ return JSONResponse ({})
74+
75+
76+ @router .get ("/botnet" , dependencies = [authorized ])
7177def botnet (action : Actions , group : typing .Optional [Groups ] = None ,
7278 runner : runctl .RunIntelMQCtl = Depends (runner )):
7379 return JSONFileResponse (runner .botnet (action , group ))
7480
7581
76- @api .get ("/api /bot" , dependencies = [authorized ])
82+ @router .get ("/bot" , dependencies = [authorized ])
7783def bot (action : Actions , id : str = Depends (ID ), runner : runctl .RunIntelMQCtl = Depends (runner )):
7884 return JSONFileResponse (runner .bot (action , id ))
7985
8086
81- @api .get ("/api /getlog" , dependencies = [authorized , cached ])
87+ @router .get ("/getlog" , dependencies = [authorized , cached ])
8288def get_log (lines : int , id : str = Depends (ID ), level : Levels = "DEBUG" ,
8389 runner : runctl .RunIntelMQCtl = Depends (runner )):
8490 return JSONFileResponse (runner .log (id , lines , level ))
8591
8692
87- @api .get ("/api /queues" , dependencies = [authorized , cached ])
93+ @router .get ("/queues" , dependencies = [authorized , cached ])
8894def queues (runner : runctl .RunIntelMQCtl = Depends (runner )):
8995 return JSONFileResponse (runner .list ("queues" ))
9096
9197
92- @api .get ("/api /queues-and-status" , dependencies = [authorized , cached ])
98+ @router .get ("/queues-and-status" , dependencies = [authorized , cached ])
9399def queues_and_status (runner : runctl .RunIntelMQCtl = Depends (runner )):
94100 return JSONFileResponse (runner .list ("queues-and-status" ))
95101
96102
97- @api .get ("/api /bots" , dependencies = [authorized , cached ])
103+ @router .get ("/bots" , dependencies = [authorized , cached ])
98104def bots (runner : runctl .RunIntelMQCtl = Depends (runner )):
99105 return JSONFileResponse (runner .list ("bots" ))
100106
101107
102- @api .get ("/api /version" , dependencies = [authorized ], response_model = dict )
108+ @router .get ("/version" , dependencies = [authorized ], response_model = dict )
103109def version (runner : runctl .RunIntelMQCtl = Depends (runner )):
104110 return runner .version ()
105111
106112
107- @api .get ("/api /check" , dependencies = [authorized ])
113+ @router .get ("/check" , dependencies = [authorized ])
108114def check (runner : runctl .RunIntelMQCtl = Depends (runner )):
109115 return JSONFileResponse (runner .check ())
110116
111117
112- @api .get ("/api /clear" , dependencies = [authorized ])
118+ @router .get ("/clear" , dependencies = [authorized ])
113119def clear (id : str = Depends (ID ), runner : runctl .RunIntelMQCtl = Depends (runner )):
114120 return JSONFileResponse (runner .clear (id ))
115121
116122
117- @api .post ("/api /run" , dependencies = [authorized ], response_model = str )
123+ @router .post ("/run" , dependencies = [authorized ], response_model = str )
118124def run (bot : str , cmd : BotCmds , show : bool = False , dry : bool = False , msg : str = Form (default = "" ),
119125 runner : runctl .RunIntelMQCtl = Depends (runner )):
120126 return runner .run (bot , cmd , show , dry , msg )
121127
122128
123- @api .get ("/api /debug" , dependencies = [authorized ])
129+ @router .get ("/debug" , dependencies = [authorized ])
124130def debug (runner : runctl .RunIntelMQCtl = Depends (runner )):
125131 return JSONFileResponse (runner .debug ())
126132
127133
128- @api .get ("/api /config" , dependencies = [authorized ])
134+ @router .get ("/config" , dependencies = [authorized ])
129135def config (file : str , fetch : bool = False ,
130136 file_access : files .FileAccess = Depends (file_access )):
131137 result = file_access .load_file_or_directory (file , fetch )
@@ -136,7 +142,7 @@ def config(file: str, fetch: bool = False,
136142 return Response (contents , headers = {"content-type" : content_type })
137143
138144
139- @api .post ("/api /login" , status_code = status .HTTP_200_OK , response_model = TokenResponse )
145+ @router .post ("/login" , status_code = status .HTTP_200_OK , response_model = TokenResponse )
140146def login (username : str = Form (...), password : str = Form (...),
141147 session : session .SessionStore = Depends (session_store )):
142148 if session is None :
@@ -156,7 +162,7 @@ def login(username: str = Form(...), password: str = Form(...),
156162 detail = "Invalid username and/or password." )
157163
158164
159- @api .get ("/api /harmonization" , dependencies = [authorized ], response_model = dict )
165+ @router .get ("/harmonization" , dependencies = [authorized ], response_model = dict )
160166def get_harmonization (runner : runctl .RunIntelMQCtl = Depends (runner )):
161167 harmonization = pathlib .Path ('/opt/intelmq/etc/harmonization.conf' )
162168 paths = runner .get_paths ()
@@ -169,16 +175,13 @@ def get_harmonization(runner: runctl.RunIntelMQCtl = Depends(runner)):
169175 return {}
170176
171177
172- @api .get ("/api /runtime" , dependencies = [authorized ], response_model = dict )
178+ @router .get ("/runtime" , dependencies = [authorized ], response_model = dict )
173179def get_runtime ():
174180 return utils .get_runtime ()
175181
176182
177- @api .post ("/api//runtime" , dependencies = [authorized ], response_model = str , deprecated = True ,
178- description = "Invalid path for compatibility with older IntelMQ Manager versions" ,
179- response_class = PlainTextResponse )
180- @api .post ("/api/runtime" , dependencies = [authorized ], response_model = str ,
181- response_class = PlainTextResponse )
183+ @router .post ("/runtime" , dependencies = [authorized ], response_model = str ,
184+ response_class = PlainTextResponse )
182185def post_runtime (body : dict ):
183186 try :
184187 utils .set_runtime (body )
@@ -188,7 +191,7 @@ def post_runtime(body: dict):
188191 return str (e )
189192
190193
191- @api .get ("/api /positions" , dependencies = [authorized ], response_model = dict )
194+ @router .get ("/positions" , dependencies = [authorized ], response_model = dict )
192195def get_positions (runner : runctl .RunIntelMQCtl = Depends (runner )):
193196 positions = pathlib .Path ('/opt/intelmq/etc/manager/positions.conf' )
194197 paths = runner .get_paths ()
@@ -201,11 +204,8 @@ def get_positions(runner: runctl.RunIntelMQCtl = Depends(runner)):
201204 return {}
202205
203206
204- @api .post ("/api//positions" , dependencies = [authorized ], response_model = str , deprecated = True ,
205- description = "Invalid path for compatibility with older IntelMQ Manager versions" ,
206- response_class = PlainTextResponse )
207- @api .post ("/api/positions" , dependencies = [authorized ], response_model = str ,
208- response_class = PlainTextResponse )
207+ @router .post ("/positions" , dependencies = [authorized ], response_model = str ,
208+ response_class = PlainTextResponse )
209209def post_positions (body : dict , runner : runctl .RunIntelMQCtl = Depends (runner )):
210210 positions = pathlib .Path ('/opt/intelmq/etc/manager/positions.conf' )
211211 paths = runner .get_paths ()
0 commit comments