Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclude 'restPath' field from being collected #173

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion collector_module/opmon_collector/collector_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def work(self):
for _ in range(self.settings['collector']['repeat-limit']):
try:
response = self._request_opmon_data()
self.records = self._parse_attachment(response)
records = self._parse_attachment(response)
sanitized_records = self._sanitize_records(records)
self.records = sanitized_records
if self.settings['collector'].get('documents-log-directory', ''):
self._store_records_to_file()
self._store_records_to_database()
Expand Down Expand Up @@ -196,6 +198,19 @@ def _parse_attachment(self, opmon_response):
self.log_exception('Cannot parse response attachment.', str(e))
raise e

@staticmethod
def _sanitize_records(records):
"""
Temporary solution to address a privacy concern - remove 'restPath' field from records.
To be removed after X-Road version 7.6.2 release.
"""
sanitized_records = []
for record in records:
sanitized_record = record.copy()
sanitized_record.pop('restPath', None)
sanitized_records.append(sanitized_record)
return sanitized_records

def _get_records_logger(self) -> logging.Logger:
host_name = re.sub('[^0-9a-zA-Z.-]+', '.', self.server_data['server'])
records_logger = logging.getLogger(host_name)
Expand Down
19 changes: 19 additions & 0 deletions collector_module/opmon_collector/tests/test_collector_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,25 @@ def test_worker_status(mock_server_manager, basic_data):
assert worker.status == CollectorWorker.Status.ALL_COLLECTED


def test_sanitize_records(mock_server_manager, basic_data):
worker = CollectorWorker(basic_data)

records = [
{"id": 1, "foo": "valid_data_foo", "restPath": "some_path/*"},
{"id": 2, "bar": "valid_data_bar", "restPath": "some_path/*"},
{"id": 3, "data3": "valid_data", "restPath": "some_path/*"},
{"restPath": "some_path/*", "id": 4, "data4": "valid_data4"},
{"data5": "valid_data5", "restPath": "some_path/*", "id": 5}
]

sanitized_records = worker._sanitize_records(records)

assert len(sanitized_records) == 5
for record in sanitized_records:
assert 'restPath' not in record
assert 'id' in record


@responses.activate
@pytest.mark.parametrize(
'mock_response_contents', [('metrics_client_proxy_ssl_auth_failed.dat',)], indirect=True
Expand Down
Loading