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

90 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="ConsumerTokenWithValue") 

17 

18 

19@_attrs_define 

20class ConsumerTokenWithValue: 

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 value (str): The raw consumer token. Shown here once, at creation, and 

30 never again. 

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

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

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

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

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

36 reads a response from an older one. 

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

38 `rotate` and 

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

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

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

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

43 what to show. 

44 """ 

45 

46 id: str 

47 consumer: str 

48 description: str 

49 created_at: datetime.datetime 

50 expires_at: datetime.datetime 

51 revoked: bool 

52 value: str 

53 last_used_at: datetime.datetime | Unset = UNSET 

54 status: TokenStatus | Unset = UNSET 

55 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET 

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

57 

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

59 id = self.id 

60 

61 consumer = self.consumer 

62 

63 description = self.description 

64 

65 created_at = self.created_at.isoformat() 

66 

67 expires_at = self.expires_at.isoformat() 

68 

69 revoked = self.revoked 

70 

71 value = self.value 

72 

73 last_used_at: str | Unset = UNSET 

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

75 last_used_at = self.last_used_at.isoformat() 

76 

77 status: str | Unset = UNSET 

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

79 status = self.status.value 

80 

81 allowed_actions: list[str] | Unset = UNSET 

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

83 allowed_actions = [] 

84 for componentsschemas_token_allowed_actions_item_data in self.allowed_actions: 

85 componentsschemas_token_allowed_actions_item = ( 

86 componentsschemas_token_allowed_actions_item_data.value 

87 ) 

88 allowed_actions.append(componentsschemas_token_allowed_actions_item) 

89 

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

91 field_dict.update(self.additional_properties) 

92 field_dict.update( 

93 { 

94 "id": id, 

95 "consumer": consumer, 

96 "description": description, 

97 "created_at": created_at, 

98 "expires_at": expires_at, 

99 "revoked": revoked, 

100 "value": value, 

101 } 

102 ) 

103 if last_used_at is not UNSET: 

104 field_dict["last_used_at"] = last_used_at 

105 if status is not UNSET: 

106 field_dict["status"] = status 

107 if allowed_actions is not UNSET: 

108 field_dict["allowed_actions"] = allowed_actions 

109 

110 return field_dict 

111 

112 @classmethod 

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

114 d = dict(src_dict) 

115 id = d.pop("id") 

116 

117 consumer = d.pop("consumer") 

118 

119 description = d.pop("description") 

120 

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

122 

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

124 

125 revoked = d.pop("revoked") 

126 

127 value = d.pop("value") 

128 

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

130 last_used_at: datetime.datetime | Unset 

131 if isinstance(_last_used_at, Unset): 

132 last_used_at = UNSET 

133 else: 

134 last_used_at = datetime.datetime.fromisoformat(_last_used_at) 

135 

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

137 status: TokenStatus | Unset 

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

139 

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

141 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET 

142 if _allowed_actions is not UNSET: 

143 allowed_actions = [] 

144 for componentsschemas_token_allowed_actions_item_data in _allowed_actions: 

145 componentsschemas_token_allowed_actions_item = TokenAllowedActionsItem( 

146 componentsschemas_token_allowed_actions_item_data 

147 ) 

148 

149 allowed_actions.append(componentsschemas_token_allowed_actions_item) 

150 

151 consumer_token_with_value = cls( 

152 id=id, 

153 consumer=consumer, 

154 description=description, 

155 created_at=created_at, 

156 expires_at=expires_at, 

157 revoked=revoked, 

158 value=value, 

159 last_used_at=last_used_at, 

160 status=status, 

161 allowed_actions=allowed_actions, 

162 ) 

163 

164 consumer_token_with_value.additional_properties = d 

165 return consumer_token_with_value 

166 

167 @property 

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

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

170 

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

172 return self.additional_properties[key] 

173 

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

175 self.additional_properties[key] = value 

176 

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

178 del self.additional_properties[key] 

179 

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

181 return key in self.additional_properties