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

50 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_token_request import CreateTokenRequest 

11from ...models.error import Error 

12from ...models.token_with_value import TokenWithValue 

13from ...types import Response 

14 

15 

16def _get_kwargs( 

17 *, 

18 body: CreateTokenRequest, 

19 x_csrf_token: str, 

20) -> dict[str, Any]: 

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

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

23 

24 _kwargs: dict[str, Any] = { 

25 "method": "post", 

26 "url": "/tokens", 

27 } 

28 

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

30 

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

32 

33 _kwargs["headers"] = headers 

34 return _kwargs 

35 

36 

37def _parse_response( 

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

39) -> Error | TokenWithValue | None: 

40 if response.status_code == 201: 

41 response_201 = TokenWithValue.from_dict(response.json()) 

42 

43 return response_201 

44 

45 if response.status_code == 400: 

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

47 

48 return response_400 

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 == 413: 

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

57 

58 return response_413 

59 

60 if response.status_code == 422: 

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

62 

63 return response_422 

64 

65 if client.raise_on_unexpected_status: 

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

67 else: 

68 return None 

69 

70 

71def _build_response( 

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

73) -> Response[Error | TokenWithValue]: 

74 return Response( 

75 status_code=HTTPStatus(response.status_code), 

76 content=response.content, 

77 headers=response.headers, 

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

79 ) 

80 

81 

82def sync_detailed( 

83 *, 

84 client: AuthenticatedClient, 

85 body: CreateTokenRequest, 

86 x_csrf_token: str, 

87) -> Response[Error | TokenWithValue]: 

88 """Create a write bearer token 

89 

90 Issues a new write-path bearer token, owned by the admin account 

91 that created it. The raw token value is returned here only - it 

92 is never recoverable again once this response is read, the same 

93 as a token issued via the `token` CLI command. 

94 

95 Args: 

96 x_csrf_token (str): 

97 body (CreateTokenRequest): 

98 

99 Raises: 

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

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

102 

103 Returns: 

104 Response[Error | TokenWithValue] 

105 """ 

106 

107 kwargs = _get_kwargs( 

108 body=body, 

109 x_csrf_token=x_csrf_token, 

110 ) 

111 

112 response = client.get_httpx_client().request( 

113 **kwargs, 

114 ) 

115 

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

117 

118 

119def sync( 

120 *, 

121 client: AuthenticatedClient, 

122 body: CreateTokenRequest, 

123 x_csrf_token: str, 

124) -> Error | TokenWithValue | None: 

125 """Create a write bearer token 

126 

127 Issues a new write-path bearer token, owned by the admin account 

128 that created it. The raw token value is returned here only - it 

129 is never recoverable again once this response is read, the same 

130 as a token issued via the `token` CLI command. 

131 

132 Args: 

133 x_csrf_token (str): 

134 body (CreateTokenRequest): 

135 

136 Raises: 

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

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

139 

140 Returns: 

141 Error | TokenWithValue 

142 """ 

143 

144 return sync_detailed( 

145 client=client, 

146 body=body, 

147 x_csrf_token=x_csrf_token, 

148 ).parsed 

149 

150 

151async def asyncio_detailed( 

152 *, 

153 client: AuthenticatedClient, 

154 body: CreateTokenRequest, 

155 x_csrf_token: str, 

156) -> Response[Error | TokenWithValue]: 

157 """Create a write bearer token 

158 

159 Issues a new write-path bearer token, owned by the admin account 

160 that created it. The raw token value is returned here only - it 

161 is never recoverable again once this response is read, the same 

162 as a token issued via the `token` CLI command. 

163 

164 Args: 

165 x_csrf_token (str): 

166 body (CreateTokenRequest): 

167 

168 Raises: 

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

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

171 

172 Returns: 

173 Response[Error | TokenWithValue] 

174 """ 

175 

176 kwargs = _get_kwargs( 

177 body=body, 

178 x_csrf_token=x_csrf_token, 

179 ) 

180 

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

182 

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

184 

185 

186async def asyncio( 

187 *, 

188 client: AuthenticatedClient, 

189 body: CreateTokenRequest, 

190 x_csrf_token: str, 

191) -> Error | TokenWithValue | None: 

192 """Create a write bearer token 

193 

194 Issues a new write-path bearer token, owned by the admin account 

195 that created it. The raw token value is returned here only - it 

196 is never recoverable again once this response is read, the same 

197 as a token issued via the `token` CLI command. 

198 

199 Args: 

200 x_csrf_token (str): 

201 body (CreateTokenRequest): 

202 

203 Raises: 

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

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

206 

207 Returns: 

208 Error | TokenWithValue 

209 """ 

210 

211 return ( 

212 await asyncio_detailed( 

213 client=client, 

214 body=body, 

215 x_csrf_token=x_csrf_token, 

216 ) 

217 ).parsed