Coverage for fingerprint_server_sdk / models / event_rule_action_block.py: 59%

44 statements  

« 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. 

5 

6The version of the OpenAPI document: 4 

7Contact: support@fingerprint.com 

8Generated by OpenAPI Generator (https://openapi-generator.tech) 

9 

10Do not edit the class manually. 

11""" # noqa: E501 

12 

13from __future__ import annotations 

14 

15import json 

16import pprint 

17import re # noqa: F401 

18from typing import Any, ClassVar, Optional 

19 

20from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr 

21from typing_extensions import Self 

22 

23from fingerprint_server_sdk.models.rule_action_header_field import RuleActionHeaderField 

24from fingerprint_server_sdk.models.rule_action_type import RuleActionType 

25 

26 

27class EventRuleActionBlock(BaseModel): 

28 """ 

29 Informs the client the request should be blocked using the response described by this rule action. 

30 """ 

31 

32 ruleset_id: StrictStr = Field(description='The ID of the evaluated ruleset.') 

33 rule_id: Optional[StrictStr] = Field( 

34 default=None, description='The ID of the rule that matched the identification event.' 

35 ) 

36 rule_expression: Optional[StrictStr] = Field( 

37 default=None, 

38 description='The expression of the rule that matched the identification event.', 

39 ) 

40 type: RuleActionType 

41 status_code: Optional[StrictInt] = Field(default=None, description='A valid HTTP status code.') 

42 headers: Optional[list[RuleActionHeaderField]] = Field( 

43 default=None, description='A list of headers to send.' 

44 ) 

45 body: Optional[StrictStr] = Field( 

46 default=None, description='The response body to send to the client.' 

47 ) 

48 __properties: ClassVar[list[str]] = [ 

49 'ruleset_id', 

50 'rule_id', 

51 'rule_expression', 

52 'type', 

53 'status_code', 

54 'headers', 

55 'body', 

56 ] 

57 

58 model_config = ConfigDict( 

59 populate_by_name=True, 

60 validate_assignment=True, 

61 protected_namespaces=(), 

62 ) 

63 

64 def to_str(self) -> str: 

65 """Returns the string representation of the model using alias""" 

66 return pprint.pformat(self.model_dump(by_alias=True)) 

67 

68 def to_json(self) -> str: 

69 """Returns the JSON representation of the model using alias""" 

70 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead 

71 return json.dumps(self.to_dict()) 

72 

73 @classmethod 

74 def from_json(cls, json_str: str) -> Optional[Self]: 

75 """Create an instance of EventRuleActionBlock from a JSON string""" 

76 return cls.from_dict(json.loads(json_str)) 

77 

78 def to_dict(self) -> dict[str, Any]: 

79 """Return the dictionary representation of the model using alias. 

80 

81 This has the following differences from calling pydantic's 

82 `self.model_dump(by_alias=True)`: 

83 

84 * `None` is only added to the output dict for nullable fields that 

85 were set at model initialization. Other fields with value `None` 

86 are ignored. 

87 """ 

88 excluded_fields: set[str] = set([]) 

89 

90 _dict = self.model_dump( 

91 by_alias=True, 

92 exclude=excluded_fields, 

93 exclude_none=True, 

94 ) 

95 # override the default output from pydantic by calling `to_dict()` of each item in headers (list) 

96 _items = [] 

97 if self.headers: 

98 for _item_headers in self.headers: 

99 if _item_headers: 

100 _items.append(_item_headers.to_dict()) 

101 _dict['headers'] = _items 

102 return _dict 

103 

104 @classmethod 

105 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]: 

106 """Create an instance of EventRuleActionBlock from a dict""" 

107 if obj is None: 

108 return None 

109 

110 if not isinstance(obj, dict): 

111 return cls.model_validate(obj) 

112 

113 _obj = cls.model_validate( 

114 { 

115 'ruleset_id': obj.get('ruleset_id'), 

116 'rule_id': obj.get('rule_id'), 

117 'rule_expression': obj.get('rule_expression'), 

118 'type': obj.get('type'), 

119 'status_code': obj.get('status_code'), 

120 'headers': [RuleActionHeaderField.from_dict(_item) for _item in obj['headers']] 

121 if obj.get('headers') is not None 

122 else None, 

123 'body': obj.get('body'), 

124 } 

125 ) 

126 return _obj