hatchet-sdk 0.40.0a9__py3-none-any.whl → 0.42.0__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 hatchet-sdk might be problematic. Click here for more details.

Files changed (152) hide show
  1. hatchet_sdk/clients/admin.py +129 -59
  2. hatchet_sdk/clients/dispatcher/action_listener.py +25 -2
  3. hatchet_sdk/clients/events.py +91 -52
  4. hatchet_sdk/clients/rest/__init__.py +21 -0
  5. hatchet_sdk/clients/rest/api/api_token_api.py +12 -9
  6. hatchet_sdk/clients/rest/api/default_api.py +24 -18
  7. hatchet_sdk/clients/rest/api/event_api.py +32 -24
  8. hatchet_sdk/clients/rest/api/github_api.py +4 -3
  9. hatchet_sdk/clients/rest/api/log_api.py +4 -3
  10. hatchet_sdk/clients/rest/api/metadata_api.py +12 -9
  11. hatchet_sdk/clients/rest/api/rate_limits_api.py +7 -4
  12. hatchet_sdk/clients/rest/api/slack_api.py +8 -6
  13. hatchet_sdk/clients/rest/api/sns_api.py +12 -9
  14. hatchet_sdk/clients/rest/api/step_run_api.py +28 -21
  15. hatchet_sdk/clients/rest/api/tenant_api.py +67 -49
  16. hatchet_sdk/clients/rest/api/user_api.py +24 -18
  17. hatchet_sdk/clients/rest/api/worker_api.py +12 -9
  18. hatchet_sdk/clients/rest/api/workflow_api.py +3073 -936
  19. hatchet_sdk/clients/rest/api/workflow_run_api.py +669 -21
  20. hatchet_sdk/clients/rest/api_client.py +34 -11
  21. hatchet_sdk/clients/rest/configuration.py +161 -36
  22. hatchet_sdk/clients/rest/models/__init__.py +21 -0
  23. hatchet_sdk/clients/rest/models/api_errors.py +3 -3
  24. hatchet_sdk/clients/rest/models/bulk_create_event_request.py +3 -3
  25. hatchet_sdk/clients/rest/models/bulk_create_event_response.py +3 -3
  26. hatchet_sdk/clients/{cloud_rest/models/managed_worker_create_request_build_config_steps_inner.py → rest/models/create_cron_workflow_trigger_request.py} +18 -14
  27. hatchet_sdk/clients/{cloud_rest/models/github_app_list_installations200_response_rows_inner.py → rest/models/cron_workflows.py} +54 -21
  28. hatchet_sdk/clients/{cloud_rest/models/log_list200_response.py → rest/models/cron_workflows_list.py} +13 -22
  29. hatchet_sdk/clients/rest/models/cron_workflows_order_by_field.py +37 -0
  30. hatchet_sdk/clients/rest/models/event_list.py +3 -3
  31. hatchet_sdk/clients/rest/models/get_step_run_diff_response.py +3 -3
  32. hatchet_sdk/clients/rest/models/job.py +3 -3
  33. hatchet_sdk/clients/rest/models/job_run.py +3 -3
  34. hatchet_sdk/clients/rest/models/list_api_tokens_response.py +3 -3
  35. hatchet_sdk/clients/rest/models/list_pull_requests_response.py +3 -3
  36. hatchet_sdk/clients/rest/models/list_slack_webhooks.py +3 -3
  37. hatchet_sdk/clients/rest/models/list_sns_integrations.py +3 -3
  38. hatchet_sdk/clients/rest/models/log_line_list.py +3 -3
  39. hatchet_sdk/clients/rest/models/rate_limit_list.py +3 -3
  40. hatchet_sdk/clients/rest/models/replay_workflow_runs_response.py +3 -3
  41. hatchet_sdk/clients/{cloud_rest/models/log_list200_response_rows_inner.py → rest/models/schedule_workflow_run_request.py} +12 -12
  42. hatchet_sdk/clients/rest/models/scheduled_run_status.py +42 -0
  43. hatchet_sdk/clients/rest/models/scheduled_workflows.py +153 -0
  44. hatchet_sdk/clients/{cloud_rest/models/managed_worker_list200_response.py → rest/models/scheduled_workflows_list.py} +13 -22
  45. hatchet_sdk/clients/rest/models/scheduled_workflows_order_by_field.py +37 -0
  46. hatchet_sdk/clients/rest/models/step_run_archive_list.py +3 -3
  47. hatchet_sdk/clients/rest/models/step_run_event_list.py +3 -3
  48. hatchet_sdk/clients/rest/models/tenant_alert_email_group_list.py +3 -3
  49. hatchet_sdk/clients/rest/models/tenant_invite_list.py +3 -3
  50. hatchet_sdk/clients/rest/models/tenant_list.py +3 -3
  51. hatchet_sdk/clients/rest/models/tenant_member_list.py +3 -3
  52. hatchet_sdk/clients/rest/models/tenant_queue_metrics.py +16 -0
  53. hatchet_sdk/clients/rest/models/tenant_resource_policy.py +3 -3
  54. hatchet_sdk/clients/rest/models/tenant_step_run_queue_metrics.py +1 -1
  55. hatchet_sdk/clients/rest/models/user_tenant_memberships_list.py +3 -3
  56. hatchet_sdk/clients/rest/models/webhook_worker_list_response.py +3 -3
  57. hatchet_sdk/clients/rest/models/webhook_worker_request_list_response.py +3 -3
  58. hatchet_sdk/clients/rest/models/worker.py +20 -9
  59. hatchet_sdk/clients/rest/models/worker_list.py +3 -3
  60. hatchet_sdk/clients/{cloud_rest/models/tenant_billing_state_get200_response_payment_methods_inner.py → rest/models/worker_runtime_info.py} +23 -19
  61. hatchet_sdk/clients/rest/models/worker_runtime_sdks.py +38 -0
  62. hatchet_sdk/clients/rest/models/workflow.py +9 -9
  63. hatchet_sdk/clients/rest/models/workflow_list.py +3 -3
  64. hatchet_sdk/clients/rest/models/workflow_run.py +3 -3
  65. hatchet_sdk/clients/rest/models/workflow_run_list.py +3 -3
  66. hatchet_sdk/clients/rest/models/workflow_run_shape.py +3 -3
  67. hatchet_sdk/clients/rest/models/workflow_runs_metrics.py +1 -5
  68. hatchet_sdk/clients/rest/models/workflow_triggers.py +6 -6
  69. hatchet_sdk/clients/rest/models/workflow_version.py +3 -3
  70. hatchet_sdk/clients/rest/rest.py +3 -3
  71. hatchet_sdk/clients/rest_client.py +200 -21
  72. hatchet_sdk/contracts/dispatcher_pb2.py +71 -67
  73. hatchet_sdk/contracts/dispatcher_pb2.pyi +31 -2
  74. hatchet_sdk/contracts/events_pb2.pyi +2 -0
  75. hatchet_sdk/contracts/workflows_pb2.py +42 -40
  76. hatchet_sdk/contracts/workflows_pb2.pyi +24 -6
  77. hatchet_sdk/features/cron.py +286 -0
  78. hatchet_sdk/features/scheduled.py +248 -0
  79. hatchet_sdk/hatchet.py +80 -79
  80. hatchet_sdk/loader.py +37 -14
  81. hatchet_sdk/utils/serialization.py +15 -0
  82. hatchet_sdk/utils/tracing.py +67 -0
  83. hatchet_sdk/worker/runner/runner.py +158 -112
  84. hatchet_sdk/worker/worker.py +1 -17
  85. hatchet_sdk/workflow.py +4 -0
  86. {hatchet_sdk-0.40.0a9.dist-info → hatchet_sdk-0.42.0.dist-info}/METADATA +8 -2
  87. {hatchet_sdk-0.40.0a9.dist-info → hatchet_sdk-0.42.0.dist-info}/RECORD +89 -143
  88. {hatchet_sdk-0.40.0a9.dist-info → hatchet_sdk-0.42.0.dist-info}/entry_points.txt +1 -1
  89. hatchet_sdk/clients/cloud_rest/__init__.py +0 -186
  90. hatchet_sdk/clients/cloud_rest/api/__init__.py +0 -14
  91. hatchet_sdk/clients/cloud_rest/api/billing_api.py +0 -819
  92. hatchet_sdk/clients/cloud_rest/api/build_api.py +0 -298
  93. hatchet_sdk/clients/cloud_rest/api/feature_flags_api.py +0 -295
  94. hatchet_sdk/clients/cloud_rest/api/github_api.py +0 -1347
  95. hatchet_sdk/clients/cloud_rest/api/log_api.py +0 -971
  96. hatchet_sdk/clients/cloud_rest/api/managed_worker_api.py +0 -2546
  97. hatchet_sdk/clients/cloud_rest/api/metadata_api.py +0 -265
  98. hatchet_sdk/clients/cloud_rest/api/metrics_api.py +0 -1026
  99. hatchet_sdk/clients/cloud_rest/api/tenant_api.py +0 -301
  100. hatchet_sdk/clients/cloud_rest/api/user_api.py +0 -473
  101. hatchet_sdk/clients/cloud_rest/api/workflow_api.py +0 -369
  102. hatchet_sdk/clients/cloud_rest/api_client.py +0 -727
  103. hatchet_sdk/clients/cloud_rest/api_response.py +0 -22
  104. hatchet_sdk/clients/cloud_rest/configuration.py +0 -488
  105. hatchet_sdk/clients/cloud_rest/exceptions.py +0 -200
  106. hatchet_sdk/clients/cloud_rest/models/__init__.py +0 -157
  107. hatchet_sdk/clients/cloud_rest/models/billing_portal_link_get200_response.py +0 -85
  108. hatchet_sdk/clients/cloud_rest/models/build_get200_response.py +0 -121
  109. hatchet_sdk/clients/cloud_rest/models/github_app_list_branches200_response_inner.py +0 -86
  110. hatchet_sdk/clients/cloud_rest/models/github_app_list_installations200_response.py +0 -119
  111. hatchet_sdk/clients/cloud_rest/models/github_app_list_installations200_response_pagination.py +0 -95
  112. hatchet_sdk/clients/cloud_rest/models/github_app_list_installations200_response_rows_inner_metadata.py +0 -98
  113. hatchet_sdk/clients/cloud_rest/models/github_app_list_repos200_response_inner.py +0 -86
  114. hatchet_sdk/clients/cloud_rest/models/infra_as_code_create_request.py +0 -107
  115. hatchet_sdk/clients/cloud_rest/models/log_create_request_inner.py +0 -136
  116. hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_event.py +0 -83
  117. hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_fly.py +0 -100
  118. hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_fly_app.py +0 -86
  119. hatchet_sdk/clients/cloud_rest/models/log_create_request_inner_log.py +0 -83
  120. hatchet_sdk/clients/cloud_rest/models/managed_worker_create_request.py +0 -128
  121. hatchet_sdk/clients/cloud_rest/models/managed_worker_create_request_build_config.py +0 -121
  122. hatchet_sdk/clients/cloud_rest/models/managed_worker_create_request_runtime_config.py +0 -166
  123. hatchet_sdk/clients/cloud_rest/models/managed_worker_events_list200_response.py +0 -119
  124. hatchet_sdk/clients/cloud_rest/models/managed_worker_events_list200_response_rows_inner.py +0 -117
  125. hatchet_sdk/clients/cloud_rest/models/managed_worker_instances_list200_response.py +0 -119
  126. hatchet_sdk/clients/cloud_rest/models/managed_worker_instances_list200_response_rows_inner.py +0 -113
  127. hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner.py +0 -154
  128. hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner_build_config.py +0 -151
  129. hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner_build_config_steps_inner.py +0 -109
  130. hatchet_sdk/clients/cloud_rest/models/managed_worker_list200_response_rows_inner_runtime_configs_inner.py +0 -171
  131. hatchet_sdk/clients/cloud_rest/models/managed_worker_update_request.py +0 -131
  132. hatchet_sdk/clients/cloud_rest/models/metadata_get200_response.py +0 -101
  133. hatchet_sdk/clients/cloud_rest/models/metadata_get400_response.py +0 -105
  134. hatchet_sdk/clients/cloud_rest/models/metadata_get400_response_errors_inner.py +0 -102
  135. hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner.py +0 -108
  136. hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner_histograms_inner.py +0 -102
  137. hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner_histograms_inner_histogram.py +0 -113
  138. hatchet_sdk/clients/cloud_rest/models/metrics_cpu_get200_response_inner_histograms_inner_histogram_buckets_inner.py +0 -93
  139. hatchet_sdk/clients/cloud_rest/models/runtime_config_list_actions200_response.py +0 -83
  140. hatchet_sdk/clients/cloud_rest/models/subscription_upsert200_response.py +0 -114
  141. hatchet_sdk/clients/cloud_rest/models/subscription_upsert_request.py +0 -88
  142. hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response.py +0 -170
  143. hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response_coupons_inner.py +0 -137
  144. hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response_plans_inner.py +0 -103
  145. hatchet_sdk/clients/cloud_rest/models/tenant_billing_state_get200_response_subscription.py +0 -114
  146. hatchet_sdk/clients/cloud_rest/models/workflow_run_events_get_metrics200_response.py +0 -107
  147. hatchet_sdk/clients/cloud_rest/models/workflow_run_events_get_metrics200_response_results_inner.py +0 -105
  148. hatchet_sdk/clients/cloud_rest/rest.py +0 -182
  149. hatchet_sdk/compute/__init__.py +0 -0
  150. hatchet_sdk/compute/configs.py +0 -34
  151. hatchet_sdk/compute/managed_compute.py +0 -111
  152. {hatchet_sdk-0.40.0a9.dist-info → hatchet_sdk-0.42.0.dist-info}/WHEEL +0 -0
