Coverage for src/hush_hush/_generated/api/objects/create_object.py: 58%
53 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_object_request import CreateObjectRequest
11from ...models.error import Error
12from ...models.object_metadata import ObjectMetadata
13from ...types import UNSET, Response, Unset
16def _get_kwargs(
17 *,
18 body: CreateObjectRequest,
19 x_caller: str | Unset = UNSET,
20 x_csrf_token: str | Unset = UNSET,
21) -> dict[str, Any]:
22 headers: dict[str, Any] = {}
23 if not isinstance(x_caller, Unset):
24 headers["X-Caller"] = x_caller
26 if not isinstance(x_csrf_token, Unset):
27 headers["X-CSRF-Token"] = x_csrf_token
29 _kwargs: dict[str, Any] = {
30 "method": "post",
31 "url": "/objects",
32 }
34 _kwargs["json"] = body.to_dict()
36 headers["Content-Type"] = "application/json"
38 _kwargs["headers"] = headers
39 return _kwargs
42def _parse_response(
43 *, client: AuthenticatedClient | Client, response: httpx.Response
44) -> Error | ObjectMetadata | None:
45 if response.status_code == 201:
46 response_201 = ObjectMetadata.from_dict(response.json())
48 return response_201
50 if response.status_code == 401:
51 response_401 = Error.from_dict(response.json())
53 return response_401
55 if response.status_code == 409:
56 response_409 = Error.from_dict(response.json())
58 return response_409
60 if response.status_code == 413:
61 response_413 = Error.from_dict(response.json())
63 return response_413
65 if response.status_code == 422:
66 response_422 = Error.from_dict(response.json())
68 return response_422
70 if client.raise_on_unexpected_status:
71 raise errors.UnexpectedStatus(response.status_code, response.content)
72 else:
73 return None
76def _build_response(
77 *, client: AuthenticatedClient | Client, response: httpx.Response
78) -> Response[Error | ObjectMetadata]:
79 return Response(
80 status_code=HTTPStatus(response.status_code),
81 content=response.content,
82 headers=response.headers,
83 parsed=_parse_response(client=client, response=response),
84 )
87def sync_detailed(
88 *,
89 client: AuthenticatedClient,
90 body: CreateObjectRequest,
91 x_caller: str | Unset = UNSET,
92 x_csrf_token: str | Unset = UNSET,
93) -> Response[Error | ObjectMetadata]:
94 """Create a new sealed object
96 Stores an already-sealed value under a new, caller-chosen slug -
97 the object's own internal id is generated server-side and never
98 returned as something addressable. The service never decrypts the
99 value, and it can't know how many recipients it was sealed to or
100 whether any key is right. It does read the age header: a value
101 that isn't base64 of a well-formed age file, or whose header
102 names no recipient, is a 422 and nothing is stored. A session-
103 authenticated call needs its CSRF token too; a bearer-token-
104 authenticated one doesn't, since there's no session to have one.
106 Args:
107 x_caller (str | Unset):
108 x_csrf_token (str | Unset):
109 body (CreateObjectRequest):
111 Raises:
112 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
113 httpx.TimeoutException: If the request takes longer than Client.timeout.
115 Returns:
116 Response[Error | ObjectMetadata]
117 """
119 kwargs = _get_kwargs(
120 body=body,
121 x_caller=x_caller,
122 x_csrf_token=x_csrf_token,
123 )
125 response = client.get_httpx_client().request(
126 **kwargs,
127 )
129 return _build_response(client=client, response=response)
132def sync(
133 *,
134 client: AuthenticatedClient,
135 body: CreateObjectRequest,
136 x_caller: str | Unset = UNSET,
137 x_csrf_token: str | Unset = UNSET,
138) -> Error | ObjectMetadata | None:
139 """Create a new sealed object
141 Stores an already-sealed value under a new, caller-chosen slug -
142 the object's own internal id is generated server-side and never
143 returned as something addressable. The service never decrypts the
144 value, and it can't know how many recipients it was sealed to or
145 whether any key is right. It does read the age header: a value
146 that isn't base64 of a well-formed age file, or whose header
147 names no recipient, is a 422 and nothing is stored. A session-
148 authenticated call needs its CSRF token too; a bearer-token-
149 authenticated one doesn't, since there's no session to have one.
151 Args:
152 x_caller (str | Unset):
153 x_csrf_token (str | Unset):
154 body (CreateObjectRequest):
156 Raises:
157 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
158 httpx.TimeoutException: If the request takes longer than Client.timeout.
160 Returns:
161 Error | ObjectMetadata
162 """
164 return sync_detailed(
165 client=client,
166 body=body,
167 x_caller=x_caller,
168 x_csrf_token=x_csrf_token,
169 ).parsed
172async def asyncio_detailed(
173 *,
174 client: AuthenticatedClient,
175 body: CreateObjectRequest,
176 x_caller: str | Unset = UNSET,
177 x_csrf_token: str | Unset = UNSET,
178) -> Response[Error | ObjectMetadata]:
179 """Create a new sealed object
181 Stores an already-sealed value under a new, caller-chosen slug -
182 the object's own internal id is generated server-side and never
183 returned as something addressable. The service never decrypts the
184 value, and it can't know how many recipients it was sealed to or
185 whether any key is right. It does read the age header: a value
186 that isn't base64 of a well-formed age file, or whose header
187 names no recipient, is a 422 and nothing is stored. A session-
188 authenticated call needs its CSRF token too; a bearer-token-
189 authenticated one doesn't, since there's no session to have one.
191 Args:
192 x_caller (str | Unset):
193 x_csrf_token (str | Unset):
194 body (CreateObjectRequest):
196 Raises:
197 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
198 httpx.TimeoutException: If the request takes longer than Client.timeout.
200 Returns:
201 Response[Error | ObjectMetadata]
202 """
204 kwargs = _get_kwargs(
205 body=body,
206 x_caller=x_caller,
207 x_csrf_token=x_csrf_token,
208 )
210 response = await client.get_async_httpx_client().request(**kwargs)
212 return _build_response(client=client, response=response)
215async def asyncio(
216 *,
217 client: AuthenticatedClient,
218 body: CreateObjectRequest,
219 x_caller: str | Unset = UNSET,
220 x_csrf_token: str | Unset = UNSET,
221) -> Error | ObjectMetadata | None:
222 """Create a new sealed object
224 Stores an already-sealed value under a new, caller-chosen slug -
225 the object's own internal id is generated server-side and never
226 returned as something addressable. The service never decrypts the
227 value, and it can't know how many recipients it was sealed to or
228 whether any key is right. It does read the age header: a value
229 that isn't base64 of a well-formed age file, or whose header
230 names no recipient, is a 422 and nothing is stored. A session-
231 authenticated call needs its CSRF token too; a bearer-token-
232 authenticated one doesn't, since there's no session to have one.
234 Args:
235 x_caller (str | Unset):
236 x_csrf_token (str | Unset):
237 body (CreateObjectRequest):
239 Raises:
240 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
241 httpx.TimeoutException: If the request takes longer than Client.timeout.
243 Returns:
244 Error | ObjectMetadata
245 """
247 return (
248 await asyncio_detailed(
249 client=client,
250 body=body,
251 x_caller=x_caller,
252 x_csrf_token=x_csrf_token,
253 )
254 ).parsed