Coverage for fingerprint_server_sdk / models / event_rule_action.py: 30%
86 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-11 18:41 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-11 18:41 +0000
1"""
2Server API
3Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios.
4Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device.
6The version of the OpenAPI document: 4
7Contact: support@fingerprint.com
8Generated by OpenAPI Generator (https://openapi-generator.tech)
10Do not edit the class manually.
11""" # noqa: E501
13from __future__ import annotations
15import json
16import pprint
17from typing import Any, Optional, Union
19from pydantic import BaseModel, ConfigDict, ValidationError, field_validator
20from typing_extensions import Self
22from fingerprint_server_sdk.models.event_rule_action_allow import EventRuleActionAllow
23from fingerprint_server_sdk.models.event_rule_action_block import EventRuleActionBlock
25EVENTRULEACTION_ONE_OF_SCHEMAS = ['EventRuleActionAllow', 'EventRuleActionBlock']
28class EventRuleAction(BaseModel):
29 """
30 Describes the action the client should take, according to the rule in the ruleset that matched the event. When getting an event by event ID, the rule_action will only be included when the ruleset_id query parameter is specified.
31 """
33 # data type: EventRuleActionAllow
34 oneof_schema_1_validator: Optional[EventRuleActionAllow] = None
35 # data type: EventRuleActionBlock
36 oneof_schema_2_validator: Optional[EventRuleActionBlock] = None
37 actual_instance: Optional[Union[EventRuleActionAllow, EventRuleActionBlock]] = None
38 one_of_schemas: set[str] = {'EventRuleActionAllow', 'EventRuleActionBlock'}
40 model_config = ConfigDict(
41 validate_assignment=True,
42 protected_namespaces=(),
43 )
45 discriminator_value_class_map: dict[str, str] = {}
47 def __init__(self, *args: Any, **kwargs: Any) -> None:
48 if args:
49 if len(args) > 1:
50 raise ValueError(
51 'If a position argument is used, only 1 is allowed to set `actual_instance`'
52 )
53 if kwargs:
54 raise ValueError(
55 'If a position argument is used, keyword arguments cannot be used.'
56 )
57 super().__init__(actual_instance=args[0])
58 else:
59 super().__init__(**kwargs)
61 @field_validator('actual_instance')
62 def actual_instance_must_validate_oneof(cls, v: Any) -> Any:
63 EventRuleAction.model_construct()
64 error_messages = []
65 match = 0
66 # validate data type: EventRuleActionAllow
67 if not isinstance(v, EventRuleActionAllow):
68 error_messages.append(f'Error! Input type `{type(v)}` is not `EventRuleActionAllow`')
69 else:
70 match += 1
71 # validate data type: EventRuleActionBlock
72 if not isinstance(v, EventRuleActionBlock):
73 error_messages.append(f'Error! Input type `{type(v)}` is not `EventRuleActionBlock`')
74 else:
75 match += 1
76 if match > 1:
77 # more than 1 match
78 raise ValueError(
79 'Multiple matches found when setting `actual_instance` in EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
80 + ', '.join(error_messages)
81 )
82 elif match == 0:
83 # no match
84 raise ValueError(
85 'No match found when setting `actual_instance` in EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
86 + ', '.join(error_messages)
87 )
88 else:
89 return v
91 @classmethod
92 def from_dict(cls, obj: Union[str, dict[str, Any]]) -> Self:
93 return cls.from_json(json.dumps(obj))
95 @classmethod
96 def from_json(cls, json_str: str) -> Self:
97 """Returns the object represented by the json string"""
98 instance = cls.model_construct()
99 error_messages = []
100 match = 0
102 # use oneOf discriminator to lookup the data type
103 _data_type = json.loads(json_str).get('type')
104 if not _data_type:
105 raise ValueError('Failed to lookup data type from the field `type` in the input.')
107 # check if data type is `EventRuleActionAllow`
108 if _data_type == 'allow':
109 instance.actual_instance = EventRuleActionAllow.from_json(json_str)
110 return instance
112 # check if data type is `EventRuleActionBlock`
113 if _data_type == 'block':
114 instance.actual_instance = EventRuleActionBlock.from_json(json_str)
115 return instance
117 # deserialize data into EventRuleActionAllow
118 try:
119 instance.actual_instance = EventRuleActionAllow.from_json(json_str)
120 match += 1
121 except (ValidationError, ValueError) as e:
122 error_messages.append(str(e))
123 # deserialize data into EventRuleActionBlock
124 try:
125 instance.actual_instance = EventRuleActionBlock.from_json(json_str)
126 match += 1
127 except (ValidationError, ValueError) as e:
128 error_messages.append(str(e))
130 if match > 1:
131 # more than 1 match
132 raise ValueError(
133 'Multiple matches found when deserializing the JSON string into EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
134 + ', '.join(error_messages)
135 )
136 elif match == 0:
137 # no match
138 raise ValueError(
139 'No match found when deserializing the JSON string into EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
140 + ', '.join(error_messages)
141 )
142 else:
143 return instance
145 def to_json(self) -> str:
146 """Returns the JSON representation of the actual instance"""
147 if self.actual_instance is None:
148 return 'null'
150 if hasattr(self.actual_instance, 'to_json') and callable(self.actual_instance.to_json):
151 return self.actual_instance.to_json()
152 else:
153 return json.dumps(self.actual_instance)
155 def to_dict(
156 self,
157 ) -> Optional[Union[dict[str, Any], EventRuleActionAllow, EventRuleActionBlock]]:
158 """Returns the dict representation of the actual instance"""
159 if self.actual_instance is None:
160 return None
162 if hasattr(self.actual_instance, 'to_dict') and callable(self.actual_instance.to_dict):
163 return self.actual_instance.to_dict()
164 else:
165 # primitive type
166 return self.actual_instance
168 def to_str(self) -> str:
169 """Returns the string representation of the actual instance"""
170 return pprint.pformat(self.model_dump())