1010from cmk .rulesets .v1 .form_specs import FormSpec
1111from cmk .shared_typing import vue_formspec_components as shared_type_defs
1212
13- from ._type_defs import DiskModel , IncomingData , InvalidValue , RawDiskData
13+ from ._type_defs import DiskModel , IncomingData , InvalidValue , RawDiskData , VisitorOptions
1414from ._utils import (
1515 compute_validation_errors ,
1616 compute_validators ,
2525
2626class FormSpecVisitor (abc .ABC , Generic [FormSpecModel , _ParsedValueModel , _FallbackDataModel ]):
2727 @final
28- def __init__ (self , form_spec : FormSpecModel ) -> None :
28+ def __init__ (self , form_spec : FormSpecModel , visitor_options : VisitorOptions ) -> None :
2929 self .form_spec = form_spec
30+ self .visitor_options = visitor_options
3031
3132 @final
3233 def to_vue (self , raw_value : IncomingData ) -> tuple [shared_type_defs .FormSpec , object ]:
33- parsed_value = self ._parse_value (self ._migrate_disk_value (raw_value ))
34+ parsed_value = self ._parse_value (
35+ self ._migrate_disk_value (raw_value )
36+ if self .visitor_options .migrate_values
37+ else raw_value
38+ )
3439 return self ._to_vue (parsed_value )
3540
3641 @final
3742 def validate (self , raw_value : IncomingData ) -> list [shared_type_defs .ValidationMessage ]:
38- parsed_value = self ._parse_value (self ._migrate_disk_value (raw_value ))
43+ parsed_value = self ._parse_value (
44+ self ._migrate_disk_value (raw_value )
45+ if self .visitor_options .migrate_values
46+ else raw_value
47+ )
3948 # Stage 1: Check if the value is invalid
4049 if isinstance (parsed_value , InvalidValue ):
4150 return create_validation_error (self ._to_vue (parsed_value )[1 ], parsed_value .reason )
@@ -55,22 +64,17 @@ def validate(self, raw_value: IncomingData) -> list[shared_type_defs.ValidationM
5564
5665 @final
5766 def to_disk (self , raw_value : IncomingData ) -> DiskModel :
58- parsed_value = self ._parse_value (self ._migrate_disk_value (raw_value ))
67+ parsed_value = self ._parse_value (
68+ self ._migrate_disk_value (raw_value )
69+ if self .visitor_options .migrate_values
70+ else raw_value
71+ )
5972 if isinstance (parsed_value , InvalidValue ):
6073 raise MKGeneralException (
6174 "Unable to serialize invalid value. Reason: %s" % parsed_value .reason
6275 )
6376 return self ._to_disk (parsed_value )
6477
65- @final
66- def mask (self , raw_value : IncomingData ) -> DiskModel :
67- parsed_value = self ._parse_value (self ._migrate_disk_value (raw_value ))
68- if isinstance (parsed_value , InvalidValue ):
69- raise MKGeneralException (
70- "Unable to serialize invalid value. Reason: %s" % parsed_value .reason
71- )
72- return self ._mask (parsed_value )
73-
7478 def _migrate_disk_value (self , value : IncomingData ) -> IncomingData :
7579 if isinstance (value , RawDiskData ) and self .form_spec .migrate :
7680 return RawDiskData (value = self .form_spec .migrate (value .value ))
@@ -103,11 +107,3 @@ def _validate(
103107 @abc .abstractmethod
104108 def _to_disk (self , parsed_value : _ParsedValueModel ) -> DiskModel :
105109 """Transforms the value into a serializable format for disk storage."""
106-
107- def _mask (self , parsed_value : _ParsedValueModel ) -> DiskModel :
108- """Obscure any sensitive information in the provided value
109-
110- Container-like ValueSpecs must recurse over their items, allow these to mask their
111- values. Other ValueSpecs that don't have a need for masking sensitive information
112- can simply return the input value."""
113- return self ._to_disk (parsed_value )
0 commit comments