Skip to content

Commit 41ef781

Browse files
authored
Merge pull request wazuh#29162 from wazuh/enhancement/28702-remove-cluster-resources
Remove cluster tasks and components
2 parents bc30197 + 96e47ba commit 41ef781

File tree

86 files changed

+246
-20151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+246
-20151
lines changed
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1+
# Copyright (C) 2015, Wazuh Inc.
2+
# Created by Wazuh, Inc. <[email protected]>.
3+
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2
4+
15
from wazuh.core.config.client import Config
26
from wazuh.core.config.models.indexer import IndexerConfig, IndexerNode
3-
from wazuh.core.config.models.server import NodeConfig, NodeType, ServerConfig, SSLConfig
7+
from wazuh.core.config.models.server import ServerConfig
48

59

610
def get_default_configuration():
711
"""Get default configuration for the tests."""
812
return Config(
9-
server=ServerConfig(
10-
nodes=['0'],
11-
node=NodeConfig(
12-
name='node_name',
13-
type=NodeType.MASTER,
14-
ssl=SSLConfig(key='example', cert='example', ca='example'),
15-
),
16-
),
13+
server=ServerConfig(),
1714
indexer=IndexerConfig(hosts=[IndexerNode(host='example', port=1516)], username='wazuh', password='wazuh'),
1815
)

apis/server_management/server_management_api/controllers/manager_controller.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
from server_management_api.constants import INSTALLATION_UID_KEY, UPDATE_INFORMATION_KEY
1414
from server_management_api.controllers.util import json_response
1515
from server_management_api.signals import cti_context
16-
from server_management_api.util import only_master_endpoint, raise_if_exc
16+
from server_management_api.util import raise_if_exc
1717

1818
logger = logging.getLogger('wazuh-api')
1919

2020

