Coverage for fingerprint_server_sdk/models/event_rule_action.py: 30%
86 statements
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-14 10:45 +0000
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-14 10:45 +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.
5The API also supports collection of Automation Intelligence for requests to your server in edge, pre-origin, or middleware contexts.
7The version of the OpenAPI document: 4
8Contact: support@fingerprint.com
9Generated by OpenAPI Generator (https://openapi-generator.tech)
11Do not edit the class manually.
12""" # noqa: E501
14from __future__ import annotations
16import json
17import pprint
18from typing import Any, Optional, Union
20from pydantic import BaseModel, ConfigDict, ValidationError, field_validator
21from typing_extensions import Self
23from fingerprint_server_sdk.models.event_rule_action_allow import EventRuleActionAllow
24from fingerprint_server_sdk.models.event_rule_action_block import EventRuleActionBlock
26EVENTRULEACTION_ONE_OF_SCHEMAS = ['EventRuleActionAllow', 'EventRuleActionBlock']
29class EventRuleAction(BaseModel):
30 """
31 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.
32 """
34 # data type: EventRuleActionAllow
35 oneof_schema_1_validator: Optional[EventRuleActionAllow] = None
36 # data type: EventRuleActionBlock
37 oneof_schema_2_validator: Optional[EventRuleActionBlock] = None
38 actual_instance: Optional[Union[EventRuleActionAllow, EventRuleActionBlock]] = None
39 one_of_schemas: set[str] = {'EventRuleActionAllow', 'EventRuleActionBlock'}
41 model_config = ConfigDict(
42 validate_assignment=True,
43 protected_namespaces=(),
44 )
46 discriminator_value_class_map: dict[str, str] = {}
48 def __init__(self, *args: Any, **kwargs: Any) -> None:
49 if args:
50 if len(args) > 1:
51 raise ValueError(
52 'If a position argument is used, only 1 is allowed to set `actual_instance`'
53 )
54 if kwargs:
55 raise ValueError(
56 'If a position argument is used, keyword arguments cannot be used.'
57 )
58 super().__init__(actual_instance=args[0])
59 else:
60 super().__init__(**kwargs)
62 @field_validator('actual_instance')
63 def actual_instance_must_validate_oneof(cls, v: Any) -> Any:
64 EventRuleAction.model_construct()
65 error_messages = []
66 match = 0
67 # validate data type: EventRuleActionAllow
68 if not isinstance(v, EventRuleActionAllow):
69 error_messages.append(f'Error! Input type `{type(v)}` is not `EventRuleActionAllow`')
70 else:
71 match += 1
72 # validate data type: EventRuleActionBlock
73 if not isinstance(v, EventRuleActionBlock):
74 error_messages.append(f'Error! Input type `{type(v)}` is not `EventRuleActionBlock`')
75 else:
76 match += 1
77 if match > 1:
78 # more than 1 match
79 raise ValueError(
80 'Multiple matches found when setting `actual_instance` in EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
81 + ', '.join(error_messages)
82 )
83 elif match == 0:
84 # no match
85 raise ValueError(
86 'No match found when setting `actual_instance` in EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
87 + ', '.join(error_messages)
88 )
89 else:
90 return v
92 @classmethod
93 def from_dict(cls, obj: Union[str, dict[str, Any]]) -> Self:
94 return cls.from_json(json.dumps(obj))
96 @classmethod
97 def from_json(cls, json_str: str) -> Self:
98 """Returns the object represented by the json string"""
99 instance = cls.model_construct()
100 error_messages = []
101 match = 0
103 # use oneOf discriminator to lookup the data type
104 _data_type = json.loads(json_str).get('type')
105 if not _data_type:
106 raise ValueError('Failed to lookup data type from the field `type` in the input.')
108 # check if data type is `EventRuleActionAllow`
109 if _data_type == 'allow':
110 instance.actual_instance = EventRuleActionAllow.from_json(json_str)
111 return instance
113 # check if data type is `EventRuleActionBlock`
114 if _data_type == 'block':
115 instance.actual_instance = EventRuleActionBlock.from_json(json_str)
116 return instance
118 # deserialize data into EventRuleActionAllow
119 try:
120 instance.actual_instance = EventRuleActionAllow.from_json(json_str)
121 match += 1
122 except (ValidationError, ValueError) as e:
123 error_messages.append(str(e))
124 # deserialize data into EventRuleActionBlock
125 try:
126 instance.actual_instance = EventRuleActionBlock.from_json(json_str)
127 match += 1
128 except (ValidationError, ValueError) as e:
129 error_messages.append(str(e))
131 if match > 1:
132 # more than 1 match
133 raise ValueError(
134 'Multiple matches found when deserializing the JSON string into EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
135 + ', '.join(error_messages)
136 )
137 elif match == 0:
138 # no match
139 raise ValueError(
140 'No match found when deserializing the JSON string into EventRuleAction with oneOf schemas: EventRuleActionAllow, EventRuleActionBlock. Details: '
141 + ', '.join(error_messages)
142 )
143 else:
144 return instance
146 def to_json(self) -> str:
147 """Returns the JSON representation of the actual instance"""
148 if self.actual_instance is None:
149 return 'null'
151 if hasattr(self.actual_instance, 'to_json') and callable(self.actual_instance.to_json):
152 return self.actual_instance.to_json()
153 else:
154 return json.dumps(self.actual_instance)
156 def to_dict(
157 self,
158 ) -> Optional[Union[dict[str, Any], EventRuleActionAllow, EventRuleActionBlock]]:
159 """Returns the dict representation of the actual instance"""
160 if self.actual_instance is None:
161 return None
163 if hasattr(self.actual_instance, 'to_dict') and callable(self.actual_instance.to_dict):
164 return self.actual_instance.to_dict()
165 else:
166 # primitive type
167 return self.actual_instance
169 def to_str(self) -> str:
170 """Returns the string representation of the actual instance"""
171 return pprint.pformat(self.model_dump())