Coverage for src/hush_hush/_generated/api/consumers/update_consumer.py: 0%

58 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 

6 

7import httpx 

8 

9from ... import errors 

10from ...client import AuthenticatedClient, Client 

11from ...models.consumer_entry import ConsumerEntry 

12from ...models.error import Error 

13from ...models.update_consumer_request import UpdateConsumerRequest 

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

15 

16 

17def _get_kwargs( 

18 name: str, 

19 *, 

20 body: UpdateConsumerRequest, 

21 x_csrf_token: str | Unset = UNSET, 

22) -> dict[str, Any]: 

23 headers: dict[str, Any] = {} 

24 if not isinstance(x_csrf_token, Unset): 

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

26 

27 _kwargs: dict[str, Any] = { 

28 "method": "patch", 

29 "url": "/consumers/{name}".format( 

30 name=quote(str(name), safe=""), 

31 ), 

32 } 

33 

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

35 

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

37 

38 _kwargs["headers"] = headers 

39 return _kwargs 

40 

41 

42def _parse_response( 

43 *, client: AuthenticatedClient | Client, response: httpx.Response 

44) -> ConsumerEntry | Error | None: 

45 if response.status_code == 200: 

46 response_200 = ConsumerEntry.from_dict(response.json()) 

47 

48 return response_200 

49 

50 if response.status_code == 400: 

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

52 

53 return response_400 

54 

55 if response.status_code == 401: 

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

57 

58 return response_401 

59 

60 if response.status_code == 404: 

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

62 

63 return response_404 

64 

65 if response.status_code == 409: 

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

67 

68 return response_409 

69 

70 if response.status_code == 413: 

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

72 

73 return response_413 

74 

75 if response.status_code == 422: 

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

77 

78 return response_422 

79 

80 if client.raise_on_unexpected_status: 

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

82 else: 

83 return None 

84 

85 

86def _build_response( 

87 *, client: AuthenticatedClient | Client, response: httpx.Response 

88) -> Response[ConsumerEntry | Error]: 

89 return Response( 

90 status_code=HTTPStatus(response.status_code), 

91 content=response.content, 

92 headers=response.headers, 

93 parsed=_parse_response(client=client, response=response), 

94 ) 

95 

96 

97def sync_detailed( 

98 name: str, 

99 *, 

100 client: AuthenticatedClient, 

101 body: UpdateConsumerRequest, 

102 x_csrf_token: str | Unset = UNSET, 

103) -> Response[ConsumerEntry | Error]: 

104 """Rename a consumer and/or register its public key 

105 

106 Consumers aren't a stored resource of their own (`alrayyes/hush-hush#282`, 

107 following ADR 0002's deferred consumer-identity decision) - a 

108 `name` in the request body replaces `name` in every stored 

109 object's `used_by` list that currently records it, the same as 

110 before this endpoint also took `public_key`. An object already 

111 recording the target name keeps a single entry, not a duplicate. 

112 If the target name already has its own recorded objects, they 

113 merge under it: the response's `secret_count` reflects every 

114 object now recording the new name, old and already-there 

115 combined. Renaming an unknown name is rejected with a 404. 

116 

117 A `public_key` in the request body registers or replaces that age 

118 public key on the (possibly just-renamed) consumer, upserting a 

119 directory entry for it even if it had none before - unlike a bare 

120 rename, this never 404s on an unrecognized name. It must be a valid 

121 age X25519 recipient (`age1...`); anything else, a private key 

122 included, is a 400 and nothing in the request is applied. Sending both 

123 fields in the same call renames first, then sets the key on the 

124 resulting name, in one step: if the key can't be written, the rename 

125 isn't applied either. 

126 

127 A rename also moves the consumer's read tokens to the new name, so 

128 they keep reading the same secrets; when it merges into an existing 

129 consumer, tokens of both names read as the merged name. 

130 

131 A session-authenticated call needs its CSRF token too; a 

132 bearer-token-authenticated one doesn't. 

133 

134 Args: 

135 name (str): 

136 x_csrf_token (str | Unset): 

137 body (UpdateConsumerRequest): At least one of `name` or `public_key` is required (enforced 

138 by 

139 `minProperties` above); a field left out leaves that aspect of the 

140 consumer unchanged. There is no way to clear a registered public 

141 key through this request, only to set or replace one. 

142 

143 Raises: 

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

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

146 

147 Returns: 

148 Response[ConsumerEntry | Error] 

149 """ 

