Coverage for fingerprint_server_sdk/models/event_rule_action_block.py: 59%
44 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
18import re # noqa: F401
19from typing import Any, ClassVar, Optional
21from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
22from typing_extensions import Self
24from fingerprint_server_sdk.models.rule_action_header_field import RuleActionHeaderField
25from fingerprint_server_sdk.models.rule_action_type import RuleActionType
28class EventRuleActionBlock(BaseModel):
29 """
30 Informs the client the request should be blocked using the response described by this rule action.
31 """
33 ruleset_id: StrictStr = Field(description='The ID of the evaluated ruleset.')
34 rule_id: Optional[StrictStr] = Field(
35 default=None, description='The ID of the rule that matched the identification event.'
36 )
37 rule_expression: Optional[StrictStr] = Field(
38 default=None,
39 description='The expression of the rule that matched the identification event.',
40 )
41 type: RuleActionType
42 status_code: Optional[StrictInt] = Field(default=None, description='A valid HTTP status code.')
43 headers: Optional[list[RuleActionHeaderField]] = Field(
44 default=None, description='A list of headers to send.'
45 )
46 body: Optional[StrictStr] = Field(
47 default=None, description='The response body to send to the client.'
48 )
49 __properties: ClassVar[list[str]] = [
50 'ruleset_id',
51 'rule_id',
52 'rule_expression',
53 'type',
54 'status_code',
55 'headers',
56 'body',
57 ]
59 model_config = ConfigDict(
60 populate_by_name=True,
61 validate_assignment=True,
62 protected_namespaces=(),
63 )
65 def to_str(self) -> str:
66 """Returns the string representation of the model using alias"""
67 return pprint.pformat(self.model_dump(by_alias=True))
69 def to_json(self) -> str:
70 """Returns the JSON representation of the model using alias"""
71 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
72 return json.dumps(self.to_dict())
74 @classmethod
75 def from_json(cls, json_str: str) -> Optional[Self]:
76 """Create an instance of EventRuleActionBlock from a JSON string"""
77 return cls.from_dict(json.loads(json_str))
79 def to_dict(self) -> dict[str, Any]:
80 """Return the dictionary representation of the model using alias.
82 This has the following differences from calling pydantic's
83 `self.model_dump(by_alias=True)`:
85 * `None` is only added to the output dict for nullable fields that
86 were set at model initialization. Other fields with value `None`
87 are ignored.
88 """
89 excluded_fields: set[str] = set([])
91 _dict = self.model_dump(
92 by_alias=True,
93 exclude=excluded_fields,
94 exclude_none=True,
95 )
96 # override the default output from pydantic by calling `to_dict()` of each item in headers (list)
97 _items = []
98 if self.headers:
99 for _item_headers in self.headers:
100 if _item_headers:
101 _items.append(_item_headers.to_dict())
102 _dict['headers'] = _items
103 return _dict
105 @classmethod
106 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]:
107 """Create an instance of EventRuleActionBlock from a dict"""
108 if obj is None:
109 return None
111 if not isinstance(obj, dict):
112 return cls.model_validate(obj)
114 _obj = cls.model_validate(
115 {
116 'ruleset_id': obj.get('ruleset_id'),
117 'rule_id': obj.get('rule_id'),
118 'rule_expression': obj.get('rule_expression'),
119 'type': obj.get('type'),
120 'status_code': obj.get('status_code'),
121 'headers': [RuleActionHeaderField.from_dict(_item) for _item in obj['headers']]
122 if obj.get('headers') is not None
123 else None,
124 'body': obj.get('body'),
125 }
126 )
127 return _obj