Coverage for src/hush_hush/_generated/models/audit_log_entry.py: 61%

79 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-10-16 16:01 +0000

1# Code generated by openapi-python-client from hush-hush/api/openapi.yaml; DO NOT EDIT. 

2 

3from __future__ import annotations 

4 

5import datetime 

6from collections.abc import Mapping 

7from typing import Any, TypeVar 

8from uuid import UUID 

9 

10from attrs import define as _attrs_define 

11from attrs import field as _attrs_field 

12 

13from ..models.audit_log_entry_action import AuditLogEntryAction 

14from ..models.audit_log_entry_actor_type import AuditLogEntryActorType 

15from ..types import UNSET, Unset 

16 

17T = TypeVar("T", bound="AuditLogEntry") 

18 

19 

20@_attrs_define 

21class AuditLogEntry: 

22 """ 

23 Attributes: 

24 id (int): This entry's own id - stable and strictly increasing, so it 

25 doubles as the cursor for the `after` query parameter. 

26 object_id (str): A caller-chosen, unique identifier for an object - what every 

27 documented request path (URL, CLI, API) addresses it by. Letters of 

28 either case, digits, `_` and `-`, starting with a letter or digit; 

29 names are case-sensitive, so `Api_Token` and `api_token` are two 

30 secrets. Create and rename follow the same rule. The 

31 object's internal id is a separate, opaque value never exposed to 

32 or accepted from a caller (specs/secret-objects/spec.md's 

33 "Internal id decoupled from user-facing slug" requirement). 

34 action (AuditLogEntryAction): 

35 timestamp (datetime.datetime): 

36 ip (str): The request's source IP. Unlike caller, this is never 

37 self-reported - it's the one piece of the request nobody gets 

38 to lie about via a header. Currently the immediate TCP peer's 

39 address; this service isn't deployed behind a reverse proxy or 

40 load balancer, so X-Forwarded-For (or similar) support isn't 

41 implemented yet. 

42 variant_id (UUID | Unset): The UUID of the object the entry is about. `object_id` is only its name, which 

43 several variants can share. Left out of an entry written before this was recorded. 

44 caller (str | Unset): The caller's presented identity, if any. 

45 actor_type (AuditLogEntryActorType | Unset): The kind of verified credential that authenticated this call - 

46 absent for an unauthenticated read. Unlike caller, this is 

47 never self-reported. 

48 actor_id (str | Unset): The specific token id or admin account this call was 

49 authenticated as - absent for an unauthenticated read. 

50 """ 

51 

52 id: int 

53 object_id: str 

54 action: AuditLogEntryAction 

55 timestamp: datetime.datetime 

56 ip: str 

57 variant_id: UUID | Unset = UNSET 

58 caller: str | Unset = UNSET 

59 actor_type: AuditLogEntryActorType | Unset = UNSET 

60 actor_id: str | Unset = UNSET 

61 additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) 

62 

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

64 id = self.id 

65 

66 object_id = self.object_id 

67 

68 action = self.action.value 

69 

70 timestamp = self.timestamp.isoformat() 

71 

72 ip = self.ip 

73 

74 variant_id: str | Unset = UNSET 

75 if not isinstance(self.variant_id, Unset): 

76 variant_id = str(self.variant_id) 

77 

78 caller = self.caller 

79 

80 actor_type: str | Unset = UNSET 

81 if not isinstance(self.actor_type, Unset): 

82 actor_type = self.actor_type.value 

83 

84 actor_id = self.actor_id 

85 

86 field_dict: dict[str, Any] = {} 

87 field_dict.update(self.additional_properties) 

88 field_dict.update( 

89 { 

90 "id": id, 

91 "object_id": object_id, 

92 "action": action, 

93 "timestamp": timestamp, 

94 "ip": ip, 

95 } 

96 ) 

97 if variant_id is not UNSET: 

98 field_dict["variant_id"] = variant_id 

99 if caller is not UNSET: 

100 field_dict["caller"] = caller 

101 if actor_type is not UNSET: 

102 field_dict["actor_type"] = actor_type 

103 if actor_id is not UNSET: 

104 field_dict["actor_id"] = actor_id 

105 

106 return field_dict 

107 

108 @classmethod 

109 def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: 

110 d = dict(src_dict) 

111 id = d.pop("id") 

112 

113 object_id = d.pop("object_id") 

114 

115 action = AuditLogEntryAction(d.pop("action")) 

116 

117 timestamp = datetime.datetime.fromisoformat(d.pop("timestamp")) 

118 

119 ip = d.pop("ip") 

120 

121 _variant_id = d.pop("variant_id", UNSET) 

122 variant_id: UUID | Unset 

123 variant_id = UNSET if isinstance(_variant_id, Unset) else UUID(_variant_id) 

124 

125 caller = d.pop("caller", UNSET) 

126 

127 _actor_type = d.pop("actor_type", UNSET) 

128 actor_type: AuditLogEntryActorType | Unset 

129 if isinstance(_actor_type, Unset): 

130 actor_type = UNSET 

131 else: 

132 actor_type = AuditLogEntryActorType(_actor_type) 

133 

134 actor_id = d.pop("actor_id", UNSET) 

135 

136 audit_log_entry = cls( 

137 id=id, 

138 object_id=object_id, 

139 action=action, 

140 timestamp=timestamp, 

141 ip=ip, 

142 variant_id=variant_id, 

143 caller=caller, 

144 actor_type=actor_type, 

145 actor_id=actor_id, 

146 ) 

147 

148 audit_log_entry.additional_properties = d 

149 return audit_log_entry 

150 

151 @property 

152 def additional_keys(self) -> list[str]: 

153 return list(self.additional_properties.keys()) 

154 

155 def __getitem__(self, key: str) -> Any: 

156 return self.additional_properties[key] 

157 

158 def __setitem__(self, key: str, value: Any) -> None: 

159 self.additional_properties[key] = value 

160 

161 def __delitem__(self, key: str) -> None: 

162 del self.additional_properties[key] 

163 

164 def __contains__(self, key: str) -> bool: 

165 return key in self.additional_properties