21-
@only_master_endpoint
2221
async def check_available_version(pretty: bool = False, force_query: bool = False) -> ConnexionResponse:
2322
"""Get available update information.
2423

apis/server_management/server_management_api/controllers/test/utils.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44

55
from wazuh.core.config.client import Config
66
from wazuh.core.config.models.indexer import IndexerConfig, IndexerNode
7-
from wazuh.core.config.models.server import NodeConfig, NodeType, ServerConfig, SSLConfig
7+
from wazuh.core.config.models.server import ServerConfig
88
from wazuh.core.results import AffectedItemsWazuhResult
99

1010

1111
def get_default_configuration():
1212
"""Get default configuration for the tests."""
1313
return Config(
14-
server=ServerConfig(
15-
nodes=['0'],
16-
node=NodeConfig(
17-
name='node_name',
18-
type=NodeType.MASTER,
19-
ssl=SSLConfig(key='example', cert='example', ca='example'),
20-
),
21-
),
14+
server=ServerConfig(),
2215
indexer=IndexerConfig(hosts=[IndexerNode(host='example', port=1516)], username='wazuh', password='wazuh'),
2316
)
2417

apis/server_management/server_management_api/signals.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from connexion import ConnexionMiddleware
1414
from wazuh.core import common
15-
from wazuh.core.cluster.utils import running_in_master_node
1615
from wazuh.core.commands_manager import CommandsManager
1716
from wazuh.core.config.client import CentralizedConfig
1817
from wazuh.core.configuration import update_check_is_enabled
@@ -101,12 +100,12 @@ async def lifespan_handler(_: ConnexionMiddleware, commands_manager: CommandsMan
101100
t = Thread(target=asyncio.run, args=(get_rbac_info(logger, commands_manager, rbac_manager),))
102101
t.start()
103102

104-
tasks: list[asyncio.Task] = []
103+
tasks: list[asyncio.Task] = [
104+
asyncio.create_task(check_installation_uid()),
105+
]
105106

106-
if running_in_master_node():
107-
tasks.append(asyncio.create_task(check_installation_uid()))
108-
if update_check_is_enabled():
109-
tasks.append(asyncio.create_task(get_update_information()))
107+
if update_check_is_enabled():
108+
tasks.append(asyncio.create_task(get_update_information()))
110109

111110
# Log the initial server startup message.
112111
management_api_config = CentralizedConfig.get_management_api_config()

apis/server_management/server_management_api/test/test_error_handler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ async def test_http_error_handler(detail, mock_request):
166166
('', '', {}, None),
167167
('', 'detail', {'status': 'status'}, None),
168168
('', 'detail', {'type': 'type'}, None),
169-
('', 'detail', {'code': 3005}, None),
170-
('', 'detail', {'code': 3005}, None),
171-
('', 'detail', {'code': 3005}, 'type'),
172-
('', {'detail_1': 'detail_1'}, {'code': 3005}, 'type'),
173-
('', {}, {'code': 3005}, 'type'),
169+
('', 'detail', {'code': 3002}, None),
170+
('', 'detail', {'code': 3002}, None),
171+
('', 'detail', {'code': 3002}, 'type'),
172+
('', {'detail_1': 'detail_1'}, {'code': 3002}, 'type'),
173+
('', {}, {'code': 3002}, 'type'),
174174
('', {}, {'status': 'status'}, 'type'),
175175
('', {}, {'type': 'type'}, 'type'),
176176
('', {}, {'type': 'type', 'more': 'more'}, 'type'),

apis/server_management/server_management_api/test/test_signals.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,19 @@ async def test_get_update_information_schedule(query_update_check_service_mock):
140140

141141

142142
@pytest.mark.parametrize(
143-
'cluster_config,update_check_config,registered_tasks',
143+
'update_check_config,registered_tasks',
144144
[
145-
(True, True, 2),
146-
(True, False, 1),
147-
(False, True, 0),
148-
(False, False, 0),
145+
(True, 2),
146+
(False, 1),
149147
],
150148
)
151149
@patch('server_management_api.signals.check_installation_uid')
152150
@patch('server_management_api.signals.get_update_information')
153151
@patch('server_management_api.signals.update_check_is_enabled')
154-
@patch('server_management_api.signals.running_in_master_node')
155152
async def test_register_background_tasks(
156-
running_in_master_node_mock,
157153
update_check_mock,
158154
get_update_information_mock,
159155
check_installation_uid_mock,
160-
cluster_config,
161156
update_check_config,
162157
registered_tasks,
163158
):
@@ -168,7 +163,6 @@ def __await__(self):
168163
self.await_count += 1
169164
return iter([])
170165

171-
running_in_master_node_mock.return_value = cluster_config
172166
update_check_mock.return_value = update_check_config
173167

174168
with patch('server_management_api.signals.asyncio') as create_task_mock:

apis/server_management/server_management_api/test/test_util.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,24 +257,6 @@ def dummy_func():
257257
assert response.headers == {}, f'Unexpected deprecation headers were found: {response.headers}'
258258

259259

260-
@patch('server_management_api.util.raise_if_exc')
261-
@pytest.mark.asyncio
262-
async def test_only_master_endpoint(mock_exc):
263-
"""Test that only_master_endpoint decorator raise the correct exception when running_in_master_node is False."""
264-
265-
@util.only_master_endpoint
266-
async def func_():
267-
return ret_val
268-
269-
ret_val = 'foo'
270-
271-
with patch('server_management_api.util.running_in_master_node', return_value=False):
272-
await func_()
273-
mock_exc.assert_called_once_with(WazuhResourceNotFound(902))
274-
with patch('server_management_api.util.running_in_master_node', return_value=True):
275-
assert await func_() == ret_val
276-
277-
278260
@patch('yaml.safe_load')
279261
def test_load_api_spec(mock_safe_load):
280262
"""Validate that the function `load_api_spec` works properly."""

apis/server_management/server_management_api/test/test_validator.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import jsonschema as js
1010
import pytest
11-
from wazuh import WazuhError
1211

1312
from server_management_api.validator import (
1413
_active_response_command,
@@ -41,7 +40,6 @@
4140
_wpk_path,
4241
_yes_no_boolean,
4342
allowed_fields,
44-
check_component_configuration_pair,
4543
check_exp,
4644
is_safe_path,
4745
)
@@ -286,18 +284,3 @@ def test_validation_json_ko(value, format):
286284
schema={'type': 'object', 'properties': {'key': {'type': 'string', 'format': format}}},
287285
format_checker=js.Draft4Validator.FORMAT_CHECKER,
288286
)
289-
290-
291-
@pytest.mark.parametrize(
292-
'component, configuration, expected_response', [('agent', 'client', None), ('agent', 'wmodules', WazuhError(1128))]
293-
)
294-
def test_check_component_configuration_pair(component, configuration, expected_response):
295-
"""Verify that `check_component_configuration_pair` function returns an exception when the configuration does
296-
not belong to a Wazuh component.
297-
"""
298-
response = check_component_configuration_pair(component, configuration)
299-
if isinstance(response, Exception):
300-
assert isinstance(response, expected_response.__class__)
301-
assert response.code == expected_response.code
302-
else:
303-
assert response is expected_response

apis/server_management/server_management_api/util.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import yaml
1414
from connexion import ProblemException
1515
from wazuh.core import common, exception
16-
from wazuh.core.cluster.utils import running_in_master_node
1716

1817
from server_management_api import __path__ as api_path
1918

@@ -351,12 +350,7 @@ def _create_problem(exc: Exception, code: int = None):
351350
"""
352351
ext = None
353352
if isinstance(exc, exception.WazuhException):
354-
ext = remove_nones_to_dict(
355-
{
356-
'remediation': exc.remediation,
357-
'code': exc.code
358-
}
359-
)
353+
ext = remove_nones_to_dict({'remediation': exc.remediation, 'code': exc.code})
360354

