Coverage for src/hush_hush/_generated/api/consumers/add_consumer.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
6import httpx
8from ... import errors
9from ...client import AuthenticatedClient, Client
10from ...models.add_consumer_request import AddConsumerRequest
11from ...models.consumer_entry import ConsumerEntry
12from ...models.error import Error
13from ...types import UNSET, Response, Unset
16def _get_kwargs(
17 *,
18 body: AddConsumerRequest,
19 x_csrf_token: str | Unset = UNSET,
20) -> dict[str, Any]:
21 headers: dict[str, Any] = {}
22 if not isinstance(x_csrf_token, Unset):
23 headers["X-CSRF-Token"] = x_csrf_token
25 _kwargs: dict[str, Any] = {
26 "method": "post",
27 "url": "/consumers",
28 }
30 _kwargs["json"] = body.to_dict()
32 headers["Content-Type"] = "application/json"
34 _kwargs["headers"] = headers
35 return _kwargs
38def _parse_response(
39 *, client: AuthenticatedClient | Client, response: httpx.Response
40) -> ConsumerEntry | Error | None:
41 if response.status_code == 201:
42 response_201 = ConsumerEntry.from_dict(response.json())
44 return response_201
46 if response.status_code == 400:
47 response_400 = Error.from_dict(response.json())
49 return response_400
51 if response.status_code == 401:
52 response_401 = Error.from_dict(response.json())
54 return response_401
56 if response.status_code == 409:
57 response_409 = Error.from_dict(response.json())
59 return response_409
61 if response.status_code == 413:
62 response_413 = Error.from_dict(response.json())
64 return response_413
66 if response.status_code == 422:
67 response_422 = Error.from_dict(response.json())
69 return response_422
71 if client.raise_on_unexpected_status:
72 raise errors.UnexpectedStatus(response.status_code, response.content)
73 else:
74 return None
77def _build_response(
78 *, client: AuthenticatedClient | Client, response: httpx.Response
79) -> Response[ConsumerEntry | Error]:
80 return Response(
81 status_code=HTTPStatus(response.status_code),
82 content=response.content,
83 headers=response.headers,
84 parsed=_parse_response(client=client, response=response),
85 )
88def sync_detailed(
89 *,
90 client: AuthenticatedClient,
91 body: AddConsumerRequest,
92 x_csrf_token: str | Unset = UNSET,
93) -> Response[ConsumerEntry | Error]:
94 """Add a consumer with no secret referencing it yet
96 Adds `name` to the directory (`alrayyes/hush-hush#324`) without
97 requiring any object's `used_by` list to reference it first -
98 unlike every other consumer here, which only ever exist because
99 some object's `used_by` recorded them. The new entry appears in
100 `GET /consumers` with a `secret_count` of 0 until something
101 actually uses it. A session-authenticated call needs its CSRF
102 token too; a bearer-token-authenticated one doesn't.
104 Args:
105 x_csrf_token (str | Unset):
106 body (AddConsumerRequest):
108 Raises:
109 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
110 httpx.TimeoutException: If the request takes longer than Client.timeout.
112 Returns:
113 Response[ConsumerEntry | Error]
114 """
116 kwargs = _get_kwargs(
117 body=body,
118 x_csrf_token=x_csrf_token,
119 )
121 response = client.get_httpx_client().request(
122 **kwargs,
123 )
125 return _build_response(client=client, response=response)
128def sync(
129 *,
130 client: AuthenticatedClient,
131 body: AddConsumerRequest,
132 x_csrf_token: str | Unset = UNSET,
133) -> ConsumerEntry | Error | None:
134 """Add a consumer with no secret referencing it yet
136 Adds `name` to the directory (`alrayyes/hush-hush#324`) without
137 requiring any object's `used_by` list to reference it first -
138 unlike every other consumer here, which only ever exist because
139 some object's `used_by` recorded them. The new entry appears in
140 `GET /consumers` with a `secret_count` of 0 until something
141 actually uses it. A session-authenticated call needs its CSRF
142 token too; a bearer-token-authenticated one doesn't.
144 Args:
145 x_csrf_token (str | Unset):
146 body (AddConsumerRequest):
148 Raises:
149 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
150 httpx.TimeoutException: If the request takes longer than Client.timeout.
152 Returns:
153 ConsumerEntry | Error
154 """
156 return sync_detailed(
157 client=client,
158 body=body,
159 x_csrf_token=x_csrf_token,
160 ).parsed
163async def asyncio_detailed(
164 *,
165 client: AuthenticatedClient,
166 body: AddConsumerRequest,
167 x_csrf_token: str | Unset = UNSET,
168) -> Response[ConsumerEntry | Error]:
169 """Add a consumer with no secret referencing it yet
171 Adds `name` to the directory (`alrayyes/hush-hush#324`) without
172 requiring any object's `used_by` list to reference it first -
173 unlike every other consumer here, which only ever exist because
174 some object's `used_by` recorded them. The new entry appears in
175 `GET /consumers` with a `secret_count` of 0 until something
176 actually uses it. A session-authenticated call needs its CSRF
177 token too; a bearer-token-authenticated one doesn't.
179 Args:
180 x_csrf_token (str | Unset):
181 body (AddConsumerRequest):
183 Raises:
184 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
185 httpx.TimeoutException: If the request takes longer than Client.timeout.
187 Returns:
188 Response[ConsumerEntry | Error]
189 """
191 kwargs = _get_kwargs(
192 body=body,
193 x_csrf_token=x_csrf_token,
194 )
196 response = await client.get_async_httpx_client().request(**kwargs)
198 return _build_response(client=client, response=response)
201async def asyncio(
202 *,
203 client: AuthenticatedClient,
204 body: AddConsumerRequest,
205 x_csrf_token: str | Unset = UNSET,
206) -> ConsumerEntry | Error | None:
207 """Add a consumer with no secret referencing it yet
209 Adds `name` to the directory (`alrayyes/hush-hush#324`) without
210 requiring any object's `used_by` list to reference it first -
211 unlike every other consumer here, which only ever exist because
212 some object's `used_by` recorded them. The new entry appears in
213 `GET /consumers` with a `secret_count` of 0 until something
214 actually uses it. A session-authenticated call needs its CSRF
215 token too; a bearer-token-authenticated one doesn't.
217 Args:
218 x_csrf_token (str | Unset):
219 body (AddConsumerRequest):
221 Raises:
222 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
223 httpx.TimeoutException: If the request takes longer than Client.timeout.
225 Returns:
226 ConsumerEntry | Error
227 """
229 return (
230 await asyncio_detailed(
231 client=client,
232 body=body,
233 x_csrf_token=x_csrf_token,
234 )
235 ).parsed