latitudesh-python-sdk 0.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of latitudesh-python-sdk might be problematic. Click here for more details.

Files changed (206) hide show
  1. latitudesh_python_sdk/__init__.py +18 -0
  2. latitudesh_python_sdk/_hooks/__init__.py +5 -0
  3. latitudesh_python_sdk/_hooks/registration.py +13 -0
  4. latitudesh_python_sdk/_hooks/sdkhooks.py +76 -0
  5. latitudesh_python_sdk/_hooks/types.py +106 -0
  6. latitudesh_python_sdk/_version.py +15 -0
  7. latitudesh_python_sdk/apikeys.py +802 -0
  8. latitudesh_python_sdk/basesdk.py +366 -0
  9. latitudesh_python_sdk/billing.py +210 -0
  10. latitudesh_python_sdk/events_sdk.py +240 -0
  11. latitudesh_python_sdk/firewalls_sdk.py +1640 -0
  12. latitudesh_python_sdk/httpclient.py +136 -0
  13. latitudesh_python_sdk/ipaddresses_sdk.py +448 -0
  14. latitudesh_python_sdk/models/__init__.py +1927 -0
  15. latitudesh_python_sdk/models/api_key.py +81 -0
  16. latitudesh_python_sdk/models/apierror.py +22 -0
  17. latitudesh_python_sdk/models/assign_server_virtual_networkop.py +43 -0
  18. latitudesh_python_sdk/models/bandwidth_packages.py +67 -0
  19. latitudesh_python_sdk/models/bandwidth_plan.py +72 -0
  20. latitudesh_python_sdk/models/bandwidth_plans.py +15 -0
  21. latitudesh_python_sdk/models/billing_usage.py +158 -0
  22. latitudesh_python_sdk/models/create_api_key.py +40 -0
  23. latitudesh_python_sdk/models/create_firewall_assignmentop.py +61 -0
  24. latitudesh_python_sdk/models/create_firewallop.py +69 -0
  25. latitudesh_python_sdk/models/create_ipmi_sessionop.py +16 -0
  26. latitudesh_python_sdk/models/create_projectop.py +79 -0
  27. latitudesh_python_sdk/models/create_server_actionop.py +69 -0
  28. latitudesh_python_sdk/models/create_server_out_of_bandop.py +61 -0
  29. latitudesh_python_sdk/models/create_server_reinstallop.py +140 -0
  30. latitudesh_python_sdk/models/create_serverop.py +173 -0
  31. latitudesh_python_sdk/models/create_tagop.py +50 -0
  32. latitudesh_python_sdk/models/create_virtual_networkop.py +72 -0
  33. latitudesh_python_sdk/models/custom_tag.py +54 -0
  34. latitudesh_python_sdk/models/delete_api_keyop.py +16 -0
  35. latitudesh_python_sdk/models/delete_firewall_assignmentop.py +25 -0
  36. latitudesh_python_sdk/models/delete_firewallop.py +18 -0
  37. latitudesh_python_sdk/models/delete_project_ssh_keyop.py +23 -0
  38. latitudesh_python_sdk/models/delete_project_user_dataop.py +23 -0
  39. latitudesh_python_sdk/models/delete_projectop.py +18 -0
  40. latitudesh_python_sdk/models/delete_storage_filesystemsop.py +16 -0
  41. latitudesh_python_sdk/models/delete_virtual_networks_assignmentsop.py +16 -0
  42. latitudesh_python_sdk/models/delete_vpn_sessionop.py +16 -0
  43. latitudesh_python_sdk/models/deploy_config.py +74 -0
  44. latitudesh_python_sdk/models/destroy_serverop.py +31 -0
  45. latitudesh_python_sdk/models/destroy_tagop.py +16 -0
  46. latitudesh_python_sdk/models/destroy_team_memberop.py +18 -0
  47. latitudesh_python_sdk/models/destroy_virtual_machineop.py +16 -0
  48. latitudesh_python_sdk/models/destroy_virtual_networkop.py +18 -0
  49. latitudesh_python_sdk/models/error_object.py +49 -0
  50. latitudesh_python_sdk/models/events.py +90 -0
  51. latitudesh_python_sdk/models/filesystem_data.py +53 -0
  52. latitudesh_python_sdk/models/firewall.py +71 -0
  53. latitudesh_python_sdk/models/firewall_server.py +50 -0
  54. latitudesh_python_sdk/models/firewalls.py +26 -0
  55. latitudesh_python_sdk/models/get_bandwidth_plansop.py +33 -0
  56. latitudesh_python_sdk/models/get_billing_usageop.py +46 -0
  57. latitudesh_python_sdk/models/get_eventsop.py +98 -0
  58. latitudesh_python_sdk/models/get_firewall_assignmentsop.py +18 -0
  59. latitudesh_python_sdk/models/get_firewallop.py +18 -0
  60. latitudesh_python_sdk/models/get_ipop.py +33 -0
  61. latitudesh_python_sdk/models/get_ipsop.py +91 -0
  62. latitudesh_python_sdk/models/get_planop.py +16 -0
  63. latitudesh_python_sdk/models/get_plans_operating_systemop.py +19 -0
  64. latitudesh_python_sdk/models/get_plansop.py +125 -0
  65. latitudesh_python_sdk/models/get_project_ssh_keyop.py +37 -0
  66. latitudesh_python_sdk/models/get_project_ssh_keysop.py +33 -0
  67. latitudesh_python_sdk/models/get_project_user_dataop.py +38 -0
  68. latitudesh_python_sdk/models/get_project_users_dataop.py +46 -0
  69. latitudesh_python_sdk/models/get_projectsop.py +76 -0
  70. latitudesh_python_sdk/models/get_regionop.py +18 -0
  71. latitudesh_python_sdk/models/get_role_idop.py +16 -0
  72. latitudesh_python_sdk/models/get_rolesop.py +19 -0
  73. latitudesh_python_sdk/models/get_server_deploy_configop.py +18 -0
  74. latitudesh_python_sdk/models/get_server_out_of_bandop.py +18 -0
  75. latitudesh_python_sdk/models/get_serverop.py +33 -0
  76. latitudesh_python_sdk/models/get_serversop.py +156 -0
  77. latitudesh_python_sdk/models/get_storage_filesystemsop.py +22 -0
  78. latitudesh_python_sdk/models/get_traffic_consumptionop.py +45 -0
  79. latitudesh_python_sdk/models/get_traffic_quotaop.py +20 -0
  80. latitudesh_python_sdk/models/get_user_profileop.py +19 -0
  81. latitudesh_python_sdk/models/get_virtual_networkop.py +32 -0
  82. latitudesh_python_sdk/models/get_virtual_networks_assignmentsop.py +40 -0
  83. latitudesh_python_sdk/models/get_virtual_networksop.py +40 -0
  84. latitudesh_python_sdk/models/get_vpn_sessionsop.py +70 -0
  85. latitudesh_python_sdk/models/index_virtual_machineop.py +22 -0
  86. latitudesh_python_sdk/models/ip_address.py +122 -0
  87. latitudesh_python_sdk/models/ip_addresses.py +15 -0
  88. latitudesh_python_sdk/models/ipmi_session.py +53 -0
  89. latitudesh_python_sdk/models/list_firewallsop.py +20 -0
  90. latitudesh_python_sdk/models/membership.py +63 -0
  91. latitudesh_python_sdk/models/operating_systems.py +57 -0
  92. latitudesh_python_sdk/models/out_of_band_connection.py +88 -0
  93. latitudesh_python_sdk/models/patch_current_teamop.py +91 -0
  94. latitudesh_python_sdk/models/patch_storage_filesystemsop.py +79 -0
  95. latitudesh_python_sdk/models/patch_user_profileop.py +88 -0
  96. latitudesh_python_sdk/models/plan.py +15 -0
  97. latitudesh_python_sdk/models/plan_data.py +206 -0
  98. latitudesh_python_sdk/models/post_api_keyop.py +19 -0
  99. latitudesh_python_sdk/models/post_project_ssh_keyop.py +81 -0
  100. latitudesh_python_sdk/models/post_project_user_dataop.py +68 -0
  101. latitudesh_python_sdk/models/post_storage_filesystemsop.py +63 -0
  102. latitudesh_python_sdk/models/post_team_membersop.py +54 -0
  103. latitudesh_python_sdk/models/post_teamop.py +67 -0
  104. latitudesh_python_sdk/models/post_vpn_sessionop.py +63 -0
  105. latitudesh_python_sdk/models/project.py +130 -0
  106. latitudesh_python_sdk/models/project_include.py +72 -0
  107. latitudesh_python_sdk/models/projects.py +15 -0
  108. latitudesh_python_sdk/models/put_project_ssh_keyop.py +87 -0
  109. latitudesh_python_sdk/models/put_project_user_dataop.py +76 -0
  110. latitudesh_python_sdk/models/put_vpn_sessionop.py +16 -0
  111. latitudesh_python_sdk/models/region.py +50 -0
  112. latitudesh_python_sdk/models/region_resource_data.py +37 -0
  113. latitudesh_python_sdk/models/regions.py +50 -0
  114. latitudesh_python_sdk/models/role.py +15 -0
  115. latitudesh_python_sdk/models/role_data.py +35 -0
  116. latitudesh_python_sdk/models/security.py +25 -0
  117. latitudesh_python_sdk/models/server.py +54 -0
  118. latitudesh_python_sdk/models/server_action.py +52 -0
  119. latitudesh_python_sdk/models/server_data.py +219 -0
  120. latitudesh_python_sdk/models/server_exit_rescue_modeop.py +16 -0
  121. latitudesh_python_sdk/models/server_lockop.py +16 -0
  122. latitudesh_python_sdk/models/server_rescue.py +22 -0
  123. latitudesh_python_sdk/models/server_schedule_deletion.py +44 -0
  124. latitudesh_python_sdk/models/server_schedule_deletionop.py +16 -0
  125. latitudesh_python_sdk/models/server_start_rescue_modeop.py +16 -0
  126. latitudesh_python_sdk/models/server_unlockop.py +16 -0
  127. latitudesh_python_sdk/models/server_unschedule_deletionop.py +16 -0
  128. latitudesh_python_sdk/models/servers.py +26 -0
  129. latitudesh_python_sdk/models/show_virtual_machineop.py +16 -0
  130. latitudesh_python_sdk/models/ssh_key.py +15 -0
  131. latitudesh_python_sdk/models/ssh_key_data.py +55 -0
  132. latitudesh_python_sdk/models/storage_plan.py +36 -0
  133. latitudesh_python_sdk/models/storage_plans.py +15 -0
  134. latitudesh_python_sdk/models/team.py +74 -0
  135. latitudesh_python_sdk/models/team_include.py +43 -0
  136. latitudesh_python_sdk/models/team_members.py +51 -0
  137. latitudesh_python_sdk/models/teams.py +26 -0
  138. latitudesh_python_sdk/models/traffic.py +133 -0
  139. latitudesh_python_sdk/models/traffic_quota.py +106 -0
  140. latitudesh_python_sdk/models/update_api_key.py +48 -0
  141. latitudesh_python_sdk/models/update_api_keyop.py +41 -0
  142. latitudesh_python_sdk/models/update_firewallop.py +89 -0
  143. latitudesh_python_sdk/models/update_plans_bandwidthop.py +50 -0
  144. latitudesh_python_sdk/models/update_projectop.py +95 -0
  145. latitudesh_python_sdk/models/update_server_deploy_configop.py +122 -0
  146. latitudesh_python_sdk/models/update_serverop.py +69 -0
  147. latitudesh_python_sdk/models/update_tagop.py +74 -0
  148. latitudesh_python_sdk/models/update_virtual_networkop.py +67 -0
  149. latitudesh_python_sdk/models/user.py +59 -0
  150. latitudesh_python_sdk/models/user_data.py +15 -0
  151. latitudesh_python_sdk/models/user_data_properties.py +46 -0
  152. latitudesh_python_sdk/models/user_include.py +52 -0
  153. latitudesh_python_sdk/models/user_team.py +61 -0
  154. latitudesh_python_sdk/models/user_teams.py +26 -0
  155. latitudesh_python_sdk/models/user_update.py +37 -0
  156. latitudesh_python_sdk/models/virtual_machine.py +25 -0
  157. latitudesh_python_sdk/models/virtual_machine_payload.py +41 -0
  158. latitudesh_python_sdk/models/virtual_machine_plans.py +180 -0
  159. latitudesh_python_sdk/models/virtual_network.py +103 -0
  160. latitudesh_python_sdk/models/virtual_network1.py +84 -0
  161. latitudesh_python_sdk/models/virtual_network_assignment.py +37 -0
  162. latitudesh_python_sdk/models/virtual_network_assignments.py +29 -0
  163. latitudesh_python_sdk/models/virtual_networks.py +26 -0
  164. latitudesh_python_sdk/models/vpn_session_data_with_password.py +77 -0
  165. latitudesh_python_sdk/models/vpn_session_with_password.py +18 -0
  166. latitudesh_python_sdk/operatingsystems_sdk.py +188 -0
  167. latitudesh_python_sdk/plans.py +1178 -0
  168. latitudesh_python_sdk/privatenetworks.py +1672 -0
  169. latitudesh_python_sdk/projects_sdk.py +864 -0
  170. latitudesh_python_sdk/py.typed +1 -0
  171. latitudesh_python_sdk/regions_sdk.py +376 -0
  172. latitudesh_python_sdk/roles.py +374 -0
  173. latitudesh_python_sdk/sdk.py +214 -0
  174. latitudesh_python_sdk/sdkconfiguration.py +57 -0
  175. latitudesh_python_sdk/servers_sdk.py +3810 -0
  176. latitudesh_python_sdk/sshkeys.py +1050 -0
  177. latitudesh_python_sdk/storage.py +820 -0
  178. latitudesh_python_sdk/tags.py +786 -0
  179. latitudesh_python_sdk/teams_sdk.py +596 -0
  180. latitudesh_python_sdk/teamsmembers.py +578 -0
  181. latitudesh_python_sdk/traffic_sdk.py +400 -0
  182. latitudesh_python_sdk/types/__init__.py +21 -0
  183. latitudesh_python_sdk/types/basemodel.py +39 -0
  184. latitudesh_python_sdk/userdata_sdk.py +1052 -0
  185. latitudesh_python_sdk/userprofile.py +596 -0
  186. latitudesh_python_sdk/utils/__init__.py +101 -0
  187. latitudesh_python_sdk/utils/annotations.py +55 -0
  188. latitudesh_python_sdk/utils/enums.py +34 -0
  189. latitudesh_python_sdk/utils/eventstreaming.py +238 -0
  190. latitudesh_python_sdk/utils/forms.py +202 -0
  191. latitudesh_python_sdk/utils/headers.py +136 -0
  192. latitudesh_python_sdk/utils/logger.py +27 -0
  193. latitudesh_python_sdk/utils/metadata.py +118 -0
  194. latitudesh_python_sdk/utils/queryparams.py +205 -0
  195. latitudesh_python_sdk/utils/requestbodies.py +66 -0
  196. latitudesh_python_sdk/utils/retries.py +217 -0
  197. latitudesh_python_sdk/utils/security.py +192 -0
  198. latitudesh_python_sdk/utils/serializers.py +219 -0
  199. latitudesh_python_sdk/utils/url.py +155 -0
  200. latitudesh_python_sdk/utils/values.py +137 -0
  201. latitudesh_python_sdk/virtualmachines.py +772 -0
  202. latitudesh_python_sdk/vpnsessions.py +818 -0
  203. latitudesh_python_sdk-0.0.6.dist-info/LICENSE +21 -0
  204. latitudesh_python_sdk-0.0.6.dist-info/METADATA +730 -0
  205. latitudesh_python_sdk-0.0.6.dist-info/RECORD +206 -0
  206. latitudesh_python_sdk-0.0.6.dist-info/WHEEL +4 -0
