Skip to content

Commit

Permalink
Merge pull request #174 from nordic-institute/develop
Browse files Browse the repository at this point in the history
chore: merge develop into master
  • Loading branch information
nortaljevgenikr authored Feb 26, 2025
2 parents 6f8402c + 2048e2f commit f9c8d51
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit f9c8d51

Please sign in to comment.