150 

151 kwargs = _get_kwargs( 

152 name=name, 

153 body=body, 

154 x_csrf_token=x_csrf_token, 

155 ) 

156 

157 response = client.get_httpx_client().request( 

158 **kwargs, 

159 ) 

160 

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

162 

163 

164def sync( 

165 name: str, 

166 *, 

167 client: AuthenticatedClient, 

168 body: UpdateConsumerRequest, 

169 x_csrf_token: str | Unset = UNSET, 

170) -> ConsumerEntry | Error | None: 

171 """Rename a consumer and/or register its public key 

172 

173 Consumers aren't a stored resource of their own (`alrayyes/hush-hush#282`, 

174 following ADR 0002's deferred consumer-identity decision) - a 

175 `name` in the request body replaces `name` in every stored 

176 object's `used_by` list that currently records it, the same as 

177 before this endpoint also took `public_key`. An object already 

178 recording the target name keeps a single entry, not a duplicate. 

179 If the target name already has its own recorded objects, they 

180 merge under it: the response's `secret_count` reflects every 

181 object now recording the new name, old and already-there 

182 combined. Renaming an unknown name is rejected with a 404. 

183 

184 A `public_key` in the request body registers or replaces that age 

185 public key on the (possibly just-renamed) consumer, upserting a 

186 directory entry for it even if it had none before - unlike a bare 

187 rename, this never 404s on an unrecognized name. It must be a valid 

188 age X25519 recipient (`age1...`); anything else, a private key 

189 included, is a 400 and nothing in the request is applied. Sending both 

190 fields in the same call renames first, then sets the key on the 

191 resulting name, in one step: if the key can't be written, the rename 

192 isn't applied either. 

193 

194 A rename also moves the consumer's read tokens to the new name, so 

195 they keep reading the same secrets; when it merges into an existing 

196 consumer, tokens of both names read as the merged name. 

197 

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

199 bearer-token-authenticated one doesn't. 

200 

201 Args: 

202 name (str): 

203 x_csrf_token (str | Unset): 

204 body (UpdateConsumerRequest): At least one of `name` or `public_key` is required (enforced 

205 by 

206 `minProperties` above); a field left out leaves that aspect of the 

207 consumer unchanged. There is no way to clear a registered public 

208 key through this request, only to set or replace one. 

209 

210 Raises: 

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

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

213 

214 Returns: 

215 ConsumerEntry | Error 

216 """ 

217 

218 return sync_detailed( 

219 name=name, 

220 client=client, 

221 body=body, 

222 x_csrf_token=x_csrf_token, 

223 ).parsed 

224 

225 

226async def asyncio_detailed( 

227 name: str, 

228 *, 

229 client: AuthenticatedClient, 

230 body: UpdateConsumerRequest, 

231 x_csrf_token: str | Unset = UNSET, 

232) -> Response[ConsumerEntry | Error]: 

