Coverage for src/hush_hush/_generated/models/token_with_value.py: 35%

92 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="TokenWithValue") 

17 

18 

19@_attrs_define 

20class TokenWithValue: 

21 """ 

22 Attributes: 

23 id (str): 

24 description (str): 

25 created_at (datetime.datetime): 

26 expires_at (datetime.datetime): 

27 revoked (bool): 

28 value (str): The raw bearer token. Shown here once, at creation, and 

29 never again - the same as a token issued via the `token` 

30 CLI command. 

31 owner (str | Unset): The admin account that created this token over HTTP. Absent 

32 for a token issued via the `token` CLI command, which has no 

33 session to attribute to - never a guessed value. 

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

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

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

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

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

39 reads a response from an older one. 

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

41 `rotate` and 

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

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

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

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

46 what to show. 

47 """ 

48 

49 id: str 

50 description: str 

51 created_at: datetime.datetime 

52 expires_at: datetime.datetime 

53 revoked: bool 

54 value: str 

55 owner: str | Unset = UNSET 

56 last_used_at: datetime.datetime | Unset = UNSET 

57 status: TokenStatus | Unset = UNSET 

58 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET 

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

60 

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

62 id = self.id 

63 

64 description = self.description 

65 

66 created_at = self.created_at.isoformat() 

67 

68 expires_at = self.expires_at.isoformat() 

69 

70 revoked = self.revoked 

71 

72 value = self.value 

73 

74 owner = self.owner 

75 

76 last_used_at: str | Unset = UNSET 

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

78 last_used_at = self.last_used_at.isoformat() 

79 

80 status: str | Unset = UNSET 

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

82 status = self.status.value 

83 

84 allowed_actions: list[str] | Unset = UNSET 

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

86 allowed_actions = [] 

87 for componentsschemas_token_allowed_actions_item_data in self.allowed_actions: 

88 componentsschemas_token_allowed_actions_item = ( 

89 componentsschemas_token_allowed_actions_item_data.value 

90 ) 

91 allowed_actions.append(componentsschemas_token_allowed_actions_item) 

92 

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

94 field_dict.update(self.additional_properties) 

95 field_dict.update( 

96 { 

97 "id": id, 

98 "description": description, 

99 "created_at": created_at, 

100 "expires_at": expires_at, 

101 "revoked": revoked, 

102 "value": value, 

103 } 

104 ) 

105 if owner is not UNSET: 

106 field_dict["owner"] = owner 

107 if last_used_at is not UNSET: 

108 field_dict["last_used_at"] = last_used_at 

109 if status is not UNSET: 

110 field_dict["status"] = status 

111 if allowed_actions is not UNSET: 

112 field_dict["allowed_actions"] = allowed_actions 

113 

114 return field_dict 

115 

116 @classmethod 

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

118 d = dict(src_dict) 

119 id = d.pop("id") 

120 

121 description = d.pop("description") 

122 

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

124 

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

126 

127 revoked = d.pop("revoked") 

128 

129 value = d.pop("value") 

130 

131 owner = d.pop("owner", UNSET) 

132 

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

134 last_used_at: datetime.datetime | Unset 

135 if isinstance(_last_used_at, Unset): 

136 last_used_at = UNSET 

137 else: 

138 last_used_at = datetime.datetime.fromisoformat(_last_used_at) 

139 

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

141 status: TokenStatus | Unset 

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

143 

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

145 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET 

146 if _allowed_actions is not UNSET: 

147 allowed_actions = [] 

148 for componentsschemas_token_allowed_actions_item_data in _allowed_actions: 

149 componentsschemas_token_allowed_actions_item = TokenAllowedActionsItem( 

150 componentsschemas_token_allowed_actions_item_data 

151 ) 

152 

153 allowed_actions.append(componentsschemas_token_allowed_actions_item) 

154 

155 token_with_value = cls( 

156 id=id, 

157 description=description, 

158 created_at=created_at, 

159 expires_at=expires_at, 

160 revoked=revoked, 

161 value=value, 

162 owner=owner, 

163 last_used_at=last_used_at, 

164 status=status, 

165 allowed_actions=allowed_actions, 

166 ) 

167 

168 token_with_value.additional_properties = d 

169 return token_with_value 

170 

171 @property 

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

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

174 

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

176 return self.additional_properties[key] 

177 

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

179 self.additional_properties[key] = value 

180 

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

182 del self.additional_properties[key] 

183 

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

185 return key in self.additional_properties