Coverage for src/hush_hush/_generated/api/tokens/rotate_token.py: 0%
54 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 http import HTTPStatus
4from typing import Any
5from urllib.parse import quote
7import httpx
9from ... import errors
10from ...client import AuthenticatedClient, Client
11from ...models.error import Error
12from ...models.rotate_token_request import RotateTokenRequest
13from ...models.token_with_value import TokenWithValue
14from ...types import Response
17def _get_kwargs(
18 id: str,
19 *,
20 body: RotateTokenRequest,
21 x_csrf_token: str,
22) -> dict[str, Any]:
23 headers: dict[str, Any] = {}
24 headers["X-CSRF-Token"] = x_csrf_token
26 _kwargs: dict[str, Any] = {
27 "method": "post",
28 "url": "/tokens/{id}/rotate".format(
29 id=quote(str(id), safe=""),
30 ),
31 }
33 _kwargs["json"] = body.to_dict()
35 headers["Content-Type"] = "application/json"
37 _kwargs["headers"] = headers
38 return _kwargs
41def _parse_response(
42 *, client: AuthenticatedClient | Client, response: httpx.Response
43) -> Error | TokenWithValue | None:
44 if response.status_code == 200:
45 response_200 = TokenWithValue.from_dict(response.json())
47 return response_200
49 if response.status_code == 400:
50 response_400 = Error.from_dict(response.json())
52 return response_400
54 if response.status_code == 401:
55 response_401 = Error.from_dict(response.json())
57 return response_401
59 if response.status_code == 404:
60 response_404 = Error.from_dict(response.json())
62 return response_404
64 if response.status_code == 413:
65 response_413 = Error.from_dict(response.json())
67 return response_413
69 if response.status_code == 422:
70 response_422 = Error.from_dict(response.json())
72 return response_422
74 if client.raise_on_unexpected_status:
75 raise errors.UnexpectedStatus(response.status_code, response.content)
76 else:
77 return None
80def _build_response(
81 *, client: AuthenticatedClient | Client, response: httpx.Response
82) -> Response[Error | TokenWithValue]:
83 return Response(
84 status_code=HTTPStatus(response.status_code),
85 content=response.content,
86 headers=response.headers,
87 parsed=_parse_response(client=client, response=response),
88 )
91def sync_detailed(
92 id: str,
93 *,
94 client: AuthenticatedClient,
95 body: RotateTokenRequest,
96 x_csrf_token: str,
97) -> Response[Error | TokenWithValue]:
98 """Rotate a write bearer token
100 Replaces the secret and expiry of the token issued under id,
101 keeping its id, description, and owner unchanged - so an audit
102 log entry, or anything else that already refers to the token by
103 id, keeps resolving through the rotation. The old secret stops
104 authenticating immediately. The new raw token value is returned
105 here only, the same as `createToken`.
107 Unlike `revokeToken`, an id that's unknown, already revoked, or
108 already expired is an error: a rotate response promises the
109 caller a working new secret, and there's no valid token to hand
110 one to.
112 Args:
113 id (str):
114 x_csrf_token (str):
115 body (RotateTokenRequest):
117 Raises:
118 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
119 httpx.TimeoutException: If the request takes longer than Client.timeout.
121 Returns:
122 Response[Error | TokenWithValue]
123 """
125 kwargs = _get_kwargs(
126 id=id,
127 body=body,
128 x_csrf_token=x_csrf_token,
129 )
131 response = client.get_httpx_client().request(
132 **kwargs,
133 )
135 return _build_response(client=client, response=response)
138def sync(
139 id: str,
140 *,
141 client: AuthenticatedClient,
142 body: RotateTokenRequest,
143 x_csrf_token: str,
144) -> Error | TokenWithValue | None:
145 """Rotate a write bearer token
147 Replaces the secret and expiry of the token issued under id,
148 keeping its id, description, and owner unchanged - so an audit
149 log entry, or anything else that already refers to the token by
150 id, keeps resolving through the rotation. The old secret stops
151 authenticating immediately. The new raw token value is returned
152 here only, the same as `createToken`.
154 Unlike `revokeToken`, an id that's unknown, already revoked, or
155 already expired is an error: a rotate response promises the
156 caller a working new secret, and there's no valid token to hand
157 one to.
159 Args:
160 id (str):
161 x_csrf_token (str):
162 body (RotateTokenRequest):
164 Raises:
165 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
166 httpx.TimeoutException: If the request takes longer than Client.timeout.
168 Returns:
169 Error | TokenWithValue
170 """
172 return sync_detailed(
173 id=id,
174 client=client,
175 body=body,
176 x_csrf_token=x_csrf_token,
177 ).parsed
180async def asyncio_detailed(
181 id: str,
182 *,
183 client: AuthenticatedClient,
184 body: RotateTokenRequest,
185 x_csrf_token: str,
186) -> Response[Error | TokenWithValue]:
187 """Rotate a write bearer token
189 Replaces the secret and expiry of the token issued under id,
190 keeping its id, description, and owner unchanged - so an audit
191 log entry, or anything else that already refers to the token by
192 id, keeps resolving through the rotation. The old secret stops
193 authenticating immediately. The new raw token value is returned
194 here only, the same as `createToken`.
196 Unlike `revokeToken`, an id that's unknown, already revoked, or
197 already expired is an error: a rotate response promises the
198 caller a working new secret, and there's no valid token to hand
199 one to.
201 Args:
202 id (str):
203 x_csrf_token (str):
204 body (RotateTokenRequest):
206 Raises:
207 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
208 httpx.TimeoutException: If the request takes longer than Client.timeout.
210 Returns:
211 Response[Error | TokenWithValue]
212 """
214 kwargs = _get_kwargs(
215 id=id,
216 body=body,
217 x_csrf_token=x_csrf_token,
218 )
220 response = await client.get_async_httpx_client().request(**kwargs)
222 return _build_response(client=client, response=response)
225async def asyncio(
226 id: str,
227 *,
228 client: AuthenticatedClient,
229 body: RotateTokenRequest,
230 x_csrf_token: str,
231) -> Error | TokenWithValue | None:
232 """Rotate a write bearer token
234 Replaces the secret and expiry of the token issued under id,
235 keeping its id, description, and owner unchanged - so an audit
236 log entry, or anything else that already refers to the token by
237 id, keeps resolving through the rotation. The old secret stops
238 authenticating immediately. The new raw token value is returned
239 here only, the same as `createToken`.
241 Unlike `revokeToken`, an id that's unknown, already revoked, or
242 already expired is an error: a rotate response promises the
243 caller a working new secret, and there's no valid token to hand
244 one to.
246 Args:
247 id (str):
248 x_csrf_token (str):
249 body (RotateTokenRequest):
251 Raises:
252 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
253 httpx.TimeoutException: If the request takes longer than Client.timeout.
255 Returns:
256 Error | TokenWithValue
257 """
259 return (
260 await asyncio_detailed(
261 id=id,
262 client=client,
263 body=body,
264 x_csrf_token=x_csrf_token,
265 )
266 ).parsed