Skip to content

Commit

Permalink
feature/form-filling-scenario-params-masking:
Browse files Browse the repository at this point in the history
- add masking for logging data_extracted_str
  • Loading branch information
Mikhail-Gl96 committed Oct 26, 2023
1 parent 96da6b4 commit e14aeaf
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions scenarios/scenario_descriptions/form_filling_scenario.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# coding: utf-8
from copy import deepcopy
from functools import lru_cache
from typing import Dict, Any, Tuple, List

import scenarios.logging.logger_constants as log_const
from core.basic_models.actions.command import Command
from core.basic_models.scenarios.base_scenario import BaseScenario
from core.monitoring.monitoring import monitoring
from core.logging.logger_utils import log

import scenarios.logging.logger_constants as log_const
from core.monitoring.monitoring import monitoring
from core.utils.masking_message import masking
from scenarios.actions.action_params_names import REQUEST_FIELD
from scenarios.scenario_models.field.field import QuestionField
from scenarios.scenario_models.history import Event, HistoryConstants
from scenarios.actions.action_params_names import REQUEST_FIELD

FORM_FIELD_DELIMETER = "__"

Expand Down Expand Up @@ -174,14 +176,25 @@ async def get_reply(self, user, text_preprocessing_result, reply_actions, field,
user.last_scenarios.delete(self.id)
return action_messages

@staticmethod
@lru_cache
def _get_common_masking_fields(user) -> list:
"""Get global masking fields from user settings from file with name template_settings."""
return user.settings['template_settings'].get('masking_fields', []) if user is not None else []

def _get_masked_params(self, data: dict, user) -> dict:
"""Masking data by global masking fields."""
masking_fields = self._get_common_masking_fields(user)
return masking(data=deepcopy(data), masking_fields=masking_fields)

@monitoring.got_histogram("scenario_time")
async def run(self, text_preprocessing_result, user, params: Dict[str, Any] = None) -> List[Command]:
form = self._get_form(user)
user.last_scenarios.add(self.id, text_preprocessing_result)
user.preprocessing_messages_for_scenarios.add(text_preprocessing_result)

data_extracted = self._extract_data(form, text_preprocessing_result, user, params)
logging_params = {"data_extracted_str": str(data_extracted)}
logging_params = {"data_extracted_str": str(self._get_masked_params(data_extracted, user))}
logging_params.update(self._log_params())
log("Extracted data=%(data_extracted_str)s", user, logging_params)

Expand Down

0 comments on commit e14aeaf

Please sign in to comment.