@@ -1,727 +0,0 @@
1
- # coding: utf-8
2
-
3
- """
4
- Hatchet API
5
-
6
- The Hatchet API
7
-
8
- The version of the OpenAPI document: 1.0.0
9
- Generated by OpenAPI Generator (https://openapi-generator.tech)
10
-
11
- Do not edit the class manually.
12
- """ # noqa: E501
13
-
14
-
15
- import datetime
16
- import json
17
- import mimetypes
18
- import os
19
- import re
20
- import tempfile
21
- from enum import Enum
22
- from typing import Dict, List, Optional, Tuple, Union
23
- from urllib.parse import quote
24
-
25
- from dateutil.parser import parse
26
- from pydantic import SecretStr
27
-
28
- import hatchet_sdk.clients.cloud_rest.models
29
- from hatchet_sdk.clients.cloud_rest import rest
30
- from hatchet_sdk.clients.cloud_rest.api_response import ApiResponse
31
- from hatchet_sdk.clients.cloud_rest.api_response import T as ApiResponseT
32
- from hatchet_sdk.clients.cloud_rest.configuration import Configuration
33
- from hatchet_sdk.clients.cloud_rest.exceptions import (
34
- ApiException,
35
- ApiValueError,
36
- BadRequestException,
37
- ForbiddenException,
38
- NotFoundException,
39
- ServiceException,
40
- UnauthorizedException,
41
- )
42
-
43
- RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
44
-
45
-
46
- class ApiClient:
47
- """Generic API client for OpenAPI client library builds.
48
-
49
- OpenAPI generic API client. This client handles the client-
50
- server communication, and is invariant across implementations. Specifics of
51
- the methods and models for each application are generated from the OpenAPI
52
- templates.
53
-
54
- :param configuration: .Configuration object for this client
55
- :param header_name: a header to pass when making calls to the API.
56
- :param header_value: a header value to pass when making calls to
57
- the API.
58
- :param cookie: a cookie to include in the header when making calls
59
- to the API
60
- """
61
-
62
- PRIMITIVE_TYPES = (float, bool, bytes, str, int)
63
- NATIVE_TYPES_MAPPING = {
64
- "int": int,
65
- "long": int, # TODO remove as only py3 is supported?
66
- "float": float,
67
- "str": str,
68
- "bool": bool,
69
- "date": datetime.date,
70
- "datetime": datetime.datetime,
71
- "object": object,
72
- }
73
- _pool = None
74
-
75
- def __init__(
76
- self, configuration=None, header_name=None, header_value=None, cookie=None
77
- ) -> None:
78
- # use default configuration if none is provided
79
- if configuration is None:
80
- configuration = Configuration.get_default()
81
- self.configuration = configuration
82
-
83
- self.rest_client = rest.RESTClientObject(configuration)
84
- self.default_headers = {}
85
- if header_name is not None:
86
- self.default_headers[header_name] = header_value
87
- self.cookie = cookie
88
- # Set default User-Agent.
89
- self.user_agent = "OpenAPI-Generator/1.0.0/python"
90
- self.client_side_validation = configuration.client_side_validation
91
-
92
- async def __aenter__(self):
93
- return self
94
-
95
- async def __aexit__(self, exc_type, exc_value, traceback):
96
- await self.close()
97
-
98
- async def close(self):
99
- await self.rest_client.close()
100
-
101
- @property
102
- def user_agent(self):
103
- """User agent for this API client"""
104
- return self.default_headers["User-Agent"]
105
-
106
- @user_agent.setter
107
- def user_agent(self, value):
108
- self.default_headers["User-Agent"] = value
109
-
110
- def set_default_header(self, header_name, header_value):
111
- self.default_headers[header_name] = header_value
112
-
113
- _default = None
114
-
115
- @classmethod
116
- def get_default(cls):
117
- """Return new instance of ApiClient.
118
-
119
- This method returns newly created, based on default constructor,
120
- object of ApiClient class or returns a copy of default
121
- ApiClient.
122
-
123
- :return: The ApiClient object.
124
- """
125
- if cls._default is None:
126
- cls._default = ApiClient()
127
- return cls._default
128
-
129
- @classmethod
130
- def set_default(cls, default):
131
- """Set default instance of ApiClient.
132
-
133
- It stores default ApiClient.
134
-
135
- :param default: object of ApiClient.
136
- """
137
- cls._default = default
138
-
139
- def param_serialize(
140
- self,
141
- method,
142
- resource_path,
143
- path_params=None,
144
- query_params=None,
145
- header_params=None,
146
- body=None,
147
- post_params=None,
148
- files=None,
149
- auth_settings=None,
150
- collection_formats=None,
151
- _host=None,
152
- _request_auth=None,
153
- ) -> RequestSerialized:
154
- """Builds the HTTP request params needed by the request.
155
- :param method: Method to call.
156
- :param resource_path: Path to method endpoint.
157
- :param path_params: Path parameters in the url.
158
- :param query_params: Query parameters in the url.
159
- :param header_params: Header parameters to be
160
- placed in the request header.
161
- :param body: Request body.
162
- :param post_params dict: Request post form parameters,
163
- for `application/x-www-form-urlencoded`, `multipart/form-data`.
164
- :param auth_settings list: Auth Settings names for the request.
165
- :param files dict: key -> filename, value -> filepath,
166
- for `multipart/form-data`.
167
- :param collection_formats: dict of collection formats for path, query,
168
- header, and post parameters.
169
- :param _request_auth: set to override the auth_settings for an a single
170
- request; this effectively ignores the authentication
171
- in the spec for a single request.
172
- :return: tuple of form (path, http_method, query_params, header_params,
173
- body, post_params, files)
174
- """
175
-
176
- config = self.configuration
177
-
178
- # header parameters
179
- header_params = header_params or {}
180
- header_params.update(self.default_headers)
181
- if self.cookie:
182
- header_params["Cookie"] = self.cookie
183
- if header_params:
184
- header_params = self.sanitize_for_serialization(header_params)
185
- header_params = dict(
186
- self.parameters_to_tuples(header_params, collection_formats)
187
- )
188
-
189
- # path parameters
190
- if path_params:
191
- path_params = self.sanitize_for_serialization(path_params)
192
- path_params = self.parameters_to_tuples(path_params, collection_formats)
193
- for k, v in path_params:
194
- # specified safe chars, encode everything
195
- resource_path = resource_path.replace(
196
- "{%s}" % k, quote(str(v), safe=config.safe_chars_for_path_param)
197
- )
198
-
199
- # post parameters
200
- if post_params or files:
201
- post_params = post_params if post_params else []
202
- post_params = self.sanitize_for_serialization(post_params)
203
- post_params = self.parameters_to_tuples(post_params, collection_formats)
204
- if files:
205
- post_params.extend(self.files_parameters(files))
206
-
207
- # auth setting
208
- self.update_params_for_auth(
209
- header_params,
210
- query_params,
211
- auth_settings,
212
- resource_path,
213
- method,
214
- body,
215
- request_auth=_request_auth,
216
- )
217
-
218
- # body
219
- if body:
220
- body = self.sanitize_for_serialization(body)
221
-
222
- # request url
223
- if _host is None:
224
- url = self.configuration.host + resource_path
225
- else:
226
- # use server/host defined in path or operation instead
227
- url = _host + resource_path
228
-
229
- # query parameters
230
- if query_params:
231
- query_params = self.sanitize_for_serialization(query_params)
232
- url_query = self.parameters_to_url_query(query_params, collection_formats)
233
- url += "?" + url_query
234
-
235
- return method, url, header_params, body, post_params
236
-
237
- async def call_api(
238
- self,
239
- method,
240
- url,
241
- header_params=None,
242
- body=None,
243
- post_params=None,
244
- _request_timeout=None,
245
- ) -> rest.RESTResponse:
246
- """Makes the HTTP request (synchronous)
247
- :param method: Method to call.
248
- :param url: Path to method endpoint.
249
- :param header_params: Header parameters to be
250
- placed in the request header.
251
- :param body: Request body.
252
- :param post_params dict: Request post form parameters,
253
- for `application/x-www-form-urlencoded`, `multipart/form-data`.
254
- :param _request_timeout: timeout setting for this request.
255
- :return: RESTResponse
256
- """
257
-
258
- try:
259
- # perform request and return response
260
- response_data = await self.rest_client.request(
261
- method,
262
- url,
263
- headers=header_params,
264
- body=body,
265
- post_params=post_params,
266
- _request_timeout=_request_timeout,
267
- )
268
-
269
- except ApiException as e:
270
- raise e
271
-
272
- return response_data
273
-
274
- def response_deserialize(
275
- self,
276
- response_data: rest.RESTResponse,
277
- response_types_map: Optional[Dict[str, ApiResponseT]] = None,
278
- ) -> ApiResponse[ApiResponseT]:
279
- """Deserializes response into an object.
280
- :param response_data: RESTResponse object to be deserialized.
281
- :param response_types_map: dict of response types.
282
- :return: ApiResponse
283
- """
284
-
285
- msg = "RESTResponse.read() must be called before passing it to response_deserialize()"
286
- assert response_data.data is not None, msg
287
-
288
- response_type = response_types_map.get(str(response_data.status), None)
289
- if (
290
- not response_type
291
- and isinstance(response_data.status, int)
292
- and 100 <= response_data.status <= 599
293
- ):
294
- # if not found, look for '1XX', '2XX', etc.
295
- response_type = response_types_map.get(
296
- str(response_data.status)[0] + "XX", None
297
- )
298
-
299
- # deserialize response data
300
- response_text = None
301
- return_data = None
302
- try:
303
- if response_type == "bytearray":
304
- return_data = response_data.data
305
- elif response_type == "file":
306
- return_data = self.__deserialize_file(response_data)
307
- elif response_type is not None:
308
- match = None
309
- content_type = response_data.getheader("content-type")
310
- if content_type is not None:
311
- match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
312
- encoding = match.group(1) if match else "utf-8"
313
- response_text = response_data.data.decode(encoding)
314
- if response_type in ["bytearray", "str"]:
315
- return_data = self.__deserialize_primitive(
316
- response_text, response_type
317
- )
318
- else:
319
- return_data = self.deserialize(response_text, response_type)
320
- finally:
321
- if not 200 <= response_data.status <= 299:
322
- raise ApiException.from_response(
323
- http_resp=response_data,
324
- body=response_text,
325
- data=return_data,
326
- )
327
-
328
- return ApiResponse(
329
- status_code=response_data.status,
330
- data=return_data,
331
- headers=response_data.getheaders(),
332
- raw_data=response_data.data,
333
- )
334
-
335
- def sanitize_for_serialization(self, obj):
336
- """Builds a JSON POST object.
337
-
338
- If obj is None, return None.
339
- If obj is SecretStr, return obj.get_secret_value()
340
- If obj is str, int, long, float, bool, return directly.
341
- If obj is datetime.datetime, datetime.date
342
- convert to string in iso8601 format.
343
- If obj is list, sanitize each element in the list.
344
- If obj is dict, return the dict.
345
- If obj is OpenAPI model, return the properties dict.
346
-
347
- :param obj: The data to serialize.
348
- :return: The serialized form of data.
349
- """
350
- if obj is None:
351
- return None
352
- elif isinstance(obj, Enum):
353
- return obj.value
354
- elif isinstance(obj, SecretStr):
355
- return obj.get_secret_value()
356
- elif isinstance(obj, self.PRIMITIVE_TYPES):
357
- return obj
358
- elif isinstance(obj, list):
359
- return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
360
- elif isinstance(obj, tuple):
361
- return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj)
362
- elif isinstance(obj, (datetime.datetime, datetime.date)):
363
- return obj.isoformat()
364
-
365
- elif isinstance(obj, dict):
366
- obj_dict = obj
367
- else:
368
- # Convert model obj to dict except
369
- # attributes `openapi_types`, `attribute_map`
370
- # and attributes which value is not None.
371
- # Convert attribute name to json key in
372
- # model definition for request.
373
- if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")):
374
- obj_dict = obj.to_dict()
375
- else:
376
- obj_dict = obj.__dict__
377
-
378
- return {
379
- key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()
380
- }
381
-
382
- def deserialize(self, response_text, response_type):
383
- """Deserializes response into an object.
384
-
385
- :param response: RESTResponse object to be deserialized.
386
- :param response_type: class literal for
387
- deserialized object, or string of class name.
388
-
389
- :return: deserialized object.
390
- """
391
-
392
- # fetch data from response object
393
- try:
394
- data = json.loads(response_text)
395
- except ValueError:
396
- data = response_text
397
-
398
- return self.__deserialize(data, response_type)
399
-
400
- def __deserialize(self, data, klass):
401
- """Deserializes dict, list, str into an object.
402
-
403
- :param data: dict, list or str.
404
- :param klass: class literal, or string of class name.
405
-
406
- :return: object.
407
- """
408
- if data is None:
409
- return None
410
-
411
- if isinstance(klass, str):
412
- if klass.startswith("List["):
413
- m = re.match(r"List\[(.*)]", klass)
414
- assert m is not None, "Malformed List type definition"
415
- sub_kls = m.group(1)
416
- return [self.__deserialize(sub_data, sub_kls) for sub_data in data]
417
-
418
- if klass.startswith("Dict["):
419
- m = re.match(r"Dict\[([^,]*), (.*)]", klass)
420
- assert m is not None, "Malformed Dict type definition"
421
- sub_kls = m.group(2)
422
- return {k: self.__deserialize(v, sub_kls) for k, v in data.items()}
423
-
424
- # convert str to class
425
- if klass in self.NATIVE_TYPES_MAPPING:
426
- klass = self.NATIVE_TYPES_MAPPING[klass]
427
- else:
428
- klass = getattr(hatchet_sdk.clients.cloud_rest.models, klass)
429
-
430
- if klass in self.PRIMITIVE_TYPES:
431
- return self.__deserialize_primitive(data, klass)
432
- elif klass == object:
433
- return self.__deserialize_object(data)
434
- elif klass == datetime.date:
435
- return self.__deserialize_date(data)
436
- elif klass == datetime.datetime:
437
- return self.__deserialize_datetime(data)
438
- elif issubclass(klass, Enum):
439
- return self.__deserialize_enum(data, klass)
440
- else:
441
- return self.__deserialize_model(data, klass)
442
-
443
- def parameters_to_tuples(self, params, collection_formats):
444
- """Get parameters as list of tuples, formatting collections.
445
-
446
- :param params: Parameters as dict or list of two-tuples
447
- :param dict collection_formats: Parameter collection formats
448
- :return: Parameters as list of tuples, collections formatted
449
- """
450
- new_params: List[Tuple[str, str]] = []
451
- if collection_formats is None:
452
- collection_formats = {}
453
- for k, v in params.items() if isinstance(params, dict) else params:
454
- if k in collection_formats:
455
- collection_format = collection_formats[k]
456
- if collection_format == "multi":
457
- new_params.extend((k, value) for value in v)
458
- else:
459
- if collection_format == "ssv":
460
- delimiter = " "
461
- elif collection_format == "tsv":
462
- delimiter = "\t"
463
- elif collection_format == "pipes":
464
- delimiter = "|"
465
- else: # csv is the default
466
- delimiter = ","
467
- new_params.append((k, delimiter.join(str(value) for value in v)))
468
- else:
469
- new_params.append((k, v))
470
- return new_params
471
-
472
- def parameters_to_url_query(self, params, collection_formats):
473
- """Get parameters as list of tuples, formatting collections.
474
-
475
- :param params: Parameters as dict or list of two-tuples
476
- :param dict collection_formats: Parameter collection formats
477
- :return: URL query string (e.g. a=Hello%20World&b=123)
478
- """
479
- new_params: List[Tuple[str, str]] = []
480
- if collection_formats is None:
481
- collection_formats = {}
482
- for k, v in params.items() if isinstance(params, dict) else params:
483
- if isinstance(v, bool):
484
- v = str(v).lower()
485
- if isinstance(v, (int, float)):
486
- v = str(v)
487
- if isinstance(v, dict):
488
- v = json.dumps(v)
489
-
490
- if k in collection_formats:
491
- collection_format = collection_formats[k]
492
- if collection_format == "multi":
493
- new_params.extend((k, str(value)) for value in v)
494
- else:
495
- if collection_format == "ssv":
496
- delimiter = " "
497
- elif collection_format == "tsv":
498
- delimiter = "\t"
499
- elif collection_format == "pipes":
500
- delimiter = "|"
501
- else: # csv is the default
502
- delimiter = ","
503
- new_params.append(
504
- (k, delimiter.join(quote(str(value)) for value in v))
505
- )
506
- else:
507
- new_params.append((k, quote(str(v))))
508
-
509
- return "&".join(["=".join(map(str, item)) for item in new_params])
510
-
511
- def files_parameters(self, files: Dict[str, Union[str, bytes]]):
512
- """Builds form parameters.
513
-
514
- :param files: File parameters.
515
- :return: Form parameters with files.
516
- """
517
- params = []
518
- for k, v in files.items():
519
- if isinstance(v, str):
520
- with open(v, "rb") as f:
521
- filename = os.path.basename(f.name)
522
- filedata = f.read()
523
- elif isinstance(v, bytes):
524
- filename = k
525
- filedata = v
526
- else:
527
- raise ValueError("Unsupported file value")
528
- mimetype = mimetypes.guess_type(filename)[0] or "application/octet-stream"
529
- params.append(tuple([k, tuple([filename, filedata, mimetype])]))
530
- return params
531
-
532
- def select_header_accept(self, accepts: List[str]) -> Optional[str]:
533
- """Returns `Accept` based on an array of accepts provided.
534
-
535
- :param accepts: List of headers.
536
- :return: Accept (e.g. application/json).
537
- """
538
- if not accepts:
539
- return None
540
-
541
- for accept in accepts:
542
- if re.search("json", accept, re.IGNORECASE):
543
- return accept
544
-
545
- return accepts[0]
546
-
547
- def select_header_content_type(self, content_types):
548
- """Returns `Content-Type` based on an array of content_types provided.
549
-
550
- :param content_types: List of content-types.
551
- :return: Content-Type (e.g. application/json).
552
- """
553
- if not content_types:
554
- return None
555
-
556
- for content_type in content_types:
557
- if re.search("json", content_type, re.IGNORECASE):
558
- return content_type
559
-
560
- return content_types[0]
561
-
562
- def update_params_for_auth(
563
- self,
564
- headers,
565
- queries,
566
- auth_settings,
567
- resource_path,
568
- method,
569
- body,
570
- request_auth=None,
571
- ) -> None:
572
- """Updates header and query params based on authentication setting.
573
-
574
- :param headers: Header parameters dict to be updated.
575
- :param queries: Query parameters tuple list to be updated.
576
- :param auth_settings: Authentication setting identifiers list.
577
- :resource_path: A string representation of the HTTP request resource path.
578
- :method: A string representation of the HTTP request method.
579
- :body: A object representing the body of the HTTP request.
580
- The object type is the return value of sanitize_for_serialization().
581
- :param request_auth: if set, the provided settings will
582
- override the token in the configuration.
583
- """
584
- if not auth_settings:
585
- return
586
-
587
- if request_auth:
588
- self._apply_auth_params(
589
- headers, queries, resource_path, method, body, request_auth
590
- )
591
- else:
592
- for auth in auth_settings:
593
- auth_setting = self.configuration.auth_settings().get(auth)
594
- if auth_setting:
595
- self._apply_auth_params(
596
- headers, queries, resource_path, method, body, auth_setting
597
- )
598
-
599
- def _apply_auth_params(
600
- self, headers, queries, resource_path, method, body, auth_setting
601
- ) -> None:
602
- """Updates the request parameters based on a single auth_setting
603
-
604
- :param headers: Header parameters dict to be updated.
605
- :param queries: Query parameters tuple list to be updated.
606
- :resource_path: A string representation of the HTTP request resource path.
607
- :method: A string representation of the HTTP request method.
608
- :body: A object representing the body of the HTTP request.
609
- The object type is the return value of sanitize_for_serialization().
610
- :param auth_setting: auth settings for the endpoint
611
- """
612
- if auth_setting["in"] == "cookie":
613
- headers["Cookie"] = auth_setting["value"]
614
- elif auth_setting["in"] == "header":
615
- if auth_setting["type"] != "http-signature":
616
- headers[auth_setting["key"]] = auth_setting["value"]
617
- elif auth_setting["in"] == "query":
618
- queries.append((auth_setting["key"], auth_setting["value"]))
619
- else:
620
- raise ApiValueError("Authentication token must be in `query` or `header`")
621
-
622
- def __deserialize_file(self, response):
623
- """Deserializes body to file
624
-
625
- Saves response body into a file in a temporary folder,
626
- using the filename from the `Content-Disposition` header if provided.
627
-
628
- handle file downloading
629
- save response body into a tmp file and return the instance
630
-
631
- :param response: RESTResponse.
632
- :return: file path.
633
- """
634
- fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
635
- os.close(fd)
636
- os.remove(path)
637
-
638
- content_disposition = response.getheader("Content-Disposition")
639
- if content_disposition:
640
- m = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition)
641
- assert m is not None, "Unexpected 'content-disposition' header value"
642
- filename = m.group(1)
643
- path = os.path.join(os.path.dirname(path), filename)
644
-
645
- with open(path, "wb") as f:
646
- f.write(response.data)
647
-
648
- return path
649
-
650
- def __deserialize_primitive(self, data, klass):
651
- """Deserializes string to primitive type.
652
-
653
- :param data: str.
654
- :param klass: class literal.
655
-
656
- :return: int, long, float, str, bool.
657
- """
658
- try:
659
- return klass(data)
660
- except UnicodeEncodeError:
661
- return str(data)
662
- except TypeError:
663
- return data
664
-
665
- def __deserialize_object(self, value):
666
- """Return an original value.
667
-
668
- :return: object.
669
- """
670
- return value
671
-
672
- def __deserialize_date(self, string):
673
- """Deserializes string to date.
674
-
675
- :param string: str.
676
- :return: date.
677
- """
678
- try:
679
- return parse(string).date()
680
- except ImportError:
681
- return string
682
- except ValueError:
683
- raise rest.ApiException(
684
- status=0, reason="Failed to parse `{0}` as date object".format(string)
685
- )
686
-
687
- def __deserialize_datetime(self, string):
688
- """Deserializes string to datetime.
689
-
690
- The string should be in iso8601 datetime format.
691
-
692
- :param string: str.
693
- :return: datetime.
694
- """
695
- try:
696
- return parse(string)
697
- except ImportError:
698
- return string
699
- except ValueError:
700
- raise rest.ApiException(
701
- status=0,
702
- reason=("Failed to parse `{0}` as datetime object".format(string)),
703
- )
704
-
705
- def __deserialize_enum(self, data, klass):
706
- """Deserializes primitive type to enum.
707
-
708
- :param data: primitive type.
709
- :param klass: class literal.
710
- :return: enum value.
711
- """
712
- try:
713
- return klass(data)
714
- except ValueError:
715
- raise rest.ApiException(
716
- status=0, reason=("Failed to parse `{0}` as `{1}`".format(data, klass))
717
- )
718
-
719
- def __deserialize_model(self, data, klass):
720
- """Deserializes list or dict to model.
721
-
722
- :param data: dict, list.
723
- :param klass: class literal.
724
- :return: model object.
725
- """
726
-
727
- return klass.from_dict(data)