@@ -0,0 +1,366 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .sdkconfiguration import SDKConfiguration
4
+ import httpx
5
+ from latitudesh_python_sdk import models, utils
6
+ from latitudesh_python_sdk._hooks import (
7
+ AfterErrorContext,
8
+ AfterSuccessContext,
9
+ BeforeRequestContext,
10
+ )
11
+ from latitudesh_python_sdk.utils import (
12
+ RetryConfig,
13
+ SerializedRequestBody,
14
+ get_body_content,
15
+ )
16
+ from typing import Callable, List, Mapping, Optional, Tuple
17
+ from urllib.parse import parse_qs, urlparse
18
+
19
+
20
+ class BaseSDK:
21
+ sdk_configuration: SDKConfiguration
22
+
23
+ def __init__(self, sdk_config: SDKConfiguration) -> None:
24
+ self.sdk_configuration = sdk_config
25
+
26
+ def _get_url(self, base_url, url_variables):
27
+ sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
28
+
29
+ if base_url is None:
30
+ base_url = sdk_url
31
+
32
+ if url_variables is None:
33
+ url_variables = sdk_variables
34
+
35
+ return utils.template_url(base_url, url_variables)
36
+
37
+ def _build_request_async(
38
+ self,
39
+ method,
40
+ path,
41
+ base_url,
42
+ url_variables,
43
+ request,
44
+ request_body_required,
45
+ request_has_path_params,
46
+ request_has_query_params,
47
+ user_agent_header,
48
+ accept_header_value,
49
+ _globals=None,
50
+ security=None,
51
+ timeout_ms: Optional[int] = None,
52
+ get_serialized_body: Optional[
53
+ Callable[[], Optional[SerializedRequestBody]]
54
+ ] = None,
55
+ url_override: Optional[str] = None,
56
+ http_headers: Optional[Mapping[str, str]] = None,
57
+ ) -> httpx.Request:
58
+ client = self.sdk_configuration.async_client
59
+ return self._build_request_with_client(
60
+ client,
61
+ method,
62
+ path,
63
+ base_url,
64
+ url_variables,
65
+ request,
66
+ request_body_required,
67
+ request_has_path_params,
68
+ request_has_query_params,
69
+ user_agent_header,
70
+ accept_header_value,
71
+ _globals,
72
+ security,
73
+ timeout_ms,
74
+ get_serialized_body,
75
+ url_override,
76
+ http_headers,
77
+ )
78
+
79
+ def _build_request(
80
+ self,
81
+ method,
82
+ path,
83
+ base_url,
84
+ url_variables,
85
+ request,
86
+ request_body_required,
87
+ request_has_path_params,
88
+ request_has_query_params,
89
+ user_agent_header,
90
+ accept_header_value,
91
+ _globals=None,
92
+ security=None,
93
+ timeout_ms: Optional[int] = None,
94
+ get_serialized_body: Optional[
95
+ Callable[[], Optional[SerializedRequestBody]]
96
+ ] = None,
97
+ url_override: Optional[str] = None,
98
+ http_headers: Optional[Mapping[str, str]] = None,
99
+ ) -> httpx.Request:
100
+ client = self.sdk_configuration.client
101
+ return self._build_request_with_client(
102
+ client,
103
+ method,
104
+ path,
105
+ base_url,
106
+ url_variables,
107
+ request,
108
+ request_body_required,
109
+ request_has_path_params,
110
+ request_has_query_params,
111
+ user_agent_header,
112
+ accept_header_value,
113
+ _globals,
114
+ security,
115
+ timeout_ms,
116
+ get_serialized_body,
117
+ url_override,
118
+ http_headers,
119
+ )
120
+
121
+ def _build_request_with_client(
122
+ self,
123
+ client,
124
+ method,
125
+ path,
126
+ base_url,
127
+ url_variables,
128
+ request,
129
+ request_body_required,
130
+ request_has_path_params,
131
+ request_has_query_params,
132
+ user_agent_header,
133
+ accept_header_value,
134
+ _globals=None,
135
+ security=None,
136
+ timeout_ms: Optional[int] = None,
137
+ get_serialized_body: Optional[
138
+ Callable[[], Optional[SerializedRequestBody]]
139
+ ] = None,
140
+ url_override: Optional[str] = None,
141
+ http_headers: Optional[Mapping[str, str]] = None,
142
+ ) -> httpx.Request:
143
+ query_params = {}
144
+
145
+ url = url_override
146
+ if url is None:
147
+ url = utils.generate_url(
148
+ self._get_url(base_url, url_variables),
149
+ path,
150
+ request if request_has_path_params else None,
151
+ _globals if request_has_path_params else None,
152
+ )
153
+
154
+ query_params = utils.get_query_params(
155
+ request if request_has_query_params else None,
156
+ _globals if request_has_query_params else None,
157
+ )
158
+ else:
159
+ # Pick up the query parameter from the override so they can be
160
+ # preserved when building the request later on (necessary as of
161
+ # httpx 0.28).
162
+ parsed_override = urlparse(str(url_override))
163
+ query_params = parse_qs(parsed_override.query, keep_blank_values=True)
164
+
165
+ headers = utils.get_headers(request, _globals)
166
+ headers["Accept"] = accept_header_value
167
+ headers[user_agent_header] = self.sdk_configuration.user_agent
168
+
169
+ if security is not None:
170
+ if callable(security):
171
+ security = security()
172
+ security = utils.get_security_from_env(security, models.Security)
173
+ if security is not None:
174
+ security_headers, security_query_params = utils.get_security(security)
175
+ headers = {**headers, **security_headers}
176
+ query_params = {**query_params, **security_query_params}
177
+
178
+ serialized_request_body = SerializedRequestBody()
179
+ if get_serialized_body is not None:
180
+ rb = get_serialized_body()
181
+ if request_body_required and rb is None:
182
+ raise ValueError("request body is required")
183
+
184
+ if rb is not None:
185
+ serialized_request_body = rb
186
+
187
+ if (
188
+ serialized_request_body.media_type is not None
189
+ and serialized_request_body.media_type
190
+ not in (
191
+ "multipart/form-data",
192
+ "multipart/mixed",
193
+ )
194
+ ):
195
+ headers["content-type"] = serialized_request_body.media_type
196
+
197
+ if http_headers is not None:
198
+ for header, value in http_headers.items():
199
+ headers[header] = value
200
+
201
+ timeout = timeout_ms / 1000 if timeout_ms is not None else None
202
+
203
+ return client.build_request(
204
+ method,
205
+ url,
206
+ params=query_params,
207
+ content=serialized_request_body.content,
208
+ data=serialized_request_body.data,
209
+ files=serialized_request_body.files,
210
+ headers=headers,
211
+ timeout=timeout,
212
+ )
213
+
214
+ def do_request(
215
+ self,
216
+ hook_ctx,
217
+ request,
218
+ error_status_codes,
219
+ stream=False,
220
+ retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
221
+ ) -> httpx.Response:
222
+ client = self.sdk_configuration.client
223
+ logger = self.sdk_configuration.debug_logger
224
+
225
+ def do():
226
+ http_res = None
227
+ try:
228
+ req = self.sdk_configuration.get_hooks().before_request(
229
+ BeforeRequestContext(hook_ctx), request
230
+ )
231
+ logger.debug(
232
+ "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
233
+ req.method,
234
+ req.url,
235
+ req.headers,
236
+ get_body_content(req),
237
+ )
238
+
239
+ if client is None:
240
+ raise ValueError("client is required")
241
+
242
+ http_res = client.send(req, stream=stream)
243
+ except Exception as e:
244
+ _, e = self.sdk_configuration.get_hooks().after_error(
245
+ AfterErrorContext(hook_ctx), None, e
246
+ )
247
+ if e is not None:
248
+ logger.debug("Request Exception", exc_info=True)
249
+ raise e
250
+
251
+ if http_res is None:
252
+ logger.debug("Raising no response SDK error")
253
+ raise models.APIError("No response received")
254
+
255
+ logger.debug(
256
+ "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
257
+ http_res.status_code,
258
+ http_res.url,
259
+ http_res.headers,
260
+ "<streaming response>" if stream else http_res.text,
261
+ )
262
+
263
+ if utils.match_status_codes(error_status_codes, http_res.status_code):
264
+ result, err = self.sdk_configuration.get_hooks().after_error(
265
+ AfterErrorContext(hook_ctx), http_res, None
266
+ )
267
+ if err is not None:
268
+ logger.debug("Request Exception", exc_info=True)
269
+ raise err
270
+ if result is not None:
271
+ http_res = result
272
+ else:
273
+ logger.debug("Raising unexpected SDK error")
274
+ raise models.APIError("Unexpected error occurred")
275
+
276
+ return http_res
277
+
278
+ if retry_config is not None:
279
+ http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
280
+ else:
281
+ http_res = do()
282
+
283
+ if not utils.match_status_codes(error_status_codes, http_res.status_code):
284
+ http_res = self.sdk_configuration.get_hooks().after_success(
285
+ AfterSuccessContext(hook_ctx), http_res
286
+ )
287
+
288
+ return http_res
289
+
290
+ async def do_request_async(
291
+ self,
292
+ hook_ctx,
293
+ request,
294
+ error_status_codes,
295
+ stream=False,
296
+ retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
297
+ ) -> httpx.Response:
298
+ client = self.sdk_configuration.async_client
299
+ logger = self.sdk_configuration.debug_logger
300
+
301
+ async def do():
302
+ http_res = None
303
+ try:
304
+ req = self.sdk_configuration.get_hooks().before_request(
305
+ BeforeRequestContext(hook_ctx), request
306
+ )
307
+ logger.debug(
308
+ "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
309
+ req.method,
310
+ req.url,
311
+ req.headers,
312
+ get_body_content(req),
313
+ )
314
+
315
+ if client is None:
316
+ raise ValueError("client is required")
317
+
318
+ http_res = await client.send(req, stream=stream)
319
+ except Exception as e:
320
+ _, e = self.sdk_configuration.get_hooks().after_error(
321
+ AfterErrorContext(hook_ctx), None, e
322
+ )
323
+ if e is not None:
324
+ logger.debug("Request Exception", exc_info=True)
325
+ raise e
326
+
327
+ if http_res is None:
328
+ logger.debug("Raising no response SDK error")
329
+ raise models.APIError("No response received")
330
+
331
+ logger.debug(
332
+ "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
333
+ http_res.status_code,
334
+ http_res.url,
335
+ http_res.headers,
336
+ "<streaming response>" if stream else http_res.text,
337
+ )
338
+
339
+ if utils.match_status_codes(error_status_codes, http_res.status_code):
340
+ result, err = self.sdk_configuration.get_hooks().after_error(
341
+ AfterErrorContext(hook_ctx), http_res, None
342
+ )
343
+ if err is not None:
344
+ logger.debug("Request Exception", exc_info=True)
345
+ raise err
346
+ if result is not None:
347
+ http_res = result
348
+ else:
349
+ logger.debug("Raising unexpected SDK error")
350
+ raise models.APIError("Unexpected error occurred")
351
+
352
+ return http_res
353
+
354
+ if retry_config is not None:
355
+ http_res = await utils.retry_async(
356
+ do, utils.Retries(retry_config[0], retry_config[1])
357
+ )
358
+ else:
359
+ http_res = await do()
360
+
361
+ if not utils.match_status_codes(error_status_codes, http_res.status_code):
362
+ http_res = self.sdk_configuration.get_hooks().after_success(
363
+ AfterSuccessContext(hook_ctx), http_res
364
+ )
365
+
366
+ return http_res
@@ -0,0 +1,210 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from latitudesh_python_sdk import models, utils
5
+ from latitudesh_python_sdk._hooks import HookContext
6
+ from latitudesh_python_sdk.types import OptionalNullable, UNSET
7
+ from latitudesh_python_sdk.utils import get_security_from_env
8
+ from typing import List, Mapping, Optional
9
+
10
+
11
+ class Billing(BaseSDK):
12
+ def list_usage(
13
+ self,
14
+ *,
15
+ filter_project: str,
16
+ filter_products: Optional[List[str]] = None,
17
+ filter_plan: Optional[str] = None,
18
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
19
+ server_url: Optional[str] = None,
20
+ timeout_ms: Optional[int] = None,
21
+ http_headers: Optional[Mapping[str, str]] = None,
22
+ ) -> models.BillingUsage:
23
+ r"""List Billing Usage
24
+
25
+ Returns the billing usage of a project
26
+
27
+
28
+ :param filter_project:
29
+ :param filter_products: Allows to filter the billing usage for specific products. It accepts an array of product ids.
30
+ :param filter_plan: Accepts a plan name and allows to filter the usage for that plan.
31
+ :param retries: Override the default retry configuration for this method
32
+ :param server_url: Override the default server URL for this method
33
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
34
+ :param http_headers: Additional headers to set or replace on requests.
35
+ """
36
+ base_url = None
37
+ url_variables = None
38
+ if timeout_ms is None:
39
+ timeout_ms = self.sdk_configuration.timeout_ms
40
+
41
+ if server_url is not None:
42
+ base_url = server_url
43
+ else:
44
+ base_url = self._get_url(base_url, url_variables)
45
+
46
+ request = models.GetBillingUsageRequest(
47
+ filter_products=filter_products,
48
+ filter_plan=filter_plan,
49
+ filter_project=filter_project,
50
+ )
51
+
52
+ req = self._build_request(
53
+ method="GET",
54
+ path="/billing/usage",
55
+ base_url=base_url,
56
+ url_variables=url_variables,
57
+ request=request,
58
+ request_body_required=False,
59
+ request_has_path_params=False,
60
+ request_has_query_params=True,
61
+ user_agent_header="user-agent",
62
+ accept_header_value="application/vnd.api+json",
63
+ http_headers=http_headers,
64
+ security=self.sdk_configuration.security,
65
+ timeout_ms=timeout_ms,
66
+ )
67
+
68
+ if retries == UNSET:
69
+ if self.sdk_configuration.retry_config is not UNSET:
70
+ retries = self.sdk_configuration.retry_config
71
+
72
+ retry_config = None
73
+ if isinstance(retries, utils.RetryConfig):
74
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
75
+
76
+ http_res = self.do_request(
77
+ hook_ctx=HookContext(
78
+ base_url=base_url or "",
79
+ operation_id="get-billing-usage",
80
+ oauth2_scopes=[],
81
+ security_source=get_security_from_env(
82
+ self.sdk_configuration.security, models.Security
83
+ ),
84
+ ),
85
+ request=req,
86
+ error_status_codes=["4XX", "5XX"],
87
+ retry_config=retry_config,
88
+ )
89
+
90
+ if utils.match_response(http_res, "200", "application/vnd.api+json"):
91
+ return utils.unmarshal_json(http_res.text, models.BillingUsage)
92
+ if utils.match_response(http_res, "4XX", "*"):
93
+ http_res_text = utils.stream_to_text(http_res)
94
+ raise models.APIError(
95
+ "API error occurred", http_res.status_code, http_res_text, http_res
96
+ )
97
+ if utils.match_response(http_res, "5XX", "*"):
98
+ http_res_text = utils.stream_to_text(http_res)
99
+ raise models.APIError(
100
+ "API error occurred", http_res.status_code, http_res_text, http_res
101
+ )
102
+
103
+ content_type = http_res.headers.get("Content-Type")
104
+ http_res_text = utils.stream_to_text(http_res)
105
+ raise models.APIError(
106
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
107
+ http_res.status_code,
108
+ http_res_text,
109
+ http_res,
110
+ )
111
+
112
+ async def list_usage_async(
113
+ self,
114
+ *,
115
+ filter_project: str,
116
+ filter_products: Optional[List[str]] = None,
117
+ filter_plan: Optional[str] = None,
118
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
119
+ server_url: Optional[str] = None,
120
+ timeout_ms: Optional[int] = None,
121
+ http_headers: Optional[Mapping[str, str]] = None,
122
+ ) -> models.BillingUsage:
123
+ r"""List Billing Usage
124
+
125
+ Returns the billing usage of a project
126
+
127
+
128
+ :param filter_project:
129
+ :param filter_products: Allows to filter the billing usage for specific products. It accepts an array of product ids.
130
+ :param filter_plan: Accepts a plan name and allows to filter the usage for that plan.
131
+ :param retries: Override the default retry configuration for this method
132
+ :param server_url: Override the default server URL for this method
133
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
134
+ :param http_headers: Additional headers to set or replace on requests.
135
+ """
136
+ base_url = None
137
+ url_variables = None
138
+ if timeout_ms is None:
139
+ timeout_ms = self.sdk_configuration.timeout_ms
140
+
141
+ if server_url is not None:
142
+ base_url = server_url
143
+ else:
144
+ base_url = self._get_url(base_url, url_variables)
145
+
146
+ request = models.GetBillingUsageRequest(
147
+ filter_products=filter_products,
148
+ filter_plan=filter_plan,
149
+ filter_project=filter_project,
150
+ )
151
+
152
+ req = self._build_request_async(
153
+ method="GET",
154
+ path="/billing/usage",
155
+ base_url=base_url,
156
+ url_variables=url_variables,
157
+ request=request,
158
+ request_body_required=False,
159
+ request_has_path_params=False,
160
+ request_has_query_params=True,
161
+ user_agent_header="user-agent",
162
+ accept_header_value="application/vnd.api+json",
163
+ http_headers=http_headers,
164
+ security=self.sdk_configuration.security,
165
+ timeout_ms=timeout_ms,
166
+ )
167
+
168
+ if retries == UNSET:
169
+ if self.sdk_configuration.retry_config is not UNSET:
170
+ retries = self.sdk_configuration.retry_config
171
+
172
+ retry_config = None
173
+ if isinstance(retries, utils.RetryConfig):
174
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
175
+
176
+ http_res = await self.do_request_async(
177
+ hook_ctx=HookContext(
178
+ base_url=base_url or "",
179
+ operation_id="get-billing-usage",
180
+ oauth2_scopes=[],
181
+ security_source=get_security_from_env(
182
+ self.sdk_configuration.security, models.Security
183
+ ),
184
+ ),
185
+ request=req,
186
+ error_status_codes=["4XX", "5XX"],
187
+ retry_config=retry_config,
188
+ )
189
+
190
+ if utils.match_response(http_res, "200", "application/vnd.api+json"):
191
+ return utils.unmarshal_json(http_res.text, models.BillingUsage)
192
+ if utils.match_response(http_res, "4XX", "*"):
193
+ http_res_text = await utils.stream_to_text_async(http_res)
194
+ raise models.APIError(
195
+ "API error occurred", http_res.status_code, http_res_text, http_res
196
+ )
197
+ if utils.match_response(http_res, "5XX", "*"):
198
+ http_res_text = await utils.stream_to_text_async(http_res)
199
+ raise models.APIError(
200
+ "API error occurred", http_res.status_code, http_res_text, http_res
201
+ )
202
+
203
+ content_type = http_res.headers.get("Content-Type")
204
+ http_res_text = await utils.stream_to_text_async(http_res)
205
+ raise models.APIError(
206
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
207
+ http_res.status_code,
208
+ http_res_text,
209
+ http_res,
210
+ )