21
21
from intelmq .lib import utils # type: ignore
22
22
from typing_extensions import Literal # Python 3.8+
23
23
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
28
28
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 )
31
31
from .models import TokenResponse
32
32
33
- api = APIRouter ()
33
+ router = APIRouter ()
34
34
35
35
36
36
Levels = Literal ["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" , "ALL" ]
@@ -48,11 +48,11 @@ def ID(id: str) -> str:
48
48
return id
49
49
50
50
51
- def runner (config : intelmq_api . config .Config = Depends (api_config )):
51
+ def runner (config : intelmq . app . config .Config = Depends (app_config )):
52
52
return runctl .RunIntelMQCtl (config .intelmq_ctl_cmd )
53
53
54
54
55
- def file_access (config : intelmq_api . config .Config = Depends (api_config )):
55
+ def file_access (config : intelmq . app . config .Config = Depends (app_config )):
56
56
return files .FileAccess (config )
57
57
58
58
@@ -67,65 +67,71 @@ def render(self, content: runctl.JSONFile) -> bytes:
67
67
return content
68
68
69
69
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 ])
71
77
def botnet (action : Actions , group : typing .Optional [Groups ] = None ,
72
78
runner : runctl .RunIntelMQCtl = Depends (runner )):
73
79
return JSONFileResponse (runner .botnet (action , group ))
74
80
75
81
76
- @api .get ("/api /bot" , dependencies = [authorized ])
82
+ @router .get ("/bot" , dependencies = [authorized ])
77
83
def bot (action : Actions , id : str = Depends (ID ), runner : runctl .RunIntelMQCtl = Depends (runner )):
78
84
return JSONFileResponse (runner .bot (action , id ))
79
85
80
86
81
- @api .get ("/api /getlog" , dependencies = [authorized , cached ])
87
+ @router .get ("/getlog" , dependencies = [authorized , cached ])
82
88
def get_log (lines : int , id : str = Depends (ID ), level : Levels = "DEBUG" ,
83
89
runner : runctl .RunIntelMQCtl = Depends (runner )):
84
90
return JSONFileResponse (runner .log (id , lines , level ))
85
91
86
92
87
- @api .get ("/api /queues" , dependencies = [authorized , cached ])
93
+ @router .get ("/queues" , dependencies = [authorized , cached ])
88
94
def queues (runner : runctl .RunIntelMQCtl = Depends (runner )):
89
95
return JSONFileResponse (runner .list ("queues" ))
90
96
91
97
92
- @api .get ("/api /queues-and-status" , dependencies = [authorized , cached ])
98
+ @router .get ("/queues-and-status" , dependencies = [authorized , cached ])
93
99
def queues_and_status (runner : runctl .RunIntelMQCtl = Depends (runner )):
94
100
return JSONFileResponse (runner .list ("queues-and-status" ))
95
101
96
102
97
- @api .get ("/api /bots" , dependencies = [authorized , cached ])
103
+ @router .get ("/bots" , dependencies = [authorized , cached ])
98
104
def bots (runner : runctl .RunIntelMQCtl = Depends (runner )):
99
105
return JSONFileResponse (runner .list ("bots" ))
100
106
101
107
102
- @api .get ("/api /version" , dependencies = [authorized ], response_model = dict )
108
+ @router .get ("/version" , dependencies = [authorized ], response_model = dict )
103
109
def version (runner : runctl .RunIntelMQCtl = Depends (runner )):
104
110
return runner .version ()
105
111
106
112
107
- @api .get ("/api /check" , dependencies = [authorized ])
113
+ @router .get ("/check" , dependencies = [authorized ])
108
114
def check (runner : runctl .RunIntelMQCtl = Depends (runner )):
109
115
return JSONFileResponse (runner .check ())
110
116
111
117
112
- @api .get ("/api /clear" , dependencies = [authorized ])
118
+ @router .get ("/clear" , dependencies = [authorized ])
113
119
def clear (id : str = Depends (ID ), runner : runctl .RunIntelMQCtl = Depends (runner )):
114
120
return JSONFileResponse (runner .clear (id ))
115
121
116
122
117
- @api .post ("/api /run" , dependencies = [authorized ], response_model = str )
123
+ @router .post ("/run" , dependencies = [authorized ], response_model = str )
118
124
def run (bot : str , cmd : BotCmds , show : bool = False , dry : bool = False , msg : str = Form (default = "" ),
119
125
runner : runctl .RunIntelMQCtl = Depends (runner )):
120
126
return runner .run (bot , cmd , show , dry , msg )
121
127
122
128
123
- @api .get ("/api /debug" , dependencies = [authorized ])
129
+ @router .get ("/debug" , dependencies = [authorized ])
124
130
def debug (runner : runctl .RunIntelMQCtl = Depends (runner )):
125
131
return JSONFileResponse (runner .debug ())
126
132
127
133
128
- @api .get ("/api /config" , dependencies = [authorized ])
134
+ @router .get ("/config" , dependencies = [authorized ])
129
135
def config (file : str , fetch : bool = False ,
130
136
file_access : files .FileAccess = Depends (file_access )):
131
137
result = file_access .load_file_or_directory (file , fetch )
@@ -136,7 +142,7 @@ def config(file: str, fetch: bool = False,
136
142
return Response (contents , headers = {"content-type" : content_type })
137
143
138
144
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 )
140
146
def login (username : str = Form (...), password : str = Form (...),
141
147
session : session .SessionStore = Depends (session_store )):
142
148
if session is None :
@@ -156,7 +162,7 @@ def login(username: str = Form(...), password: str = Form(...),
156
162
detail = "Invalid username and/or password." )
157
163
158
164
159
- @api .get ("/api /harmonization" , dependencies = [authorized ], response_model = dict )
165
+ @router .get ("/harmonization" , dependencies = [authorized ], response_model = dict )
160
166
def get_harmonization (runner : runctl .RunIntelMQCtl = Depends (runner )):
161
167
harmonization = pathlib .Path ('/opt/intelmq/etc/harmonization.conf' )
162
168
paths = runner .get_paths ()
@@ -169,16 +175,13 @@ def get_harmonization(runner: runctl.RunIntelMQCtl = Depends(runner)):
169
175
return {}
170
176
171
177
172
- @api .get ("/api /runtime" , dependencies = [authorized ], response_model = dict )
178
+ @router .get ("/runtime" , dependencies = [authorized ], response_model = dict )
173
179
def get_runtime ():
174
180
return utils .get_runtime ()
175
181
176
182
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 )
182
185
def post_runtime (body : dict ):
183
186
try :
184
187
utils .set_runtime (body )
@@ -188,7 +191,7 @@ def post_runtime(body: dict):
188
191
return str (e )
189
192
190
193
191
- @api .get ("/api /positions" , dependencies = [authorized ], response_model = dict )
194
+ @router .get ("/positions" , dependencies = [authorized ], response_model = dict )
192
195
def get_positions (runner : runctl .RunIntelMQCtl = Depends (runner )):
193
196
positions = pathlib .Path ('/opt/intelmq/etc/manager/positions.conf' )
194
197
paths = runner .get_paths ()
@@ -201,11 +204,8 @@ def get_positions(runner: runctl.RunIntelMQCtl = Depends(runner)):
201
204
return {}
202
205
203
206
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 )
209
209
def post_positions (body : dict , runner : runctl .RunIntelMQCtl = Depends (runner )):
210
210
positions = pathlib .Path ('/opt/intelmq/etc/manager/positions.conf' )
211
211
paths = runner .get_paths ()
0 commit comments