Coverage for src/hush_hush/_generated/models/token_metadata.py: 35%
89 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-10-16 16:01 +0000
« 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.
3from __future__ import annotations
5import datetime
6from collections.abc import Mapping
7from typing import Any, TypeVar
9from attrs import define as _attrs_define
10from attrs import field as _attrs_field
12from ..models.token_allowed_actions_item import TokenAllowedActionsItem
13from ..models.token_status import TokenStatus
14from ..types import UNSET, Unset
16T = TypeVar("T", bound="TokenMetadata")
19@_attrs_define
20class TokenMetadata:
21 """
22 Attributes:
23 id (str):
24 description (str):
25 created_at (datetime.datetime):
26 expires_at (datetime.datetime):
27 revoked (bool):
28 owner (str | Unset): The admin account that created this token over HTTP. Absent
29 for a token issued via the `token` CLI command, which has no
30 session to attribute to - never a guessed value.
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 """
46 id: str
47 description: str
48 created_at: datetime.datetime
49 expires_at: datetime.datetime
50 revoked: bool
51 owner: str | Unset = UNSET
52 last_used_at: datetime.datetime | Unset = UNSET
53 status: TokenStatus | Unset = UNSET
54 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET
55 additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
57 def to_dict(self) -> dict[str, Any]:
58 id = self.id
60 description = self.description
62 created_at = self.created_at.isoformat()
64 expires_at = self.expires_at.isoformat()
66 revoked = self.revoked
68 owner = self.owner
70 last_used_at: str | Unset = UNSET
71 if not isinstance(self.last_used_at, Unset):
72 last_used_at = self.last_used_at.isoformat()
74 status: str | Unset = UNSET
75 if not isinstance(self.status, Unset):
76 status = self.status.value
78 allowed_actions: list[str] | Unset = UNSET
79 if not isinstance(self.allowed_actions, Unset):
80 allowed_actions = []
81 for componentsschemas_token_allowed_actions_item_data in self.allowed_actions:
82 componentsschemas_token_allowed_actions_item = (
83 componentsschemas_token_allowed_actions_item_data.value
84 )
85 allowed_actions.append(componentsschemas_token_allowed_actions_item)
87 field_dict: dict[str, Any] = {}
88 field_dict.update(self.additional_properties)
89 field_dict.update(
90 {
91 "id": id,
92 "description": description,
93 "created_at": created_at,
94 "expires_at": expires_at,
95 "revoked": revoked,
96 }
97 )
98 if owner is not UNSET:
99 field_dict["owner"] = owner
100 if last_used_at is not UNSET:
101 field_dict["last_used_at"] = last_used_at
102 if status is not UNSET:
103 field_dict["status"] = status
104 if allowed_actions is not UNSET:
105 field_dict["allowed_actions"] = allowed_actions
107 return field_dict
109 @classmethod
110 def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
111 d = dict(src_dict)
112 id = d.pop("id")
114 description = d.pop("description")
116 created_at = datetime.datetime.fromisoformat(d.pop("created_at"))
118 expires_at = datetime.datetime.fromisoformat(d.pop("expires_at"))
120 revoked = d.pop("revoked")
122 owner = d.pop("owner", UNSET)
124 _last_used_at = d.pop("last_used_at", UNSET)
125 last_used_at: datetime.datetime | Unset
126 if isinstance(_last_used_at, Unset):
127 last_used_at = UNSET
128 else:
129 last_used_at = datetime.datetime.fromisoformat(_last_used_at)
131 _status = d.pop("status", UNSET)
132 status: TokenStatus | Unset
133 status = UNSET if isinstance(_status, Unset) else TokenStatus(_status)
135 _allowed_actions = d.pop("allowed_actions", UNSET)
136 allowed_actions: list[TokenAllowedActionsItem] | Unset = UNSET
137 if _allowed_actions is not UNSET:
138 allowed_actions = []
139 for componentsschemas_token_allowed_actions_item_data in _allowed_actions:
140 componentsschemas_token_allowed_actions_item = TokenAllowedActionsItem(
141 componentsschemas_token_allowed_actions_item_data
142 )
144 allowed_actions.append(componentsschemas_token_allowed_actions_item)
146 token_metadata = cls(
147 id=id,
148 description=description,
149 created_at=created_at,
150 expires_at=expires_at,
151 revoked=revoked,
152 owner=owner,
153 last_used_at=last_used_at,
154 status=status,
155 allowed_actions=allowed_actions,
156 )
158 token_metadata.additional_properties = d
159 return token_metadata
161 @property
162 def additional_keys(self) -> list[str]:
163 return list(self.additional_properties.keys())
165 def __getitem__(self, key: str) -> Any:
166 return self.additional_properties[key]
168 def __setitem__(self, key: str, value: Any) -> None:
169 self.additional_properties[key] = value
171 def __delitem__(self, key: str) -> None:
172 del self.additional_properties[key]
174 def __contains__(self, key: str) -> bool:
175 return key in self.additional_properties