Coverage for src/hush_hush/_generated/api/tokens/create_token.py: 0%
50 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
6import httpx
8from ... import errors
9from ...client import AuthenticatedClient, Client
10from ...models.create_token_request import CreateTokenRequest
11from ...models.error import Error
12from ...models.token_with_value import TokenWithValue
13from ...types import Response
16def _get_kwargs(
17 *,
18 body: CreateTokenRequest,
19 x_csrf_token: str,
20) -> dict[str, Any]:
21 headers: dict[str, Any] = {}
22 headers["X-CSRF-Token"] = x_csrf_token
24 _kwargs: dict[str, Any] = {
25 "method": "post",
26 "url": "/tokens",
27 }
29 _kwargs["json"] = body.to_dict()
31 headers["Content-Type"] = "application/json"
33 _kwargs["headers"] = headers
34 return _kwargs
37def _parse_response(
38 *, client: AuthenticatedClient | Client, response: httpx.Response
39) -> Error | TokenWithValue | None:
40 if response.status_code == 201:
41 response_201 = TokenWithValue.from_dict(response.json())
43 return response_201
45 if response.status_code == 400:
46 response_400 = Error.from_dict(response.json())
48 return response_400
50 if response.status_code == 401:
51 response_401 = Error.from_dict(response.json())
53 return response_401
55 if response.status_code == 413:
56 response_413 = Error.from_dict(response.json())
58 return response_413
60 if response.status_code == 422:
61 response_422 = Error.from_dict(response.json())
63 return response_422
65 if client.raise_on_unexpected_status:
66 raise errors.UnexpectedStatus(response.status_code, response.content)
67 else:
68 return None
71def _build_response(
72 *, client: AuthenticatedClient | Client, response: httpx.Response
73) -> Response[Error | TokenWithValue]:
74 return Response(
75 status_code=HTTPStatus(response.status_code),
76 content=response.content,
77 headers=response.headers,
78 parsed=_parse_response(client=client, response=response),
79 )
82def sync_detailed(
83 *,
84 client: AuthenticatedClient,
85 body: CreateTokenRequest,
86 x_csrf_token: str,
87) -> Response[Error | TokenWithValue]:
88 """Create a write bearer token
90 Issues a new write-path bearer token, owned by the admin account
91 that created it. The raw token value is returned here only - it
92 is never recoverable again once this response is read, the same
93 as a token issued via the `token` CLI command.
95 Args:
96 x_csrf_token (str):
97 body (CreateTokenRequest):
99 Raises:
100 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
101 httpx.TimeoutException: If the request takes longer than Client.timeout.
103 Returns:
104 Response[Error | TokenWithValue]
105 """
107 kwargs = _get_kwargs(
108 body=body,
109 x_csrf_token=x_csrf_token,
110 )
112 response = client.get_httpx_client().request(
113 **kwargs,
114 )
116 return _build_response(client=client, response=response)
119def sync(
120 *,
121 client: AuthenticatedClient,
122 body: CreateTokenRequest,
123 x_csrf_token: str,
124) -> Error | TokenWithValue | None:
125 """Create a write bearer token
127 Issues a new write-path bearer token, owned by the admin account
128 that created it. The raw token value is returned here only - it
129 is never recoverable again once this response is read, the same
130 as a token issued via the `token` CLI command.
132 Args:
133 x_csrf_token (str):
134 body (CreateTokenRequest):
136 Raises:
137 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
138 httpx.TimeoutException: If the request takes longer than Client.timeout.
140 Returns:
141 Error | TokenWithValue
142 """
144 return sync_detailed(
145 client=client,
146 body=body,
147 x_csrf_token=x_csrf_token,
148 ).parsed
151async def asyncio_detailed(
152 *,
153 client: AuthenticatedClient,
154 body: CreateTokenRequest,
155 x_csrf_token: str,
156) -> Response[Error | TokenWithValue]:
157 """Create a write bearer token
159 Issues a new write-path bearer token, owned by the admin account
160 that created it. The raw token value is returned here only - it
161 is never recoverable again once this response is read, the same
162 as a token issued via the `token` CLI command.
164 Args:
165 x_csrf_token (str):
166 body (CreateTokenRequest):
168 Raises:
169 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
170 httpx.TimeoutException: If the request takes longer than Client.timeout.
172 Returns:
173 Response[Error | TokenWithValue]
174 """
176 kwargs = _get_kwargs(
177 body=body,
178 x_csrf_token=x_csrf_token,
179 )
181 response = await client.get_async_httpx_client().request(**kwargs)
183 return _build_response(client=client, response=response)
186async def asyncio(
187 *,
188 client: AuthenticatedClient,
189 body: CreateTokenRequest,
190 x_csrf_token: str,
191) -> Error | TokenWithValue | None:
192 """Create a write bearer token
194 Issues a new write-path bearer token, owned by the admin account
195 that created it. The raw token value is returned here only - it
196 is never recoverable again once this response is read, the same
197 as a token issued via the `token` CLI command.
199 Args:
200 x_csrf_token (str):
201 body (CreateTokenRequest):
203 Raises:
204 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
205 httpx.TimeoutException: If the request takes longer than Client.timeout.
207 Returns:
208 Error | TokenWithValue
209 """
211 return (
212 await asyncio_detailed(
213 client=client,
214 body=body,
215 x_csrf_token=x_csrf_token,
216 )
217 ).parsed