361355
if isinstance(exc, exception.WazuhInternalError):
362356
raise ProblemException(
@@ -452,19 +446,6 @@ async def wrapper(*args, **kwargs):
452446
return add_deprecation_headers
453447

454448

455-
def only_master_endpoint(func):
456-
"""Restrict endpoints to the master node."""
457-
458-
@wraps(func)
459-
async def wrapper(*args, **kwargs):
460-
if not running_in_master_node():
461-
raise_if_exc(exception.WazuhResourceNotFound(902))
462-
else:
463-
return await func(*args, **kwargs)
464-
465-
return wrapper
466-
467-
468449
@lru_cache(maxsize=None)
469450
def load_api_spec():
470451
"""Load API specification."""

apis/server_management/server_management_api/validator.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
import os
66
import re
7-
from types import MappingProxyType
87
from typing import Dict, List
98

109
from jsonschema import Draft4Validator
1110
from uuid6 import UUID
1211
from wazuh.core import common
13-
from wazuh.core.exception import WazuhError
1412

1513
_alphanumeric_param = re.compile(r'^[\w,\-.+\s:]+$')
1614
_symbols_alphanumeric_param = re.compile(r'^[\w,*<>!\-.+\s:/()\[\]\'\"|=~#]+$')
@@ -60,25 +58,6 @@
6058
},
6159
}
6260

63-
WAZUH_COMPONENT_CONFIGURATION_MAPPING = MappingProxyType(
64-
{
65-
'agent': {'client', 'buffer', 'labels', 'internal'},
66-
'agentless': {'agentless'},
67-
'analysis': {'global', 'active_response', 'alerts', 'command', 'rules', 'decoders', 'internal', 'rule_test'},
68-
'auth': {'auth'},
69-
'com': {'active-response', 'logging', 'internal', 'cluster'},
70-
'csyslog': {'csyslog'},
71-
'integrator': {'integration'},
72-
'logcollector': {'localfile', 'socket', 'internal'},
73-
'mail': {'global', 'alerts', 'internal'},
74-
'monitor': {'global', 'internal', 'reports'},
75-
'request': {'global', 'remote', 'internal'},
76-
'syscheck': {'syscheck', 'rootcheck', 'internal'},
77-
'wazuh-db': {'wdb', 'internal'},
78-
'wmodules': {'wmodules'},
79-
}
80-
)
81-
8261

8362
def check_exp(exp: str, regex: re.Pattern) -> bool:
8463
"""Function to check if an expression matches a regex.
@@ -145,28 +124,6 @@ def is_safe_path(path: str, basedir: str = common.WAZUH_ETC, relative: bool = Tr
145124
return os.path.commonpath([full_path, full_basedir]) == full_basedir
146125

147126

148-
def check_component_configuration_pair(component: str, configuration: str) -> WazuhError:
149-
"""Parameters
150-
----------
151-
component : str
152-
Wazuh component name.
153-
configuration : str
154-
Component configuration.
155-
156-
Returns
157-
-------
158-
WazuhError
159-
It can either return a `WazuhError` or `None`, depending on the given component and configuration. The exception
160-
is returned and not raised because we use the object to create a problem on API level.
161-
"""
162-
if configuration not in WAZUH_COMPONENT_CONFIGURATION_MAPPING[component]:
163-
return WazuhError(
164-
1128,
165-
extra_message=f"Valid configuration values for '{component}': "
166-
f'{WAZUH_COMPONENT_CONFIGURATION_MAPPING[component]}',
167-
)
168-
169-
170127
@Draft4Validator.FORMAT_CHECKER.checks('alphanumeric')
171128
def format_alphanumeric(value):
172129
return check_exp(value, _alphanumeric_param)

0 commit comments

Comments
 (0)