Coverage for src/hush_hush/_generated/models/consumer_token_metadata.py: 36%

87 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 

8 

9from attrs import define as _attrs_define 

10from attrs import field as _attrs_field 

11 

12from ..models.token_allowed_actions_item import TokenAllowedActionsItem 

13from ..models.token_status import TokenStatus 

14from ..types import UNSET, Unset 

15 

16T = TypeVar("T", bound="ConsumerTokenMetadata") 

17 

18 

19@_attrs_define 

20class ConsumerTokenMetadata: 

21 """ 

22 Attributes: 

23 id (str): 

24 consumer (str): 

25 description (str): 

26 created_at (datetime.datetime): 

27 expires_at (datetime.datetime): 

28 revoked (bool): 

29 last_used_at (datetime.datetime | Unset): Absent if this token has never authenticated a request. 

30 status (TokenStatus | Unset): What the token is right now, by the server's own clock: `revoked` 

31 if it was revoked (even if it has also expired), `expired` if its 

32 `expires_at` has passed, `active` otherwise. Always sent by this 

33 server; optional in the schema so a client generated from it still 

34 reads a response from an older one. 

35 allowed_actions (list[TokenAllowedActionsItem] | Unset): What may be done to the token in its current state: 

36 `rotate` and 

37 `revoke` while it is `active`, only `purge` once it is `expired` or 

38 `revoked`. The endpoints enforce the same rule themselves - a purge 

39 of an active token is still a 409 - so a client that acts on a stale 

40 view gets the server's answer. Hiding a button is cosmetic; this is 

41 what to show. 

42 """ 

43 

44 id: str 

45 consumer: str 

46 description: str 

47 created_at: datetime.datetime 

48 expires_at: datetime.datetime 

49 revoked: bool 

50 last_used_at: datetime.datetime | Unset = UNSET 

51 status: TokenStatus | Unset = UNSET 

52 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET 

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

54 

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

56 id = self.id 

57 

58 consumer = self.consumer 

59 

60 description = self.description 

61 

62 created_at = self.created_at.isoformat() 

63 

64 expires_at = self.expires_at.isoformat() 

65 

66 revoked = self.revoked 

67 

68 last_used_at: str | Unset = UNSET 

69 if not isinstance(self.last_used_at, Unset): 

70 last_used_at = self.last_used_at.isoformat() 

71 

72 status: str | Unset = UNSET 

73 if not isinstance(self.status, Unset): 

74 status = self.status.value 

75 

76 allowed_actions: list[str] | Unset = UNSET 

77 if not isinstance(self.allowed_actions, Unset): 

78 allowed_actions = [] 

79 for componentsschemas_token_allowed_actions_item_data in self.allowed_actions: 

80 componentsschemas_token_allowed_actions_item = ( 

81 componentsschemas_token_allowed_actions_item_data.value 

82 ) 

83 allowed_actions.append(componentsschemas_token_allowed_actions_item) 

84 

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

86 field_dict.update(self.additional_properties) 

87 field_dict.update( 

88 { 

89 "id": id, 

90 "consumer": consumer, 

91 "description": description, 

92 "created_at": created_at, 

93 "expires_at": expires_at, 

94 "revoked": revoked, 

95 } 

96 ) 

97 if last_used_at is not UNSET: 

98 field_dict["last_used_at"] = last_used_at 

99 if status is not UNSET: 

100 field_dict["status"] = status 

101 if allowed_actions is not UNSET: 

102 field_dict["allowed_actions"] = allowed_actions 

103 

104 return field_dict 

105 

106 @classmethod 

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

108 d = dict(src_dict) 

109 id = d.pop("id") 

110 

111 consumer = d.pop("consumer") 

112 

113 description = d.pop("description") 

114 

115 created_at = datetime.datetime.fromisoformat(d.pop("created_at")) 

116 

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

118 

119 revoked = d.pop("revoked") 

120 

121 _last_used_at = d.pop("last_used_at", UNSET) 

122 last_used_at: datetime.datetime | Unset 

123 if isinstance(_last_used_at, Unset): 

124 last_used_at = UNSET 

125 else: 

126 last_used_at = datetime.datetime.fromisoformat(_last_used_at) 

127 

128 _status = d.pop("status", UNSET) 

129 status: TokenStatus | Unset 

130 status = UNSET if isinstance(_status, Unset) else TokenStatus(_status) 

131 

132 _allowed_actions = d.pop("allowed_actions", UNSET) 

133 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET 

134 if _allowed_actions is not UNSET: 

135 allowed_actions = [] 

136 for componentsschemas_token_allowed_actions_item_data in _allowed_actions: 

137 componentsschemas_token_allowed_actions_item = TokenAllowedActionsItem( 

138 componentsschemas_token_allowed_actions_item_data 

139 ) 

140 

141 allowed_actions.append(componentsschemas_token_allowed_actions_item) 

142 

143 consumer_token_metadata = cls( 

144 id=id, 

145 consumer=consumer, 

146 description=description, 

147 created_at=created_at, 

148 expires_at=expires_at, 

149 revoked=revoked, 

150 last_used_at=last_used_at, 

151 status=status, 

152 allowed_actions=allowed_actions, 

153 ) 

154 

155 consumer_token_metadata.additional_properties = d 

156 return consumer_token_metadata 

157 

158 @property 

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

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

161 

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

163 return self.additional_properties[key] 

164 

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

166 self.additional_properties[key] = value 

167 

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

169 del self.additional_properties[key] 

170 

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

172 return key in self.additional_properties