Coverage for src/hush_hush/_generated/api/objects/create_object.py: 58%

53 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 

5 

6import httpx 

7 

8from ... import errors 

9from ...client import AuthenticatedClient, Client 

10from ...models.create_object_request import CreateObjectRequest 

11from ...models.error import Error 

12from ...models.object_metadata import ObjectMetadata 

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

14 

15 

16def _get_kwargs( 

17 *, 

18 body: CreateObjectRequest, 

19 x_caller: str | Unset = UNSET, 

20 x_csrf_token: str | Unset = UNSET, 

21) -> dict[str, Any]: 

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

23 if not isinstance(x_caller, Unset): 

24 headers["X-Caller"] = x_caller 

25 

26 if not isinstance(x_csrf_token, Unset): 

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

28 

29 _kwargs: dict[str, Any] = { 

30 "method": "post", 

31 "url": "/objects", 

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) -> Error | ObjectMetadata | None: 

45 if response.status_code == 201: 

46 response_201 = ObjectMetadata.from_dict(response.json()) 

47 

48 return response_201 

49 

50 if response.status_code == 401: 

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

52 

53 return response_401 

54 

55 if response.status_code == 409: 

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

57 

58 return response_409 

59 

60 if response.status_code == 413: 

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

62 

63 return response_413 

64 

65 if response.status_code == 422: 

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

67 

68 return response_422 

69 

70 if client.raise_on_unexpected_status: 

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

72 else: 

73 return None 

74 

75 

76def _build_response( 

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

78) -> Response[Error | ObjectMetadata]: 

79 return Response( 

80 status_code=HTTPStatus(response.status_code), 

81 content=response.content, 

82 headers=response.headers, 

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

84 ) 

85 

86 

87def sync_detailed( 

88 *, 

89 client: AuthenticatedClient, 

90 body: CreateObjectRequest, 

91 x_caller: str | Unset = UNSET, 

92 x_csrf_token: str | Unset = UNSET, 

93) -> Response[Error | ObjectMetadata]: 

94 """Create a new sealed object 

95 

96 Stores an already-sealed value under a new, caller-chosen slug - 

97 the object's own internal id is generated server-side and never 

98 returned as something addressable. The service never decrypts the 

99 value, and it can't know how many recipients it was sealed to or 

100 whether any key is right. It does read the age header: a value 

101 that isn't base64 of a well-formed age file, or whose header 

102 names no recipient, is a 422 and nothing is stored. A session- 

103 authenticated call needs its CSRF token too; a bearer-token- 

104 authenticated one doesn't, since there's no session to have one. 

105 

106 Args: 

107 x_caller (str | Unset): 

108 x_csrf_token (str | Unset): 

109 body (CreateObjectRequest): 

110 

111 Raises: 

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

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

114 

115 Returns: 

116 Response[Error | ObjectMetadata] 

117 """ 

118 

119 kwargs = _get_kwargs( 

120 body=body, 

121 x_caller=x_caller, 

122 x_csrf_token=x_csrf_token, 

123 ) 

124 

125 response = client.get_httpx_client().request( 

126 **kwargs, 

127 ) 

128 

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

130 

131 

132def sync( 

133 *, 

134 client: AuthenticatedClient, 

135 body: CreateObjectRequest, 

136 x_caller: str | Unset = UNSET, 

137 x_csrf_token: str | Unset = UNSET, 

138) -> Error | ObjectMetadata | None: 

139 """Create a new sealed object 

140 

141 Stores an already-sealed value under a new, caller-chosen slug - 

142 the object's own internal id is generated server-side and never 

143 returned as something addressable. The service never decrypts the 

144 value, and it can't know how many recipients it was sealed to or 

145 whether any key is right. It does read the age header: a value 

146 that isn't base64 of a well-formed age file, or whose header 

147 names no recipient, is a 422 and nothing is stored. A session- 

148 authenticated call needs its CSRF token too; a bearer-token- 

149 authenticated one doesn't, since there's no session to have one. 

150 

151 Args: 

152 x_caller (str | Unset): 

153 x_csrf_token (str | Unset): 

154 body (CreateObjectRequest): 

155 

156 Raises: 

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

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

159 

160 Returns: 

161 Error | ObjectMetadata 

162 """ 

163 

164 return sync_detailed( 

165 client=client, 

166 body=body, 

167 x_caller=x_caller, 

168 x_csrf_token=x_csrf_token, 

169 ).parsed 

170 

171 

172async def asyncio_detailed( 

173 *, 

174 client: AuthenticatedClient, 

175 body: CreateObjectRequest, 

176 x_caller: str | Unset = UNSET, 

177 x_csrf_token: str | Unset = UNSET, 

178) -> Response[Error | ObjectMetadata]: 

179 """Create a new sealed object 

180 

181 Stores an already-sealed value under a new, caller-chosen slug - 

182 the object's own internal id is generated server-side and never 

183 returned as something addressable. The service never decrypts the 

184 value, and it can't know how many recipients it was sealed to or 

185 whether any key is right. It does read the age header: a value 

186 that isn't base64 of a well-formed age file, or whose header 

187 names no recipient, is a 422 and nothing is stored. A session- 

188 authenticated call needs its CSRF token too; a bearer-token- 

189 authenticated one doesn't, since there's no session to have one. 

190 

191 Args: 

192 x_caller (str | Unset): 

193 x_csrf_token (str | Unset): 

194 body (CreateObjectRequest): 

195 

196 Raises: 

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

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

199 

200 Returns: 

201 Response[Error | ObjectMetadata] 

202 """ 

203 

204 kwargs = _get_kwargs( 

205 body=body, 

206 x_caller=x_caller, 

207 x_csrf_token=x_csrf_token, 

208 ) 

209 

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

211 

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

213 

214 

215async def asyncio( 

216 *, 

217 client: AuthenticatedClient, 

218 body: CreateObjectRequest, 

219 x_caller: str | Unset = UNSET, 

220 x_csrf_token: str | Unset = UNSET, 

221) -> Error | ObjectMetadata | None: 

222 """Create a new sealed object 

223 

224 Stores an already-sealed value under a new, caller-chosen slug - 

225 the object's own internal id is generated server-side and never 

226 returned as something addressable. The service never decrypts the 

227 value, and it can't know how many recipients it was sealed to or 

228 whether any key is right. It does read the age header: a value 

229 that isn't base64 of a well-formed age file, or whose header 

230 names no recipient, is a 422 and nothing is stored. A session- 

231 authenticated call needs its CSRF token too; a bearer-token- 

232 authenticated one doesn't, since there's no session to have one. 

233 

234 Args: 

235 x_caller (str | Unset): 

236 x_csrf_token (str | Unset): 

237 body (CreateObjectRequest): 

238 

239 Raises: 

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

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

242 

243 Returns: 

244 Error | ObjectMetadata 

245 """ 

246 

247 return ( 

248 await asyncio_detailed( 

249 client=client, 

250 body=body, 

251 x_caller=x_caller, 

252 x_csrf_token=x_csrf_token, 

253 ) 

254 ).parsed