Skip to content

Commit 17fe30b

Browse files
committed
Changes positions.conf file path to /var/lib/intelmq/server/positions.json.
1 parent d97eafe commit 17fe30b

File tree

9 files changed

+98
-27
lines changed

9 files changed

+98
-27
lines changed

.reuse/dep5

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ License: AGPL-3.0-or-later
8686

8787
Files: intelmq/etc/intelmq.yaml
8888
Copyright: 2023 Filip Pokorný
89-
License: AGPL-3.0-or-later
89+
License: AGPL-3.0-or-later
90+
91+
Files: intelmq/etc/positions.json
92+
Copyright: 2020 Birger Schacht, 2023 Filip Pokorný
93+
License: CC0-1.0

debian/conffiles

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/etc/intelmq/harmonization.conf
22
/etc/intelmq/runtime.yaml
33
/etc/intelmq/intelmq.yaml
4+
/var/lib/intelmq/server/positions.json

debian/intelmq.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ intelmq/bots/experts/modify/examples/* usr/share/doc/intelmq/bots/experts/modify
77
intelmq/etc/runtime.yaml etc/intelmq/
88
intelmq/etc/harmonization.conf etc/intelmq/
99
intelmq/etc/intelmq.yaml etc/intelmq/
10+
intelmq/etc/positions.json var/lib/intelmq/server/

intelmq/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
HARMONIZATION_CONF_FILE = os.path.join(CONFIG_DIR, "harmonization.conf")
3636
RUNTIME_CONF_FILE = os.path.join(CONFIG_DIR, "runtime.yaml")
3737
INTELMQ_CONF_FILE = os.path.join(CONFIG_DIR, "intelmq.yaml")
38+
POSITIONS_FILE = os.path.join(VAR_SERVER_PATH, "positions.json")
3839
old_runtime_conf_file = pathlib.Path(RUNTIME_CONF_FILE).with_suffix('.conf')
3940
if not pathlib.Path(RUNTIME_CONF_FILE).exists() and old_runtime_conf_file.exists():
4041
old_runtime_conf_file.rename(RUNTIME_CONF_FILE)

intelmq/app/api/router.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import intelmq.app.api.runctl as runctl
2727
import intelmq.app.api.session as session
2828

29+
from intelmq import RUNTIME_CONF_FILE, POSITIONS_FILE, HARMONIZATION_CONF_FILE
2930
from intelmq.app.dependencies import (app_config, cached_response, session_store,
3031
token_authorization)
3132
from .models import TokenResponse
@@ -193,10 +194,8 @@ def post_runtime(body: dict):
193194

194195
@router.get("/positions", dependencies=[authorized], response_model=dict)
195196
def get_positions(runner: runctl.RunIntelMQCtl = Depends(runner)):
196-
positions = pathlib.Path('/opt/intelmq/etc/manager/positions.conf')
197197
paths = runner.get_paths()
198-
if 'CONFIG_DIR' in paths:
199-
positions = pathlib.Path(paths['CONFIG_DIR']) / 'manager/positions.conf'
198+
positions = pathlib.Path(paths.get("POSITIONS_FILE", POSITIONS_FILE))
200199
try:
201200
return json.loads(positions.read_text())
202201
except OSError as e:
@@ -207,10 +206,8 @@ def get_positions(runner: runctl.RunIntelMQCtl = Depends(runner)):
207206
@router.post("/positions", dependencies=[authorized], response_model=str,
208207
response_class=PlainTextResponse)
209208
def post_positions(body: dict, runner: runctl.RunIntelMQCtl = Depends(runner)):
210-
positions = pathlib.Path('/opt/intelmq/etc/manager/positions.conf')
211209
paths = runner.get_paths()
212-
if 'CONFIG_DIR' in paths:
213-
positions = pathlib.Path(paths['CONFIG_DIR']) / 'manager/positions.conf'
210+
positions = pathlib.Path(paths.get("POSITIONS_FILE", POSITIONS_FILE))
214211
try:
215212
positions.parent.mkdir(exist_ok=True)
216213
positions.write_text(json.dumps(body, indent=4))

intelmq/bin/intelmqctl.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
HARMONIZATION_CONF_FILE,
2525
RUNTIME_CONF_FILE, VAR_RUN_PATH, STATE_FILE_PATH,
2626
DEFAULT_LOGGING_PATH, __version_info__,
27-
CONFIG_DIR, ROOT_DIR)
27+
CONFIG_DIR, ROOT_DIR, POSITIONS_FILE, VAR_SERVER_PATH, INTELMQ_CONF_FILE)
2828
from intelmq.lib import utils
2929
from intelmq.lib.datatypes import ReturnType, MESSAGES, LogLevel
3030
from intelmq.lib.processmanager import *
@@ -1257,9 +1257,16 @@ def debug(self, sections=None):
12571257
if self._returntype is ReturnType.TEXT:
12581258
print('Paths:')
12591259
for path in ('HARMONIZATION_CONF_FILE',
1260-
'RUNTIME_CONF_FILE', 'VAR_RUN_PATH', 'STATE_FILE_PATH',
1261-
'DEFAULT_LOGGING_PATH', '__file__',
1262-
'CONFIG_DIR', 'ROOT_DIR'):
1260+
'RUNTIME_CONF_FILE',
1261+
'INTELMQ_CONF_FILE',
1262+
'POSITIONS_FILE',
1263+
'VAR_RUN_PATH',
1264+
'STATE_FILE_PATH',
1265+
'DEFAULT_LOGGING_PATH',
1266+
'__file__',
1267+
'CONFIG_DIR',
1268+
'ROOT_DIR',
1269+
'VAR_SERVER_PATH'):
12631270
output['paths'][path] = variables[path]
12641271
if self._returntype is ReturnType.TEXT:
12651272
print(f'{path}: {variables[path]!r}')

intelmq/bin/intelmqsetup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ def intelmqsetup_core(ownership=True, state_file=STATE_FILE_PATH):
9494

9595
example_path = Path(pkg_resources.resource_filename('intelmq', 'etc'))
9696
example_confs = [
97-
example_path / 'runtime.yaml',
98-
example_path / 'harmonization.conf',
99-
example_path / 'intelmq.yaml',
97+
(example_path / 'runtime.yaml', Path(CONFIG_DIR) / 'runtime.yaml'),
98+
(example_path / 'harmonization.conf', Path(CONFIG_DIR) / 'harmonization.conf'),
99+
(example_path / 'intelmq.yaml', Path(CONFIG_DIR) / 'intelmq.yaml'),
100+
(example_path / 'positions.json', Path(VAR_SERVER_PATH) / 'positions.json'),
100101
]
101-
for example_conf in example_confs:
102+
for example_conf, destination_file in example_confs:
102103
fname = Path(example_conf).name
103-
destination_file = Path(CONFIG_DIR) / fname
104104
if destination_file.exists():
105105
print(f'Not overwriting existing {fname!r} with example.')
106106
log_ownership_change = True
107107
else:
108-
shutil.copy(example_conf, CONFIG_DIR)
109-
print(f'Installing example {fname!r} to {CONFIG_DIR}.')
108+
shutil.copy(example_conf, destination_file.parent)
109+
print(f'Installing example {fname!r} to {destination_file.parent}.')
110110
log_ownership_change = False # For installing the new files, we don't need to inform the admin that the permissions have been "fixed"
111111
if ownership:
112112
change_owner(destination_file, owner='intelmq', group='intelmq', log=log_ownership_change)

intelmq/etc/positions.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"feodo-tracker-browse-parser": {
3+
"x": -304,
4+
"y": 250
5+
},
6+
"feodo-tracker-browse-collector": {
7+
"x": -508,
8+
"y": 282
9+
},
10+
"cymru-whois-expert": {
11+
"x": 510,
12+
"y": -407
13+
},
14+
"deduplicator-expert": {
15+
"x": -107,
16+
"y": 162
17+
},
18+
"file-output": {
19+
"x": 504,
20+
"y": -614
21+
},
22+
"gethostbyname-1-expert": {
23+
"x": 481,
24+
"y": -198
25+
},
26+
"gethostbyname-2-expert": {
27+
"x": 322,
28+
"y": -325
29+
},
30+
"malc0de-parser": {
31+
"x": -292,
32+
"y": 48
33+
},
34+
"malc0de-windows-format-collector": {
35+
"x": -477,
36+
"y": -46
37+
},
38+
"spamhaus-drop-collector": {
39+
"x": -88,
40+
"y": 589
41+
},
42+
"spamhaus-drop-parser": {
43+
"x": -114,
44+
"y": 381
45+
},
46+
"taxonomy-expert": {
47+
"x": 89,
48+
"y": 29
49+
},
50+
"url2fqdn-expert": {
51+
"x": 275,
52+
"y": -116
53+
},
54+
"settings": {
55+
"physics": false,
56+
"live": true
57+
}
58+
}

intelmq/tests/app/api/test_api.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from unittest.mock import patch, MagicMock
1515
from fastapi.testclient import TestClient
1616

17-
1817
with patch("intelmq.lib.utils.get_intelmq_settings", MagicMock(return_value={})):
1918

2019
from intelmq.app import dependencies
@@ -97,7 +96,11 @@ def setUp(self) -> None:
9796
dependencies.startup(DummyConfig())
9897
self.conf_dir = TemporaryDirectory()
9998
app.dependency_overrides[runner] = get_dummy_reader(
100-
paths={"CONFIG_DIR": self.conf_dir.name})
99+
paths={
100+
"CONFIG_DIR": self.conf_dir.name,
101+
"POSITIONS_FILE": os.path.join(self.conf_dir.name, "positions.json")
102+
}
103+
)
101104

102105
self.save_runtime()
103106
self.save_positions()
@@ -110,9 +113,12 @@ def save_runtime(self):
110113
with open(f"{self.conf_dir.name}/runtime.yaml", "w+") as f:
111114
json.dump({}, f)
112115

116+
def load_positions(self):
117+
with open(f"{self.conf_dir.name}/positions.json") as f:
118+
return json.load(f)
119+
113120
def save_positions(self):
114-
os.makedirs(f"{self.conf_dir.name}/manager", exist_ok=True)
115-
with open(f"{self.conf_dir.name}/manager/positions.conf", "w+") as f:
121+
with open(f"{self.conf_dir.name}/positions.json", "w+") as f:
116122
json.dump({}, f)
117123

118124
def tearDown(self) -> None:
@@ -141,7 +147,6 @@ def test_post_runtime(self):
141147

142148
self.assertEqual(response.status_code, 200)
143149
self.assertEqual(response.text, "success")
144-
145150
self.assertEqual(utils.get_runtime(), data)
146151

147152
def test_post_positions(self):
@@ -155,10 +160,7 @@ def test_post_positions(self):
155160

156161
self.assertEqual(response.status_code, 200)
157162
self.assertEqual(response.text, "success")
158-
159-
with open(f"{self.conf_dir.name}/manager/positions.conf", "r") as f:
160-
saved = json.load(f)
161-
self.assertEqual(saved, data)
163+
self.assertEqual(self.load_positions(), data)
162164

163165

164166
class TestAPILogin(TestCase):

0 commit comments

Comments
 (0)