Coverage for src/hush_hush/_generated/api/tokens/rotate_consumer_token.py: 0%

55 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_token_with_value import ConsumerTokenWithValue 

12from ...models.error import Error 

13from ...models.rotate_consumer_token_request import RotateConsumerTokenRequest 

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

15 

16 

17def _get_kwargs( 

18 id: str, 

19 *, 

20 body: RotateConsumerTokenRequest, 

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": "post", 

29 "url": "/consumer-tokens/{id}/rotate".format( 

30 id=quote(str(id), 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) -> ConsumerTokenWithValue | Error | None: 

45 if response.status_code == 200: 

46 response_200 = ConsumerTokenWithValue.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 == 413: 

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

67 

68 return response_413 

69 

70 if response.status_code == 422: 

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

72 

73 return response_422 

74 

75 if client.raise_on_unexpected_status: 

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

77 else: 

78 return None 

79 

80 

81def _build_response( 

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

83) -> Response[ConsumerTokenWithValue | Error]: 

84 return Response( 

85 status_code=HTTPStatus(response.status_code), 

86 content=response.content, 

87 headers=response.headers, 

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

89 ) 

90 

91 

92def sync_detailed( 

93 id: str, 

94 *, 

95 client: AuthenticatedClient, 

96 body: RotateConsumerTokenRequest, 

97 x_csrf_token: str | Unset = UNSET, 

98) -> Response[ConsumerTokenWithValue | Error]: 

99 """Rotate a consumer read token 

100 

101 Replaces the secret and expiry of the consumer token issued under 

102 id, keeping its id, consumer, and description unchanged. The old 

103 secret stops authenticating immediately. The new raw token value 

104 is returned here only, the same as `createConsumerToken`. 

105 

106 Unlike `revokeConsumerToken`, an id that's unknown, already 

107 revoked, or already expired is an error: a rotate response 

108 promises the caller a working new secret, and there's no valid 

109 token to hand one to. A write bearer token may rotate one too, 

110 the same as it may create one (alrayyes/hush-hush#467). 

111 

112 Args: 

113 id (str): 

114 x_csrf_token (str | Unset): 

115 body (RotateConsumerTokenRequest): 

116 

117 Raises: 

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

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

120 

121 Returns: 

122 Response[ConsumerTokenWithValue | Error] 

123 """ 

124 

125 kwargs = _get_kwargs( 

126 id=id, 

127 body=body, 

128 x_csrf_token=x_csrf_token, 

129 ) 

130 

131 response = client.get_httpx_client().request( 

132 **kwargs, 

133 ) 

134 

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

136 

137 

138def sync( 

139 id: str, 

140 *, 

141 client: AuthenticatedClient, 

142 body: RotateConsumerTokenRequest, 

143 x_csrf_token: str | Unset = UNSET, 

144) -> ConsumerTokenWithValue | Error | None: 

145 """Rotate a consumer read token 

146 

147 Replaces the secret and expiry of the consumer token issued under 

148 id, keeping its id, consumer, and description unchanged. The old 

149 secret stops authenticating immediately. The new raw token value 

150 is returned here only, the same as `createConsumerToken`. 

151 

152 Unlike `revokeConsumerToken`, an id that's unknown, already 

153 revoked, or already expired is an error: a rotate response 

154 promises the caller a working new secret, and there's no valid 

155 token to hand one to. A write bearer token may rotate one too, 

156 the same as it may create one (alrayyes/hush-hush#467). 

157 

158 Args: 

159 id (str): 

160 x_csrf_token (str | Unset): 

161 body (RotateConsumerTokenRequest): 

162 

163 Raises: 

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

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

166 

167 Returns: 

168 ConsumerTokenWithValue | Error 

169 """ 

170 

171 return sync_detailed( 

172 id=id, 

173 client=client, 

174 body=body, 

175 x_csrf_token=x_csrf_token, 

176 ).parsed 

177 

178 

179async def asyncio_detailed( 

180 id: str, 

181 *, 

182 client: AuthenticatedClient, 

183 body: RotateConsumerTokenRequest, 

184 x_csrf_token: str | Unset = UNSET, 

185) -> Response[ConsumerTokenWithValue | Error]: 

186 """Rotate a consumer read token 

187 

188 Replaces the secret and expiry of the consumer token issued under 

189 id, keeping its id, consumer, and description unchanged. The old 

190 secret stops authenticating immediately. The new raw token value 

191 is returned here only, the same as `createConsumerToken`. 

192 

193 Unlike `revokeConsumerToken`, an id that's unknown, already 

194 revoked, or already expired is an error: a rotate response 

195 promises the caller a working new secret, and there's no valid 

196 token to hand one to. A write bearer token may rotate one too, 

197 the same as it may create one (alrayyes/hush-hush#467). 

198 

199 Args: 

200 id (str): 

201 x_csrf_token (str | Unset): 

202 body (RotateConsumerTokenRequest): 

203 

204 Raises: 

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

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

207 

208 Returns: 

209 Response[ConsumerTokenWithValue | Error] 

210 """ 

211 

212 kwargs = _get_kwargs( 

213 id=id, 

214 body=body, 

215 x_csrf_token=x_csrf_token, 

216 ) 

217 

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

219 

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

221 

222 

223async def asyncio( 

224 id: str, 

225 *, 

226 client: AuthenticatedClient, 

227 body: RotateConsumerTokenRequest, 

228 x_csrf_token: str | Unset = UNSET, 

229) -> ConsumerTokenWithValue | Error | None: 

230 """Rotate a consumer read token 

231 

232 Replaces the secret and expiry of the consumer token issued under 

233 id, keeping its id, consumer, and description unchanged. The old 

234 secret stops authenticating immediately. The new raw token value 

235 is returned here only, the same as `createConsumerToken`. 

236 

237 Unlike `revokeConsumerToken`, an id that's unknown, already 

238 revoked, or already expired is an error: a rotate response 

239 promises the caller a working new secret, and there's no valid 

240 token to hand one to. A write bearer token may rotate one too, 

241 the same as it may create one (alrayyes/hush-hush#467). 

242 

243 Args: 

244 id (str): 

245 x_csrf_token (str | Unset): 

246 body (RotateConsumerTokenRequest): 

247 

248 Raises: 

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

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

251 

252 Returns: 

253 ConsumerTokenWithValue | Error 

254 """ 

255 

256 return ( 

257 await asyncio_detailed( 

258 id=id, 

259 client=client, 

260 body=body, 

261 x_csrf_token=x_csrf_token, 

262 ) 

263 ).parsed