233 """Rename a consumer and/or register its public key 

234 

235 Consumers aren't a stored resource of their own (`alrayyes/hush-hush#282`, 

236 following ADR 0002's deferred consumer-identity decision) - a 

237 `name` in the request body replaces `name` in every stored 

238 object's `used_by` list that currently records it, the same as 

239 before this endpoint also took `public_key`. An object already 

240 recording the target name keeps a single entry, not a duplicate. 

241 If the target name already has its own recorded objects, they 

242 merge under it: the response's `secret_count` reflects every 

243 object now recording the new name, old and already-there 

244 combined. Renaming an unknown name is rejected with a 404. 

245 

246 A `public_key` in the request body registers or replaces that age 

247 public key on the (possibly just-renamed) consumer, upserting a 

248 directory entry for it even if it had none before - unlike a bare 

249 rename, this never 404s on an unrecognized name. It must be a valid 

250 age X25519 recipient (`age1...`); anything else, a private key 

251 included, is a 400 and nothing in the request is applied. Sending both 

252 fields in the same call renames first, then sets the key on the 

253 resulting name, in one step: if the key can't be written, the rename 

254 isn't applied either. 

255 

256 A rename also moves the consumer's read tokens to the new name, so 

257 they keep reading the same secrets; when it merges into an existing 

258 consumer, tokens of both names read as the merged name. 

259 

260 A session-authenticated call needs its CSRF token too; a 

261 bearer-token-authenticated one doesn't. 

262 

263 Args: 

264 name (str): 

265 x_csrf_token (str | Unset): 

266 body (UpdateConsumerRequest): At least one of `name` or `public_key` is required (enforced 

267 by 

268 `minProperties` above); a field left out leaves that aspect of the 

269 consumer unchanged. There is no way to clear a registered public 

270 key through this request, only to set or replace one. 

271 

272 Raises: 

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

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

275 

276 Returns: 

277 Response[ConsumerEntry | Error] 

278 """ 

279 

280 kwargs = _get_kwargs( 

281 name=name, 

282 body=body, 

283 x_csrf_token=x_csrf_token, 

284 ) 

285 

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

287 

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

289 

290 

291async def asyncio( 

292 name: str, 

293 *, 

294 client: AuthenticatedClient, 

295 body: UpdateConsumerRequest, 

296 x_csrf_token: str | Unset = UNSET, 

297) -> ConsumerEntry | Error | None: 

298 """Rename a consumer and/or register its public key 

299 

300 Consumers aren't a stored resource of their own (`alrayyes/hush-hush#282`, 

301 following ADR 0002's deferred consumer-identity decision) - a 

302 `name` in the request body replaces `name` in every stored 

303 object's `used_by` list that currently records it, the same as 

304 before this endpoint also took `public_key`. An object already 

305 recording the target name keeps a single entry, not a duplicate. 

306 If the target name already has its own recorded objects, they 

307 merge under it: the response's `secret_count` reflects every 

308 object now recording the new name, old and already-there 

309 combined. Renaming an unknown name is rejected with a 404. 

310 

311 A `public_key` in the request body registers or replaces that age 

312 public key on the (possibly just-renamed) consumer, upserting a 

313 directory entry for it even if it had none before - unlike a bare 

314 rename, this never 404s on an unrecognized name. It must be a valid 

315 age X25519 recipient (`age1...`); anything else, a private key 

316 included, is a 400 and nothing in the request is applied. Sending both 

317 fields in the same call renames first, then sets the key on the 

318 resulting name, in one step: if the key can't be written, the rename 

319 isn't applied either. 

320 

321 A rename also moves the consumer's read tokens to the new name, so 

322 they keep reading the same secrets; when it merges into an existing 

323 consumer, tokens of both names read as the merged name. 

324 

325 A session-authenticated call needs its CSRF token too; a 

326 bearer-token-authenticated one doesn't. 

327 

328 Args: 

329 name (str): 

330 x_csrf_token (str | Unset): 

331 body (UpdateConsumerRequest): At least one of `name` or `public_key` is required (enforced 

332 by 

333 `minProperties` above); a field left out leaves that aspect of the 

334 consumer unchanged. There is no way to clear a registered public 

335 key through this request, only to set or replace one. 

336 

337 Raises: 

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

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

340 

341 Returns: 

342 ConsumerEntry | Error 

343 """ 

344 

345 return ( 

346 await asyncio_detailed( 

347 name=name, 

348 client=client, 

349 body=body, 

350 x_csrf_token=x_csrf_token, 

351 ) 

352 ).parsed