Coverage for src/hush_hush/_generated/api/objects/get_object.py: 77%
60 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 io import BytesIO
5from typing import Any
6from urllib.parse import quote
7from uuid import UUID
9import httpx
11from ... import errors
12from ...client import AuthenticatedClient, Client
13from ...models.error import Error
14from ...types import UNSET, File, Response, Unset
17def _get_kwargs(
18 slug: str,
19 *,
20 id: UUID | Unset = UNSET,
21 consumer: str | Unset = UNSET,
22 x_caller: str | Unset = UNSET,
23) -> dict[str, Any]:
24 headers: dict[str, Any] = {}
25 if not isinstance(x_caller, Unset):
26 headers["X-Caller"] = x_caller
28 params: dict[str, Any] = {}
30 json_id: str | Unset = UNSET
31 if not isinstance(id, Unset):
32 json_id = str(id)
33 params["id"] = json_id
35 params["consumer"] = consumer
37 params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
39 _kwargs: dict[str, Any] = {
40 "method": "get",
41 "url": "/objects/{slug}".format(
42 slug=quote(str(slug), safe=""),
43 ),
44 "params": params,
45 }
47 _kwargs["headers"] = headers
48 return _kwargs
51def _parse_response(
52 *, client: AuthenticatedClient | Client, response: httpx.Response
53) -> Error | File | None:
54 if response.status_code == 200:
55 response_200 = File(payload=BytesIO(response.content))
57 return response_200
59 if response.status_code == 400:
60 response_400 = Error.from_dict(response.json())
62 return response_400
64 if response.status_code == 401:
65 response_401 = Error.from_dict(response.json())
67 return response_401
69 if response.status_code == 404:
70 response_404 = Error.from_dict(response.json())
72 return response_404
74 if response.status_code == 409:
75 response_409 = Error.from_dict(response.json())
77 return response_409
79 if response.status_code == 422:
80 response_422 = Error.from_dict(response.json())
82 return response_422
84 if client.raise_on_unexpected_status:
85 raise errors.UnexpectedStatus(response.status_code, response.content)
86 else:
87 return None
90def _build_response(
91 *, client: AuthenticatedClient | Client, response: httpx.Response
92) -> Response[Error | File]:
93 return Response(
94 status_code=HTTPStatus(response.status_code),
95 content=response.content,
96 headers=response.headers,
97 parsed=_parse_response(client=client, response=response),
98 )
101def sync_detailed(
102 slug: str,
103 *,
104 client: AuthenticatedClient,
105 id: UUID | Unset = UNSET,
106 consumer: str | Unset = UNSET,
107 x_caller: str | Unset = UNSET,
108) -> Response[Error | File]:
109 """Fetch an object's sealed ciphertext
111 Returns the stored ciphertext exactly as sealed, byte for byte -
112 the service never decrypts it. Requires a write bearer token, an
113 admin session, or a consumer read token whose bound consumer
114 appears in this object's `used_by` list - the confidentiality
115 boundary is still "who holds a matching private key," this adds
116 an access-control layer on top of it
117 (openspec/changes/consumer-read-tokens/proposal.md). Every fetch
118 is recorded to the audit log regardless of which credential
119 authenticated it.
121 A consumer token presented for an object outside its scope gets
122 the same 404 an unknown slug would, not 403 - so it can't be used
123 to enumerate which other slugs exist.
125 Args:
126 slug (str): A caller-chosen, unique identifier for an object - what every
127 documented request path (URL, CLI, API) addresses it by. Letters of
128 either case, digits, `_` and `-`, starting with a letter or digit;
129 names are case-sensitive, so `Api_Token` and `api_token` are two
130 secrets. Create and rename follow the same rule. The
131 object's internal id is a separate, opaque value never exposed to
132 or accepted from a caller (specs/secret-objects/spec.md's
133 "Internal id decoupled from user-facing slug" requirement).
134 id (UUID | Unset):
135 consumer (str | Unset):
136 x_caller (str | Unset):
138 Raises:
139 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
140 httpx.TimeoutException: If the request takes longer than Client.timeout.
142 Returns:
143 Response[Error | File]
144 """
146 kwargs = _get_kwargs(
147 slug=slug,
148 id=id,
149 consumer=consumer,
150 x_caller=x_caller,
151 )
153 response = client.get_httpx_client().request(
154 **kwargs,
155 )
157 return _build_response(client=client, response=response)
160def sync(
161 slug: str,
162 *,
163 client: AuthenticatedClient,
164 id: UUID | Unset = UNSET,
165 consumer: str | Unset = UNSET,
166 x_caller: str | Unset = UNSET,
167) -> Error | File | None:
168 """Fetch an object's sealed ciphertext
170 Returns the stored ciphertext exactly as sealed, byte for byte -
171 the service never decrypts it. Requires a write bearer token, an
172 admin session, or a consumer read token whose bound consumer
173 appears in this object's `used_by` list - the confidentiality
174 boundary is still "who holds a matching private key," this adds
175 an access-control layer on top of it
176 (openspec/changes/consumer-read-tokens/proposal.md). Every fetch
177 is recorded to the audit log regardless of which credential
178 authenticated it.
180 A consumer token presented for an object outside its scope gets
181 the same 404 an unknown slug would, not 403 - so it can't be used
182 to enumerate which other slugs exist.
184 Args:
185 slug (str): A caller-chosen, unique identifier for an object - what every
186 documented request path (URL, CLI, API) addresses it by. Letters of
187 either case, digits, `_` and `-`, starting with a letter or digit;
188 names are case-sensitive, so `Api_Token` and `api_token` are two
189 secrets. Create and rename follow the same rule. The
190 object's internal id is a separate, opaque value never exposed to
191 or accepted from a caller (specs/secret-objects/spec.md's
192 "Internal id decoupled from user-facing slug" requirement).
193 id (UUID | Unset):
194 consumer (str | Unset):
195 x_caller (str | Unset):
197 Raises:
198 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
199 httpx.TimeoutException: If the request takes longer than Client.timeout.
201 Returns:
202 Error | File
203 """
205 return sync_detailed(
206 slug=slug,
207 client=client,
208 id=id,
209 consumer=consumer,
210 x_caller=x_caller,
211 ).parsed
214async def asyncio_detailed(
215 slug: str,
216 *,
217 client: AuthenticatedClient,
218 id: UUID | Unset = UNSET,
219 consumer: str | Unset = UNSET,
220 x_caller: str | Unset = UNSET,
221) -> Response[Error | File]:
222 """Fetch an object's sealed ciphertext
224 Returns the stored ciphertext exactly as sealed, byte for byte -
225 the service never decrypts it. Requires a write bearer token, an
226 admin session, or a consumer read token whose bound consumer
227 appears in this object's `used_by` list - the confidentiality
228 boundary is still "who holds a matching private key," this adds
229 an access-control layer on top of it
230 (openspec/changes/consumer-read-tokens/proposal.md). Every fetch
231 is recorded to the audit log regardless of which credential
232 authenticated it.
234 A consumer token presented for an object outside its scope gets
235 the same 404 an unknown slug would, not 403 - so it can't be used
236 to enumerate which other slugs exist.
238 Args:
239 slug (str): A caller-chosen, unique identifier for an object - what every
240 documented request path (URL, CLI, API) addresses it by. Letters of
241 either case, digits, `_` and `-`, starting with a letter or digit;
242 names are case-sensitive, so `Api_Token` and `api_token` are two
243 secrets. Create and rename follow the same rule. The
244 object's internal id is a separate, opaque value never exposed to
245 or accepted from a caller (specs/secret-objects/spec.md's
246 "Internal id decoupled from user-facing slug" requirement).
247 id (UUID | Unset):
248 consumer (str | Unset):
249 x_caller (str | Unset):
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 Response[Error | File]
257 """
259 kwargs = _get_kwargs(
260 slug=slug,
261 id=id,
262 consumer=consumer,
263 x_caller=x_caller,
264 )
266 response = await client.get_async_httpx_client().request(**kwargs)
268 return _build_response(client=client, response=response)
271async def asyncio(
272 slug: str,
273 *,
274 client: AuthenticatedClient,
275 id: UUID | Unset = UNSET,
276 consumer: str | Unset = UNSET,
277 x_caller: str | Unset = UNSET,
278) -> Error | File | None:
279 """Fetch an object's sealed ciphertext
281 Returns the stored ciphertext exactly as sealed, byte for byte -
282 the service never decrypts it. Requires a write bearer token, an
283 admin session, or a consumer read token whose bound consumer
284 appears in this object's `used_by` list - the confidentiality
285 boundary is still "who holds a matching private key," this adds
286 an access-control layer on top of it
287 (openspec/changes/consumer-read-tokens/proposal.md). Every fetch
288 is recorded to the audit log regardless of which credential
289 authenticated it.
291 A consumer token presented for an object outside its scope gets
292 the same 404 an unknown slug would, not 403 - so it can't be used
293 to enumerate which other slugs exist.
295 Args:
296 slug (str): A caller-chosen, unique identifier for an object - what every
297 documented request path (URL, CLI, API) addresses it by. Letters of
298 either case, digits, `_` and `-`, starting with a letter or digit;
299 names are case-sensitive, so `Api_Token` and `api_token` are two
300 secrets. Create and rename follow the same rule. The
301 object's internal id is a separate, opaque value never exposed to
302 or accepted from a caller (specs/secret-objects/spec.md's
303 "Internal id decoupled from user-facing slug" requirement).
304 id (UUID | Unset):
305 consumer (str | Unset):
306 x_caller (str | Unset):
308 Raises:
309 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
310 httpx.TimeoutException: If the request takes longer than Client.timeout.
312 Returns:
313 Error | File
314 """
316 return (
317 await asyncio_detailed(
318 slug=slug,
319 client=client,
320 id=id,
321 consumer=consumer,
322 x_caller=x_caller,
323 )
324 ).parsed