Coverage for src/hush_hush/_generated/api/objects/update_object.py: 26%

68 statements  

« 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. 

2 

3from http import HTTPStatus 

4from typing import Any 

5from urllib.parse import quote 

6from uuid import UUID 

7 

8import httpx 

9 

10from ... import errors 

11from ...client import AuthenticatedClient, Client 

12from ...models.error import Error 

13from ...models.object_metadata import ObjectMetadata 

14from ...models.update_object_request import UpdateObjectRequest 

15from ...types import UNSET, Response, Unset 

16 

17 

18def _get_kwargs( 

19 slug: str, 

20 *, 

21 body: UpdateObjectRequest, 

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 

30 

31 if not isinstance(x_csrf_token, Unset): 

32 headers["X-CSRF-Token"] = x_csrf_token 

33 

34 params: dict[str, Any] = {} 

35 

36 json_id: str | Unset = UNSET 

37 if not isinstance(id, Unset): 

38 json_id = str(id) 

39 params["id"] = json_id 

40 

41 params["consumer"] = consumer 

42 

43 params = {k: v for k, v in params.items() if v is not UNSET and v is not None} 

44 

45 _kwargs: dict[str, Any] = { 

46 "method": "put", 

47 "url": "/objects/{slug}".format( 

48 slug=quote(str(slug), safe=""), 

49 ), 

50 "params": params, 

51 } 

52 

53 _kwargs["json"] = body.to_dict() 

54 

55 headers["Content-Type"] = "application/json" 

56 

57 _kwargs["headers"] = headers 

58 return _kwargs 

59 

60 

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()) 

66 

67 return response_200 

68 

69 if response.status_code == 400: 

70 response_400 = Error.from_dict(response.json()) 

71 

72 return response_400 

73 

74 if response.status_code == 401: 

75 response_401 = Error.from_dict(response.json()) 

76 

77 return response_401 

78 

79 if response.status_code == 404: 

80 response_404 = Error.from_dict(response.json()) 

81 

82 return response_404 

83 

84 if response.status_code == 409: 

85 response_409 = Error.from_dict(response.json()) 

86 

87 return response_409 

88 

89 if response.status_code == 413: 

90 response_413 = Error.from_dict(response.json()) 

91 

92 return response_413 

93 

94 if response.status_code == 422: 

95 response_422 = Error.from_dict(response.json()) 

96 

97 return response_422 

98 

99 if client.raise_on_unexpected_status: 

100 raise errors.UnexpectedStatus(response.status_code, response.content) 

101 else: 

102 return None 

103 

104 

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 ) 

114 

115 

