Coverage for src/hush_hush/_generated/api/objects/patch_object.py: 0%
68 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
6from uuid import UUID
8import httpx
10from ... import errors
11from ...client import AuthenticatedClient, Client
12from ...models.error import Error
13from ...models.object_metadata import ObjectMetadata
14from ...models.patch_object_request import PatchObjectRequest
15from ...types import UNSET, Response, Unset
18def _get_kwargs(
19 slug: str,
20 *,
21 body: PatchObjectRequest,
22 id: UUID | Unset = UNSET,
23 consumer: str | Unset = UNSET,
24 x_caller: str | Unset = UNSET,
25 x_csrf_token: str | Unset = UNSET,
26) -> dict[str, Any]:
27 headers: dict[str, Any] = {}
28 if not isinstance(x_caller, Unset):
29 headers["X-Caller"] = x_caller
31 if not isinstance(x_csrf_token, Unset):
32 headers["X-CSRF-Token"] = x_csrf_token
34 params: dict[str, Any] = {}
36 json_id: str | Unset = UNSET
37 if not isinstance(id, Unset):
38 json_id = str(id)
39 params["id"] = json_id
41 params["consumer"] = consumer
43 params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
45 _kwargs: dict[str, Any] = {
46 "method": "patch",
47 "url": "/objects/{slug}".format(
48 slug=quote(str(slug), safe=""),
49 ),
50 "params": params,
51 }
53 _kwargs["json"] = body.to_dict()
55 headers["Content-Type"] = "application/json"
57 _kwargs["headers"] = headers
58 return _kwargs
61def _parse_response(
62 *, client: AuthenticatedClient | Client, response: httpx.Response
63) -> Error | ObjectMetadata | None:
64 if response.status_code == 200:
65 response_200 = ObjectMetadata.from_dict(response.json())
67 return response_200
69 if response.status_code == 400:
70 response_400 = Error.from_dict(response.json())
72 return response_400
74 if response.status_code == 401:
75 response_401 = Error.from_dict(response.json())
77 return response_401
79 if response.status_code == 404:
80 response_404 = Error.from_dict(response.json())
82 return response_404
84 if response.status_code == 409:
85 response_409 = Error.from_dict(response.json())
87 return response_409
89 if response.status_code == 413:
90 response_413 = Error.from_dict(response.json())
92 return response_413
94 if response.status_code == 422:
95 response_422 = Error.from_dict(response.json())
97 return response_422
99 if client.raise_on_unexpected_status:
100 raise errors.UnexpectedStatus(response.status_code, response.content)
101 else:
102 return None
105def _build_response(
106 *, client: AuthenticatedClient | Client, response: httpx.Response
107) -> Response[Error | ObjectMetadata]:
108 return Response(
109 status_code=HTTPStatus(response.status_code),
110 content=response.content,
111 headers=response.headers,
112 parsed=_parse_response(client=client, response=response),
113 )
116def sync_detailed(
117 slug: str,
118 *,
119 client: AuthenticatedClient,
120 body: PatchObjectRequest,
121 id: UUID | Unset = UNSET,
122 consumer: str | Unset = UNSET,
123 x_caller: str | Unset = UNSET,
124 x_csrf_token: str | Unset = UNSET,
125) -> Response[Error | ObjectMetadata]:
126 """Edit an object's description, tags or slug
128 Changes metadata without touching the sealed value, so fixing a
129 typo or reorganising names never needs the plaintext again. Send
130 any of `description`, `tags` and `slug`; a field left out stays as
131 it is, and at least one is required. The change is applied whole
132 or not at all, so a refused rename applies none of the request.
134 `slug` renames the name: every variant of it moves, each keeps its
135 id, value and `used_by`, and the old slug is a 404 afterwards. A
136 slug that already has objects is a 409, and one that doesn't match
137 the slug pattern is a 400. `description` and `tags` change the one
138 variant `id` names, the same as `PUT`; a name with several
139 variants and no `id` is a 409. The response describes that variant
140 under its (possibly new) slug.
142 The call is recorded in the audit log as an update of the object
143 under its new slug; entries written before a rename keep the name
144 they were written under. A session-authenticated call needs its
145 CSRF token too; a bearer-token-authenticated one doesn't.
147 Args:
148 slug (str): A caller-chosen, unique identifier for an object - what every
149 documented request path (URL, CLI, API) addresses it by. Letters of
150 either case, digits, `_` and `-`, starting with a letter or digit;
151 names are case-sensitive, so `Api_Token` and `api_token` are two
152 secrets. Create and rename follow the same rule. The
153 object's internal id is a separate, opaque value never exposed to
154 or accepted from a caller (specs/secret-objects/spec.md's
155 "Internal id decoupled from user-facing slug" requirement).
156 id (UUID | Unset):
157 consumer (str | Unset):
158 x_caller (str | Unset):
159 x_csrf_token (str | Unset):
160 body (PatchObjectRequest): At least one of `description`, `slug` or `tags` is required; a
161 field
162 left out leaves that aspect of the object unchanged.
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 Response[Error | ObjectMetadata]
170 """
172 kwargs = _get_kwargs(
173 slug=slug,
174 body=body,
175 id=id,
176 consumer=consumer,
177 x_caller=x_caller,
178 x_csrf_token=x_csrf_token,
179 )
181 response = client.get_httpx_client().request(
182 **kwargs,
183 )
185 return _build_response(client=client, response=response)
188def sync(
189 slug: str,
190 *,
191 client: AuthenticatedClient,
192 body: PatchObjectRequest,
193 id: UUID | Unset = UNSET,
194 consumer: str | Unset = UNSET,
195 x_caller: str | Unset = UNSET,
196 x_csrf_token: str | Unset = UNSET,
197) -> Error | ObjectMetadata | None:
198 """Edit an object's description, tags or slug
200 Changes metadata without touching the sealed value, so fixing a
201 typo or reorganising names never needs the plaintext again. Send
202 any of `description`, `tags` and `slug`; a field left out stays as
203 it is, and at least one is required. The change is applied whole
204 or not at all, so a refused rename applies none of the request.
206 `slug` renames the name: every variant of it moves, each keeps its
207 id, value and `used_by`, and the old slug is a 404 afterwards. A
208 slug that already has objects is a 409, and one that doesn't match
209 the slug pattern is a 400. `description` and `tags` change the one
210 variant `id` names, the same as `PUT`; a name with several
211 variants and no `id` is a 409. The response describes that variant
212 under its (possibly new) slug.
214 The call is recorded in the audit log as an update of the object
215 under its new slug; entries written before a rename keep the name
216 they were written under. A session-authenticated call needs its
217 CSRF token too; a bearer-token-authenticated one doesn't.
219 Args:
220 slug (str): A caller-chosen, unique identifier for an object - what every
221 documented request path (URL, CLI, API) addresses it by. Letters of
222 either case, digits, `_` and `-`, starting with a letter or digit;
223 names are case-sensitive, so `Api_Token` and `api_token` are two
224 secrets. Create and rename follow the same rule. The
225 object's internal id is a separate, opaque value never exposed to
226 or accepted from a caller (specs/secret-objects/spec.md's
227 "Internal id decoupled from user-facing slug" requirement).
228 id (UUID | Unset):
229 consumer (str | Unset):
230 x_caller (str | Unset):
231 x_csrf_token (str | Unset):
232 body (PatchObjectRequest): At least one of `description`, `slug` or `tags` is required; a
233 field
234 left out leaves that aspect of the object unchanged.
236 Raises:
237 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
238 httpx.TimeoutException: If the request takes longer than Client.timeout.
240 Returns:
241 Error | ObjectMetadata
242 """
244 return sync_detailed(
245 slug=slug,
246 client=client,
247 body=body,
248 id=id,
249 consumer=consumer,
250 x_caller=x_caller,
251 x_csrf_token=x_csrf_token,
252 ).parsed
255async def asyncio_detailed(
256 slug: str,
257 *,
258 client: AuthenticatedClient,
259 body: PatchObjectRequest,
260 id: UUID | Unset = UNSET,
261 consumer: str | Unset = UNSET,
262 x_caller: str | Unset = UNSET,
263 x_csrf_token: str | Unset = UNSET,
264) -> Response[Error | ObjectMetadata]:
265 """Edit an object's description, tags or slug
267 Changes metadata without touching the sealed value, so fixing a
268 typo or reorganising names never needs the plaintext again. Send
269 any of `description`, `tags` and `slug`; a field left out stays as
270 it is, and at least one is required. The change is applied whole
271 or not at all, so a refused rename applies none of the request.
273 `slug` renames the name: every variant of it moves, each keeps its
274 id, value and `used_by`, and the old slug is a 404 afterwards. A
275 slug that already has objects is a 409, and one that doesn't match
276 the slug pattern is a 400. `description` and `tags` change the one
277 variant `id` names, the same as `PUT`; a name with several
278 variants and no `id` is a 409. The response describes that variant
279 under its (possibly new) slug.
281 The call is recorded in the audit log as an update of the object
282 under its new slug; entries written before a rename keep the name
283 they were written under. A session-authenticated call needs its
284 CSRF token too; a bearer-token-authenticated one doesn't.
286 Args:
287 slug (str): A caller-chosen, unique identifier for an object - what every
288 documented request path (URL, CLI, API) addresses it by. Letters of
289 either case, digits, `_` and `-`, starting with a letter or digit;
290 names are case-sensitive, so `Api_Token` and `api_token` are two
291 secrets. Create and rename follow the same rule. The
292 object's internal id is a separate, opaque value never exposed to
293 or accepted from a caller (specs/secret-objects/spec.md's
294 "Internal id decoupled from user-facing slug" requirement).
295 id (UUID | Unset):
296 consumer (str | Unset):
297 x_caller (str | Unset):
298 x_csrf_token (str | Unset):
299 body (PatchObjectRequest): At least one of `description`, `slug` or `tags` is required; a
300 field
301 left out leaves that aspect of the object unchanged.
303 Raises:
304 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
305 httpx.TimeoutException: If the request takes longer than Client.timeout.
307 Returns:
308 Response[Error | ObjectMetadata]
309 """
311 kwargs = _get_kwargs(
312 slug=slug,
313 body=body,
314 id=id,
315 consumer=consumer,
316 x_caller=x_caller,
317 x_csrf_token=x_csrf_token,
318 )
320 response = await client.get_async_httpx_client().request(**kwargs)
322 return _build_response(client=client, response=response)
325async def asyncio(
326 slug: str,
327 *,
328 client: AuthenticatedClient,
329 body: PatchObjectRequest,
330 id: UUID | Unset = UNSET,
331 consumer: str | Unset = UNSET,
332 x_caller: str | Unset = UNSET,
333 x_csrf_token: str | Unset = UNSET,
334) -> Error | ObjectMetadata | None:
335 """Edit an object's description, tags or slug
337 Changes metadata without touching the sealed value, so fixing a
338 typo or reorganising names never needs the plaintext again. Send
339 any of `description`, `tags` and `slug`; a field left out stays as
340 it is, and at least one is required. The change is applied whole
341 or not at all, so a refused rename applies none of the request.
343 `slug` renames the name: every variant of it moves, each keeps its
344 id, value and `used_by`, and the old slug is a 404 afterwards. A
345 slug that already has objects is a 409, and one that doesn't match
346 the slug pattern is a 400. `description` and `tags` change the one
347 variant `id` names, the same as `PUT`; a name with several
348 variants and no `id` is a 409. The response describes that variant
349 under its (possibly new) slug.
351 The call is recorded in the audit log as an update of the object
352 under its new slug; entries written before a rename keep the name
353 they were written under. A session-authenticated call needs its
354 CSRF token too; a bearer-token-authenticated one doesn't.
356 Args:
357 slug (str): A caller-chosen, unique identifier for an object - what every
358 documented request path (URL, CLI, API) addresses it by. Letters of
359 either case, digits, `_` and `-`, starting with a letter or digit;
360 names are case-sensitive, so `Api_Token` and `api_token` are two
361 secrets. Create and rename follow the same rule. The
362 object's internal id is a separate, opaque value never exposed to
363 or accepted from a caller (specs/secret-objects/spec.md's
364 "Internal id decoupled from user-facing slug" requirement).
365 id (UUID | Unset):
366 consumer (str | Unset):
367 x_caller (str | Unset):
368 x_csrf_token (str | Unset):
369 body (PatchObjectRequest): At least one of `description`, `slug` or `tags` is required; a
370 field
371 left out leaves that aspect of the object unchanged.
373 Raises:
374 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
375 httpx.TimeoutException: If the request takes longer than Client.timeout.
377 Returns:
378 Error | ObjectMetadata
379 """
381 return (
382 await asyncio_detailed(
383 slug=slug,
384 client=client,
385 body=body,
386 id=id,
387 consumer=consumer,
388 x_caller=x_caller,
389 x_csrf_token=x_csrf_token,
390 )
391 ).parsed