116def sync_detailed( 

117 slug: str, 

118 *, 

119 client: AuthenticatedClient, 

120 body: UpdateObjectRequest, 

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 """Rotate an object's value 

127 

128 Replaces the stored ciphertext for an existing object. The new 

129 value is checked the same way a created one is: not base64 of a 

130 well-formed age file, or no recipient in its header, is a 422 

131 and the stored value is left alone. The 

132 object's slug and description metadata are always preserved 

133 unchanged; `PATCH` is what edits them. used_by is preserved too, unless the request body 

134 includes it - in which case it fully replaces the object's 

135 recorded consumers, the same way creating an object sets it. A 

136 session-authenticated call needs its CSRF token too; a 

137 bearer-token-authenticated one doesn't. 

138 

139 Args: 

140 slug (str): A caller-chosen, unique identifier for an object - what every 

141 documented request path (URL, CLI, API) addresses it by. Letters of 

142 either case, digits, `_` and `-`, starting with a letter or digit; 

143 names are case-sensitive, so `Api_Token` and `api_token` are two 

144 secrets. Create and rename follow the same rule. The 

145 object's internal id is a separate, opaque value never exposed to 

146 or accepted from a caller (specs/secret-objects/spec.md's 

147 "Internal id decoupled from user-facing slug" requirement). 

148 id (UUID | Unset): 

149 consumer (str | Unset): 

150 x_caller (str | Unset): 

151 x_csrf_token (str | Unset): 

152 body (UpdateObjectRequest): 

153 

154 Raises: 

155 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. 

156 httpx.TimeoutException: If the request takes longer than Client.timeout. 

157 

158 Returns: 

159 Response[Error | ObjectMetadata] 

160 """ 

161 

162 kwargs = _get_kwargs( 

163 slug=slug, 

164 body=body, 

165 id=id, 

166 consumer=consumer, 

167 x_caller=x_caller, 

168 x_csrf_token=x_csrf_token, 

169 ) 

170 

171 response = client.get_httpx_client().request( 

172 **kwargs, 

173 ) 

174 

175 return _build_response(client=client, response=response) 

176 

177 

178def sync( 

179 slug: str, 

180 *, 

181 client: AuthenticatedClient, 

182 body: UpdateObjectRequest, 

183 id: UUID | Unset = UNSET, 

184 consumer: str | Unset = UNSET, 

185 x_caller: str | Unset = UNSET, 

186 x_csrf_token: str | Unset = UNSET, 

187) -> Error | ObjectMetadata | None: 

188 """Rotate an object's value 

189 

190 Replaces the stored ciphertext for an existing object. The new 

191 value is checked the same way a created one is: not base64 of a 

192 well-formed age file, or no recipient in its header, is a 422 

193 and the stored value is left alone. The 

194 object's slug and description metadata are always preserved 

195 unchanged; `PATCH` is what edits them. used_by is preserved too, unless the request body 

196 includes it - in which case it fully replaces the object's 

197 recorded consumers, the same way creating an object sets it. A 

198 session-authenticated call needs its CSRF token too; a 

199 bearer-token-authenticated one doesn't. 

200 

201 Args: 

202 slug (str): A caller-chosen, unique identifier for an object - what every 

203 documented request path (URL, CLI, API) addresses it by. Letters of 

204 either case, digits, `_` and `-`, starting with a letter or digit; 

205 names are case-sensitive, so `Api_Token` and `api_token` are two 

206 secrets. Create and rename follow the same rule. The 

207 object's internal id is a separate, opaque value never exposed to 

208 or accepted from a caller (specs/secret-objects/spec.md's 

209 "Internal id decoupled from user-facing slug" requirement). 

210 id (UUID | Unset): 

211 consumer (str | Unset): 

212 x_caller (str | Unset): 

213 x_csrf_token (str | Unset): 

214 body (UpdateObjectRequest): 

215 

216 Raises: 

217 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. 

218 httpx.TimeoutException: If the request takes longer than Client.timeout. 

219 

220 Returns: 

221 Error | ObjectMetadata 

222 """ 

223 

224 return sync_detailed( 

225 slug=slug, 

226 client=client, 

227 body=body, 

228 id=id, 

229 consumer=consumer, 

230 x_caller=x_caller, 

231 x_csrf_token=x_csrf_token, 

232 ).parsed 

233 

234 

235async def asyncio_detailed( 

236 slug: str, 

237 *, 

238 client: AuthenticatedClient, 

239 body: UpdateObjectRequest, 

240 id: UUID | Unset = UNSET, 

241 consumer: str | Unset = UNSET, 

242 x_caller: str | Unset = UNSET, 

243 x_csrf_token: str | Unset = UNSET, 

244) -> Response[Error | ObjectMetadata]: 

245 """Rotate an object's value 

246 

247 Replaces the stored ciphertext for an existing object. The new 

248 value is checked the same way a created one is: not base64 of a 

249 well-formed age file, or no recipient in its header, is a 422 

250 and the stored value is left alone. The 

251 object's slug and description metadata are always preserved 

252 unchanged; `PATCH` is what edits them. used_by is preserved too, unless the request body 

253 includes it - in which case it fully replaces the object's 

254 recorded consumers, the same way creating an object sets it. A 

255 session-authenticated call needs its CSRF token too; a 

256 bearer-token-authenticated one doesn't. 

257 

258 Args: 

259 slug (str): A caller-chosen, unique identifier for an object - what every 

260 documented request path (URL, CLI, API) addresses it by. Letters of 

261 either case, digits, `_` and `-`, starting with a letter or digit; 

262 names are case-sensitive, so `Api_Token` and `api_token` are two 

263 secrets. Create and rename follow the same rule. The 

264 object's internal id is a separate, opaque value never exposed to 

265 or accepted from a caller (specs/secret-objects/spec.md's 

266 "Internal id decoupled from user-facing slug" requirement). 

267 id (UUID | Unset): 

268 consumer (str | Unset): 

269 x_caller (str | Unset): 

270 x_csrf_token (str | Unset): 

271 body (UpdateObjectRequest): 

272 

273 Raises: 

274 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. 

275 httpx.TimeoutException: If the request takes longer than Client.timeout. 

276 

277 Returns: 

278 Response[Error | ObjectMetadata] 

279 """ 

280 

281 kwargs = _get_kwargs( 

282 slug=slug, 

283 body=body, 

284 id=id, 

285 consumer=consumer, 

286 x_caller=x_caller, 

287 x_csrf_token=x_csrf_token, 

288 ) 

289 

290 response = await client.get_async_httpx_client().request(**kwargs) 

291 

292 return _build_response(client=client, response=response) 

293 

294 

295async def asyncio( 

296 slug: str, 

297 *, 

298 client: AuthenticatedClient, 

299 body: UpdateObjectRequest, 

300 id: UUID | Unset = UNSET, 

301 consumer: str | Unset = UNSET, 

302 x_caller: str | Unset = UNSET, 

303 x_csrf_token: str | Unset = UNSET, 

304) -> Error | ObjectMetadata | None: 

305 """Rotate an object's value 

306 

307 Replaces the stored ciphertext for an existing object. The new 

308 value is checked the same way a created one is: not base64 of a 

309 well-formed age file, or no recipient in its header, is a 422 

310 and the stored value is left alone. The 

311 object's slug and description metadata are always preserved 

312 unchanged; `PATCH` is what edits them. used_by is preserved too, unless the request body 

313 includes it - in which case it fully replaces the object's 

314 recorded consumers, the same way creating an object sets it. A 

315 session-authenticated call needs its CSRF token too; a 

316 bearer-token-authenticated one doesn't. 

317 

318 Args: 

319 slug (str): A caller-chosen, unique identifier for an object - what every 

320 documented request path (URL, CLI, API) addresses it by. Letters of 

321 either case, digits, `_` and `-`, starting with a letter or digit; 

322 names are case-sensitive, so `Api_Token` and `api_token` are two 

323 secrets. Create and rename follow the same rule. The 

324 object's internal id is a separate, opaque value never exposed to 

325 or accepted from a caller (specs/secret-objects/spec.md's 

326 "Internal id decoupled from user-facing slug" requirement). 

327 id (UUID | Unset): 

328 consumer (str | Unset): 

329 x_caller (str | Unset): 

330 x_csrf_token (str | Unset): 

331 body (UpdateObjectRequest): 

332 

333 Raises: 

334 errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. 

335 httpx.TimeoutException: If the request takes longer than Client.timeout. 

336 

337 Returns: 

338 Error | ObjectMetadata 

339 """ 

340 

341 return ( 

342 await asyncio_detailed( 

343 slug=slug, 

344 client=client, 

345 body=body, 

346 id=id, 

347 consumer=consumer, 

348 x_caller=x_caller, 

349 x_csrf_token=x_csrf_token, 

350 ) 

351 ).parsed