levelfour 0.1.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.
- levelfour/__init__.py +495 -0
- levelfour/api_keys/__init__.py +34 -0
- levelfour/api_keys/client.py +337 -0
- levelfour/api_keys/raw_client.py +621 -0
- levelfour/api_keys/types/__init__.py +34 -0
- levelfour/api_keys/types/create_api_key_request_scope.py +5 -0
- levelfour/async_levelfour_client.py +39 -0
- levelfour/base_client.py +346 -0
- levelfour/client.py +54 -0
- levelfour/core/__init__.py +127 -0
- levelfour/core/api_error.py +23 -0
- levelfour/core/client_wrapper.py +105 -0
- levelfour/core/datetime_utils.py +70 -0
- levelfour/core/file.py +67 -0
- levelfour/core/force_multipart.py +18 -0
- levelfour/core/http_client.py +776 -0
- levelfour/core/http_response.py +59 -0
- levelfour/core/http_sse/__init__.py +42 -0
- levelfour/core/http_sse/_api.py +112 -0
- levelfour/core/http_sse/_decoders.py +61 -0
- levelfour/core/http_sse/_exceptions.py +7 -0
- levelfour/core/http_sse/_models.py +17 -0
- levelfour/core/jsonable_encoder.py +108 -0
- levelfour/core/logging.py +107 -0
- levelfour/core/pagination.py +82 -0
- levelfour/core/pydantic_utilities.py +577 -0
- levelfour/core/query_encoder.py +58 -0
- levelfour/core/remove_none_from_dict.py +11 -0
- levelfour/core/request_options.py +35 -0
- levelfour/core/serialization.py +276 -0
- levelfour/errors/__init__.py +40 -0
- levelfour/errors/forbidden_error.py +11 -0
- levelfour/errors/unauthorized_error.py +11 -0
- levelfour/errors/unprocessable_entity_error.py +11 -0
- levelfour/evaluation/__init__.py +4 -0
- levelfour/evaluation/client.py +102 -0
- levelfour/evaluation/raw_client.py +141 -0
- levelfour/exceptions.py +63 -0
- levelfour/health/__init__.py +4 -0
- levelfour/health/client.py +163 -0
- levelfour/health/raw_client.py +164 -0
- levelfour/integrations/__init__.py +0 -0
- levelfour/integrations/django.py +26 -0
- levelfour/integrations/fastapi.py +39 -0
- levelfour/integrations/telemetry.py +66 -0
- levelfour/levelfour_client.py +47 -0
- levelfour/pagination.py +84 -0
- levelfour/pr_analysis/__init__.py +4 -0
- levelfour/pr_analysis/client.py +408 -0
- levelfour/pr_analysis/raw_client.py +620 -0
- levelfour/pr_analysis_actions/__init__.py +4 -0
- levelfour/pr_analysis_actions/client.py +588 -0
- levelfour/pr_analysis_actions/raw_client.py +939 -0
- levelfour/pr_analysis_installations/__init__.py +4 -0
- levelfour/pr_analysis_installations/client.py +470 -0
- levelfour/pr_analysis_installations/raw_client.py +868 -0
- levelfour/providers/__init__.py +34 -0
- levelfour/providers/client.py +1504 -0
- levelfour/providers/raw_client.py +2398 -0
- levelfour/providers/types/__init__.py +36 -0
- levelfour/providers/types/list_spending_breakdown_providers_response.py +11 -0
- levelfour/py.typed +0 -0
- levelfour/recommendations/__init__.py +4 -0
- levelfour/recommendations/client.py +1018 -0
- levelfour/recommendations/raw_client.py +1810 -0
- levelfour/savings/__init__.py +4 -0
- levelfour/savings/client.py +401 -0
- levelfour/savings/raw_client.py +624 -0
- levelfour/spending/__init__.py +34 -0
- levelfour/spending/client.py +437 -0
- levelfour/spending/raw_client.py +684 -0
- levelfour/spending/types/__init__.py +34 -0
- levelfour/spending/types/list_breakdown_spending_response.py +12 -0
- levelfour/types/__init__.py +413 -0
- levelfour/types/accept_terms_data.py +25 -0
- levelfour/types/accept_terms_response.py +27 -0
- levelfour/types/action_request.py +42 -0
- levelfour/types/api_key_created_data.py +28 -0
- levelfour/types/api_key_data.py +27 -0
- levelfour/types/authentication_error.py +5 -0
- levelfour/types/authorization_error.py +5 -0
- levelfour/types/bad_request_error.py +5 -0
- levelfour/types/comparison_item.py +32 -0
- levelfour/types/complete_wizard_data.py +27 -0
- levelfour/types/complete_wizard_response.py +27 -0
- levelfour/types/conflict_error.py +5 -0
- levelfour/types/cost_breakdown_data.py +35 -0
- levelfour/types/cost_breakdown_item.py +71 -0
- levelfour/types/cost_breakdown_raw_data.py +37 -0
- levelfour/types/cost_breakdown_raw_response.py +27 -0
- levelfour/types/cost_breakdown_response.py +27 -0
- levelfour/types/costs_breakdown_chart_data.py +48 -0
- levelfour/types/costs_breakdown_chart_response.py +27 -0
- levelfour/types/costs_breakdown_data_point.py +46 -0
- levelfour/types/costs_breakdown_grouped_chart_data.py +52 -0
- levelfour/types/costs_breakdown_grouped_chart_response.py +27 -0
- levelfour/types/costs_breakdown_grouped_data_point.py +36 -0
- levelfour/types/costs_breakdown_totals.py +41 -0
- levelfour/types/create_api_key_response.py +23 -0
- levelfour/types/daily_spending_breakdown_data.py +42 -0
- levelfour/types/daily_spending_breakdown_response.py +27 -0
- levelfour/types/daily_spending_data_point.py +31 -0
- levelfour/types/dashboard_summary_data.py +72 -0
- levelfour/types/dashboard_summary_response.py +27 -0
- levelfour/types/delete_endpoint_data.py +20 -0
- levelfour/types/delete_endpoint_response.py +23 -0
- levelfour/types/endpoint_data.py +23 -0
- levelfour/types/error_response.py +23 -0
- levelfour/types/error_response_error.py +21 -0
- levelfour/types/evaluation_status_data.py +71 -0
- levelfour/types/evaluation_status_response.py +27 -0
- levelfour/types/execution_log_command.py +21 -0
- levelfour/types/execution_log_entry.py +23 -0
- levelfour/types/execution_step_schema.py +23 -0
- levelfour/types/http_validation_error.py +20 -0
- levelfour/types/implementation_method_data.py +25 -0
- levelfour/types/implementation_method_response.py +27 -0
- levelfour/types/implementation_step.py +27 -0
- levelfour/types/internal_server_error.py +5 -0
- levelfour/types/list_api_keys_data.py +21 -0
- levelfour/types/list_api_keys_response.py +23 -0
- levelfour/types/list_endpoints_response.py +23 -0
- levelfour/types/metric_data_point.py +27 -0
- levelfour/types/metric_series.py +40 -0
- levelfour/types/metric_series_entry.py +25 -0
- levelfour/types/monthly_spending_data.py +27 -0
- levelfour/types/monthly_spending_data_point.py +31 -0
- levelfour/types/monthly_spending_response.py +27 -0
- levelfour/types/not_found_error.py +5 -0
- levelfour/types/pagination_meta.py +51 -0
- levelfour/types/processing_recommendation_item.py +61 -0
- levelfour/types/processing_recommendations_data.py +28 -0
- levelfour/types/processing_recommendations_response.py +27 -0
- levelfour/types/provider.py +46 -0
- levelfour/types/provider_breakdown_data.py +31 -0
- levelfour/types/provider_breakdown_item.py +77 -0
- levelfour/types/provider_breakdown_response.py +27 -0
- levelfour/types/provider_filter_options_data.py +51 -0
- levelfour/types/provider_filter_options_response.py +27 -0
- levelfour/types/provider_potential_savings_summary_data.py +46 -0
- levelfour/types/provider_potential_savings_summary_response.py +27 -0
- levelfour/types/provider_recommendations_summary_data.py +37 -0
- levelfour/types/provider_recommendations_summary_response.py +27 -0
- levelfour/types/provider_saved_summary_data.py +56 -0
- levelfour/types/provider_saved_summary_response.py +27 -0
- levelfour/types/provider_service_breakdown_data.py +65 -0
- levelfour/types/provider_service_breakdown_item.py +72 -0
- levelfour/types/provider_service_breakdown_raw_data.py +62 -0
- levelfour/types/provider_service_breakdown_raw_response.py +27 -0
- levelfour/types/provider_service_breakdown_response.py +27 -0
- levelfour/types/provider_service_costs_breakdown_data.py +62 -0
- levelfour/types/provider_service_costs_breakdown_response.py +27 -0
- levelfour/types/provider_service_costs_data_point.py +36 -0
- levelfour/types/provider_spending.py +61 -0
- levelfour/types/provider_spending_summary_data.py +67 -0
- levelfour/types/provider_spending_summary_response.py +27 -0
- levelfour/types/provider_timeline_data.py +57 -0
- levelfour/types/provider_timeline_response.py +27 -0
- levelfour/types/provider_top_service.py +36 -0
- levelfour/types/providers_summary_data.py +24 -0
- levelfour/types/providers_summary_response.py +27 -0
- levelfour/types/rate_limit_error.py +5 -0
- levelfour/types/recommendation_actions.py +60 -0
- levelfour/types/recommendation_detail.py +42 -0
- levelfour/types/recommendation_detail_response.py +27 -0
- levelfour/types/recommendation_filter_options_data.py +41 -0
- levelfour/types/recommendation_filter_options_response.py +27 -0
- levelfour/types/recommendation_item.py +36 -0
- levelfour/types/recommendation_wizard_data.py +173 -0
- levelfour/types/recommendation_wizard_data_metrics.py +7 -0
- levelfour/types/recommendation_wizard_response.py +27 -0
- levelfour/types/recommendations_breakdown_data.py +26 -0
- levelfour/types/recommendations_breakdown_response.py +27 -0
- levelfour/types/recommendations_overview_data.py +51 -0
- levelfour/types/recommendations_overview_response.py +27 -0
- levelfour/types/register_endpoint_response.py +23 -0
- levelfour/types/resource_change.py +42 -0
- levelfour/types/resource_snapshot.py +21 -0
- levelfour/types/revoke_api_key_data.py +20 -0
- levelfour/types/revoke_api_key_response.py +23 -0
- levelfour/types/risk_assessment.py +29 -0
- levelfour/types/risk_factor.py +27 -0
- levelfour/types/saved_breakdown_data.py +31 -0
- levelfour/types/saved_breakdown_response.py +27 -0
- levelfour/types/saved_by_provider_breakdown_data.py +31 -0
- levelfour/types/saved_by_provider_breakdown_response.py +27 -0
- levelfour/types/saved_by_provider_item.py +76 -0
- levelfour/types/saved_item.py +35 -0
- levelfour/types/saved_provider_summary.py +36 -0
- levelfour/types/saved_summary_data.py +57 -0
- levelfour/types/saved_summary_response.py +27 -0
- levelfour/types/savings_decision_data.py +28 -0
- levelfour/types/savings_decision_response.py +27 -0
- levelfour/types/spending_by_date_item.py +36 -0
- levelfour/types/top_recommendation.py +56 -0
- levelfour/types/trigger_info.py +22 -0
- levelfour/types/update_tag_data.py +20 -0
- levelfour/types/update_tag_response.py +23 -0
- levelfour/types/validation_error.py +24 -0
- levelfour/types/validation_error_loc_item.py +5 -0
- levelfour/webhooks/__init__.py +4 -0
- levelfour/webhooks/client.py +273 -0
- levelfour/webhooks/raw_client.py +483 -0
- levelfour/webhooks/verifier.py +61 -0
- levelfour-0.1.0.dist-info/METADATA +12 -0
- levelfour-0.1.0.dist-info/RECORD +208 -0
- levelfour-0.1.0.dist-info/WHEEL +5 -0
- levelfour-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from json.decoder import JSONDecodeError
|
|
5
|
+
|
|
6
|
+
from ..core.api_error import ApiError
|
|
7
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
8
|
+
from ..core.http_response import AsyncHttpResponse, HttpResponse
|
|
9
|
+
from ..core.jsonable_encoder import jsonable_encoder
|
|
10
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
11
|
+
from ..core.request_options import RequestOptions
|
|
12
|
+
from ..errors.forbidden_error import ForbiddenError
|
|
13
|
+
from ..errors.unauthorized_error import UnauthorizedError
|
|
14
|
+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
|
|
15
|
+
from ..types.authentication_error import AuthenticationError
|
|
16
|
+
from ..types.authorization_error import AuthorizationError
|
|
17
|
+
from ..types.delete_endpoint_response import DeleteEndpointResponse
|
|
18
|
+
from ..types.http_validation_error import HttpValidationError
|
|
19
|
+
from ..types.list_endpoints_response import ListEndpointsResponse
|
|
20
|
+
from ..types.register_endpoint_response import RegisterEndpointResponse
|
|
21
|
+
|
|
22
|
+
# this is used as the default value for optional parameters
|
|
23
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class RawWebhooksClient:
|
|
27
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
28
|
+
self._client_wrapper = client_wrapper
|
|
29
|
+
|
|
30
|
+
def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[ListEndpointsResponse]:
|
|
31
|
+
"""
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
request_options : typing.Optional[RequestOptions]
|
|
35
|
+
Request-specific configuration.
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
HttpResponse[ListEndpointsResponse]
|
|
40
|
+
Successful Response
|
|
41
|
+
"""
|
|
42
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
43
|
+
"api/v1/webhooks/endpoints",
|
|
44
|
+
method="GET",
|
|
45
|
+
request_options=request_options,
|
|
46
|
+
)
|
|
47
|
+
try:
|
|
48
|
+
if 200 <= _response.status_code < 300:
|
|
49
|
+
_data = typing.cast(
|
|
50
|
+
ListEndpointsResponse,
|
|
51
|
+
parse_obj_as(
|
|
52
|
+
type_=ListEndpointsResponse, # type: ignore
|
|
53
|
+
object_=_response.json(),
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
return HttpResponse(response=_response, data=_data)
|
|
57
|
+
if _response.status_code == 401:
|
|
58
|
+
raise UnauthorizedError(
|
|
59
|
+
headers=dict(_response.headers),
|
|
60
|
+
body=typing.cast(
|
|
61
|
+
AuthenticationError,
|
|
62
|
+
parse_obj_as(
|
|
63
|
+
type_=AuthenticationError, # type: ignore
|
|
64
|
+
object_=_response.json(),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
if _response.status_code == 403:
|
|
69
|
+
raise ForbiddenError(
|
|
70
|
+
headers=dict(_response.headers),
|
|
71
|
+
body=typing.cast(
|
|
72
|
+
AuthorizationError,
|
|
73
|
+
parse_obj_as(
|
|
74
|
+
type_=AuthorizationError, # type: ignore
|
|
75
|
+
object_=_response.json(),
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
if _response.status_code == 422:
|
|
80
|
+
raise UnprocessableEntityError(
|
|
81
|
+
headers=dict(_response.headers),
|
|
82
|
+
body=typing.cast(
|
|
83
|
+
HttpValidationError,
|
|
84
|
+
parse_obj_as(
|
|
85
|
+
type_=HttpValidationError, # type: ignore
|
|
86
|
+
object_=_response.json(),
|
|
87
|
+
),
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
_response_json = _response.json()
|
|
91
|
+
except JSONDecodeError:
|
|
92
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
93
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
94
|
+
|
|
95
|
+
def register(
|
|
96
|
+
self,
|
|
97
|
+
*,
|
|
98
|
+
url: str,
|
|
99
|
+
event_types: typing.Sequence[str],
|
|
100
|
+
description: typing.Optional[str] = OMIT,
|
|
101
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
102
|
+
) -> HttpResponse[RegisterEndpointResponse]:
|
|
103
|
+
"""
|
|
104
|
+
Parameters
|
|
105
|
+
----------
|
|
106
|
+
url : str
|
|
107
|
+
Webhook endpoint URL
|
|
108
|
+
|
|
109
|
+
event_types : typing.Sequence[str]
|
|
110
|
+
Event types to subscribe to
|
|
111
|
+
|
|
112
|
+
description : typing.Optional[str]
|
|
113
|
+
|
|
114
|
+
request_options : typing.Optional[RequestOptions]
|
|
115
|
+
Request-specific configuration.
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
HttpResponse[RegisterEndpointResponse]
|
|
120
|
+
Successful Response
|
|
121
|
+
"""
|
|
122
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
123
|
+
"api/v1/webhooks/endpoints",
|
|
124
|
+
method="POST",
|
|
125
|
+
json={
|
|
126
|
+
"url": url,
|
|
127
|
+
"event_types": event_types,
|
|
128
|
+
"description": description,
|
|
129
|
+
},
|
|
130
|
+
headers={
|
|
131
|
+
"content-type": "application/json",
|
|
132
|
+
},
|
|
133
|
+
request_options=request_options,
|
|
134
|
+
omit=OMIT,
|
|
135
|
+
)
|
|
136
|
+
try:
|
|
137
|
+
if 200 <= _response.status_code < 300:
|
|
138
|
+
_data = typing.cast(
|
|
139
|
+
RegisterEndpointResponse,
|
|
140
|
+
parse_obj_as(
|
|
141
|
+
type_=RegisterEndpointResponse, # type: ignore
|
|
142
|
+
object_=_response.json(),
|
|
143
|
+
),
|
|
144
|
+
)
|
|
145
|
+
return HttpResponse(response=_response, data=_data)
|
|
146
|
+
if _response.status_code == 401:
|
|
147
|
+
raise UnauthorizedError(
|
|
148
|
+
headers=dict(_response.headers),
|
|
149
|
+
body=typing.cast(
|
|
150
|
+
AuthenticationError,
|
|
151
|
+
parse_obj_as(
|
|
152
|
+
type_=AuthenticationError, # type: ignore
|
|
153
|
+
object_=_response.json(),
|
|
154
|
+
),
|
|
155
|
+
),
|
|
156
|
+
)
|
|
157
|
+
if _response.status_code == 403:
|
|
158
|
+
raise ForbiddenError(
|
|
159
|
+
headers=dict(_response.headers),
|
|
160
|
+
body=typing.cast(
|
|
161
|
+
AuthorizationError,
|
|
162
|
+
parse_obj_as(
|
|
163
|
+
type_=AuthorizationError, # type: ignore
|
|
164
|
+
object_=_response.json(),
|
|
165
|
+
),
|
|
166
|
+
),
|
|
167
|
+
)
|
|
168
|
+
if _response.status_code == 422:
|
|
169
|
+
raise UnprocessableEntityError(
|
|
170
|
+
headers=dict(_response.headers),
|
|
171
|
+
body=typing.cast(
|
|
172
|
+
HttpValidationError,
|
|
173
|
+
parse_obj_as(
|
|
174
|
+
type_=HttpValidationError, # type: ignore
|
|
175
|
+
object_=_response.json(),
|
|
176
|
+
),
|
|
177
|
+
),
|
|
178
|
+
)
|
|
179
|
+
_response_json = _response.json()
|
|
180
|
+
except JSONDecodeError:
|
|
181
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
182
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
183
|
+
|
|
184
|
+
def delete(
|
|
185
|
+
self, endpoint_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
186
|
+
) -> HttpResponse[DeleteEndpointResponse]:
|
|
187
|
+
"""
|
|
188
|
+
Parameters
|
|
189
|
+
----------
|
|
190
|
+
endpoint_id : str
|
|
191
|
+
Webhook endpoint ID
|
|
192
|
+
|
|
193
|
+
request_options : typing.Optional[RequestOptions]
|
|
194
|
+
Request-specific configuration.
|
|
195
|
+
|
|
196
|
+
Returns
|
|
197
|
+
-------
|
|
198
|
+
HttpResponse[DeleteEndpointResponse]
|
|
199
|
+
Successful Response
|
|
200
|
+
"""
|
|
201
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
202
|
+
f"api/v1/webhooks/endpoints/{jsonable_encoder(endpoint_id)}",
|
|
203
|
+
method="DELETE",
|
|
204
|
+
request_options=request_options,
|
|
205
|
+
)
|
|
206
|
+
try:
|
|
207
|
+
if 200 <= _response.status_code < 300:
|
|
208
|
+
_data = typing.cast(
|
|
209
|
+
DeleteEndpointResponse,
|
|
210
|
+
parse_obj_as(
|
|
211
|
+
type_=DeleteEndpointResponse, # type: ignore
|
|
212
|
+
object_=_response.json(),
|
|
213
|
+
),
|
|
214
|
+
)
|
|
215
|
+
return HttpResponse(response=_response, data=_data)
|
|
216
|
+
if _response.status_code == 401:
|
|
217
|
+
raise UnauthorizedError(
|
|
218
|
+
headers=dict(_response.headers),
|
|
219
|
+
body=typing.cast(
|
|
220
|
+
AuthenticationError,
|
|
221
|
+
parse_obj_as(
|
|
222
|
+
type_=AuthenticationError, # type: ignore
|
|
223
|
+
object_=_response.json(),
|
|
224
|
+
),
|
|
225
|
+
),
|
|
226
|
+
)
|
|
227
|
+
if _response.status_code == 403:
|
|
228
|
+
raise ForbiddenError(
|
|
229
|
+
headers=dict(_response.headers),
|
|
230
|
+
body=typing.cast(
|
|
231
|
+
AuthorizationError,
|
|
232
|
+
parse_obj_as(
|
|
233
|
+
type_=AuthorizationError, # type: ignore
|
|
234
|
+
object_=_response.json(),
|
|
235
|
+
),
|
|
236
|
+
),
|
|
237
|
+
)
|
|
238
|
+
if _response.status_code == 422:
|
|
239
|
+
raise UnprocessableEntityError(
|
|
240
|
+
headers=dict(_response.headers),
|
|
241
|
+
body=typing.cast(
|
|
242
|
+
HttpValidationError,
|
|
243
|
+
parse_obj_as(
|
|
244
|
+
type_=HttpValidationError, # type: ignore
|
|
245
|
+
object_=_response.json(),
|
|
246
|
+
),
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
_response_json = _response.json()
|
|
250
|
+
except JSONDecodeError:
|
|
251
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
252
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class AsyncRawWebhooksClient:
|
|
256
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
257
|
+
self._client_wrapper = client_wrapper
|
|
258
|
+
|
|
259
|
+
async def list(
|
|
260
|
+
self, *, request_options: typing.Optional[RequestOptions] = None
|
|
261
|
+
) -> AsyncHttpResponse[ListEndpointsResponse]:
|
|
262
|
+
"""
|
|
263
|
+
Parameters
|
|
264
|
+
----------
|
|
265
|
+
request_options : typing.Optional[RequestOptions]
|
|
266
|
+
Request-specific configuration.
|
|
267
|
+
|
|
268
|
+
Returns
|
|
269
|
+
-------
|
|
270
|
+
AsyncHttpResponse[ListEndpointsResponse]
|
|
271
|
+
Successful Response
|
|
272
|
+
"""
|
|
273
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
274
|
+
"api/v1/webhooks/endpoints",
|
|
275
|
+
method="GET",
|
|
276
|
+
request_options=request_options,
|
|
277
|
+
)
|
|
278
|
+
try:
|
|
279
|
+
if 200 <= _response.status_code < 300:
|
|
280
|
+
_data = typing.cast(
|
|
281
|
+
ListEndpointsResponse,
|
|
282
|
+
parse_obj_as(
|
|
283
|
+
type_=ListEndpointsResponse, # type: ignore
|
|
284
|
+
object_=_response.json(),
|
|
285
|
+
),
|
|
286
|
+
)
|
|
287
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
288
|
+
if _response.status_code == 401:
|
|
289
|
+
raise UnauthorizedError(
|
|
290
|
+
headers=dict(_response.headers),
|
|
291
|
+
body=typing.cast(
|
|
292
|
+
AuthenticationError,
|
|
293
|
+
parse_obj_as(
|
|
294
|
+
type_=AuthenticationError, # type: ignore
|
|
295
|
+
object_=_response.json(),
|
|
296
|
+
),
|
|
297
|
+
),
|
|
298
|
+
)
|
|
299
|
+
if _response.status_code == 403:
|
|
300
|
+
raise ForbiddenError(
|
|
301
|
+
headers=dict(_response.headers),
|
|
302
|
+
body=typing.cast(
|
|
303
|
+
AuthorizationError,
|
|
304
|
+
parse_obj_as(
|
|
305
|
+
type_=AuthorizationError, # type: ignore
|
|
306
|
+
object_=_response.json(),
|
|
307
|
+
),
|
|
308
|
+
),
|
|
309
|
+
)
|
|
310
|
+
if _response.status_code == 422:
|
|
311
|
+
raise UnprocessableEntityError(
|
|
312
|
+
headers=dict(_response.headers),
|
|
313
|
+
body=typing.cast(
|
|
314
|
+
HttpValidationError,
|
|
315
|
+
parse_obj_as(
|
|
316
|
+
type_=HttpValidationError, # type: ignore
|
|
317
|
+
object_=_response.json(),
|
|
318
|
+
),
|
|
319
|
+
),
|
|
320
|
+
)
|
|
321
|
+
_response_json = _response.json()
|
|
322
|
+
except JSONDecodeError:
|
|
323
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
324
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
325
|
+
|
|
326
|
+
async def register(
|
|
327
|
+
self,
|
|
328
|
+
*,
|
|
329
|
+
url: str,
|
|
330
|
+
event_types: typing.Sequence[str],
|
|
331
|
+
description: typing.Optional[str] = OMIT,
|
|
332
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
333
|
+
) -> AsyncHttpResponse[RegisterEndpointResponse]:
|
|
334
|
+
"""
|
|
335
|
+
Parameters
|
|
336
|
+
----------
|
|
337
|
+
url : str
|
|
338
|
+
Webhook endpoint URL
|
|
339
|
+
|
|
340
|
+
event_types : typing.Sequence[str]
|
|
341
|
+
Event types to subscribe to
|
|
342
|
+
|
|
343
|
+
description : typing.Optional[str]
|
|
344
|
+
|
|
345
|
+
request_options : typing.Optional[RequestOptions]
|
|
346
|
+
Request-specific configuration.
|
|
347
|
+
|
|
348
|
+
Returns
|
|
349
|
+
-------
|
|
350
|
+
AsyncHttpResponse[RegisterEndpointResponse]
|
|
351
|
+
Successful Response
|
|
352
|
+
"""
|
|
353
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
354
|
+
"api/v1/webhooks/endpoints",
|
|
355
|
+
method="POST",
|
|
356
|
+
json={
|
|
357
|
+
"url": url,
|
|
358
|
+
"event_types": event_types,
|
|
359
|
+
"description": description,
|
|
360
|
+
},
|
|
361
|
+
headers={
|
|
362
|
+
"content-type": "application/json",
|
|
363
|
+
},
|
|
364
|
+
request_options=request_options,
|
|
365
|
+
omit=OMIT,
|
|
366
|
+
)
|
|
367
|
+
try:
|
|
368
|
+
if 200 <= _response.status_code < 300:
|
|
369
|
+
_data = typing.cast(
|
|
370
|
+
RegisterEndpointResponse,
|
|
371
|
+
parse_obj_as(
|
|
372
|
+
type_=RegisterEndpointResponse, # type: ignore
|
|
373
|
+
object_=_response.json(),
|
|
374
|
+
),
|
|
375
|
+
)
|
|
376
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
377
|
+
if _response.status_code == 401:
|
|
378
|
+
raise UnauthorizedError(
|
|
379
|
+
headers=dict(_response.headers),
|
|
380
|
+
body=typing.cast(
|
|
381
|
+
AuthenticationError,
|
|
382
|
+
parse_obj_as(
|
|
383
|
+
type_=AuthenticationError, # type: ignore
|
|
384
|
+
object_=_response.json(),
|
|
385
|
+
),
|
|
386
|
+
),
|
|
387
|
+
)
|
|
388
|
+
if _response.status_code == 403:
|
|
389
|
+
raise ForbiddenError(
|
|
390
|
+
headers=dict(_response.headers),
|
|
391
|
+
body=typing.cast(
|
|
392
|
+
AuthorizationError,
|
|
393
|
+
parse_obj_as(
|
|
394
|
+
type_=AuthorizationError, # type: ignore
|
|
395
|
+
object_=_response.json(),
|
|
396
|
+
),
|
|
397
|
+
),
|
|
398
|
+
)
|
|
399
|
+
if _response.status_code == 422:
|
|
400
|
+
raise UnprocessableEntityError(
|
|
401
|
+
headers=dict(_response.headers),
|
|
402
|
+
body=typing.cast(
|
|
403
|
+
HttpValidationError,
|
|
404
|
+
parse_obj_as(
|
|
405
|
+
type_=HttpValidationError, # type: ignore
|
|
406
|
+
object_=_response.json(),
|
|
407
|
+
),
|
|
408
|
+
),
|
|
409
|
+
)
|
|
410
|
+
_response_json = _response.json()
|
|
411
|
+
except JSONDecodeError:
|
|
412
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
413
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
414
|
+
|
|
415
|
+
async def delete(
|
|
416
|
+
self, endpoint_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
417
|
+
) -> AsyncHttpResponse[DeleteEndpointResponse]:
|
|
418
|
+
"""
|
|
419
|
+
Parameters
|
|
420
|
+
----------
|
|
421
|
+
endpoint_id : str
|
|
422
|
+
Webhook endpoint ID
|
|
423
|
+
|
|
424
|
+
request_options : typing.Optional[RequestOptions]
|
|
425
|
+
Request-specific configuration.
|
|
426
|
+
|
|
427
|
+
Returns
|
|
428
|
+
-------
|
|
429
|
+
AsyncHttpResponse[DeleteEndpointResponse]
|
|
430
|
+
Successful Response
|
|
431
|
+
"""
|
|
432
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
433
|
+
f"api/v1/webhooks/endpoints/{jsonable_encoder(endpoint_id)}",
|
|
434
|
+
method="DELETE",
|
|
435
|
+
request_options=request_options,
|
|
436
|
+
)
|
|
437
|
+
try:
|
|
438
|
+
if 200 <= _response.status_code < 300:
|
|
439
|
+
_data = typing.cast(
|
|
440
|
+
DeleteEndpointResponse,
|
|
441
|
+
parse_obj_as(
|
|
442
|
+
type_=DeleteEndpointResponse, # type: ignore
|
|
443
|
+
object_=_response.json(),
|
|
444
|
+
),
|
|
445
|
+
)
|
|
446
|
+
return AsyncHttpResponse(response=_response, data=_data)
|
|
447
|
+
if _response.status_code == 401:
|
|
448
|
+
raise UnauthorizedError(
|
|
449
|
+
headers=dict(_response.headers),
|
|
450
|
+
body=typing.cast(
|
|
451
|
+
AuthenticationError,
|
|
452
|
+
parse_obj_as(
|
|
453
|
+
type_=AuthenticationError, # type: ignore
|
|
454
|
+
object_=_response.json(),
|
|
455
|
+
),
|
|
456
|
+
),
|
|
457
|
+
)
|
|
458
|
+
if _response.status_code == 403:
|
|
459
|
+
raise ForbiddenError(
|
|
460
|
+
headers=dict(_response.headers),
|
|
461
|
+
body=typing.cast(
|
|
462
|
+
AuthorizationError,
|
|
463
|
+
parse_obj_as(
|
|
464
|
+
type_=AuthorizationError, # type: ignore
|
|
465
|
+
object_=_response.json(),
|
|
466
|
+
),
|
|
467
|
+
),
|
|
468
|
+
)
|
|
469
|
+
if _response.status_code == 422:
|
|
470
|
+
raise UnprocessableEntityError(
|
|
471
|
+
headers=dict(_response.headers),
|
|
472
|
+
body=typing.cast(
|
|
473
|
+
HttpValidationError,
|
|
474
|
+
parse_obj_as(
|
|
475
|
+
type_=HttpValidationError, # type: ignore
|
|
476
|
+
object_=_response.json(),
|
|
477
|
+
),
|
|
478
|
+
),
|
|
479
|
+
)
|
|
480
|
+
_response_json = _response.json()
|
|
481
|
+
except JSONDecodeError:
|
|
482
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
|
|
483
|
+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
import json
|
|
7
|
+
import time
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class WebhookVerificationError(Exception):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WebhookVerifier:
|
|
15
|
+
def __init__(self, secret: str):
|
|
16
|
+
if secret.startswith("whsec_"):
|
|
17
|
+
secret = secret[6:]
|
|
18
|
+
self._secret = base64.b64decode(secret)
|
|
19
|
+
|
|
20
|
+
def verify(
|
|
21
|
+
self,
|
|
22
|
+
payload: str | bytes,
|
|
23
|
+
headers: dict[str, str],
|
|
24
|
+
*,
|
|
25
|
+
tolerance_seconds: int = 300,
|
|
26
|
+
) -> dict:
|
|
27
|
+
msg_id = headers.get("webhook-id") or headers.get("svix-id")
|
|
28
|
+
msg_timestamp = headers.get("webhook-timestamp") or headers.get("svix-timestamp")
|
|
29
|
+
msg_signature = headers.get("webhook-signature") or headers.get("svix-signature")
|
|
30
|
+
|
|
31
|
+
if not msg_id or not msg_timestamp or not msg_signature:
|
|
32
|
+
raise WebhookVerificationError("Missing required webhook headers")
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
ts = int(msg_timestamp)
|
|
36
|
+
except ValueError:
|
|
37
|
+
raise WebhookVerificationError("Invalid timestamp")
|
|
38
|
+
|
|
39
|
+
now = int(time.time())
|
|
40
|
+
if abs(now - ts) > tolerance_seconds:
|
|
41
|
+
raise WebhookVerificationError("Timestamp too old or too new")
|
|
42
|
+
|
|
43
|
+
if isinstance(payload, str):
|
|
44
|
+
payload = payload.encode("utf-8")
|
|
45
|
+
|
|
46
|
+
to_sign = f"{msg_id}.{msg_timestamp}.".encode("utf-8") + payload
|
|
47
|
+
expected = base64.b64encode(
|
|
48
|
+
hmac.new(self._secret, to_sign, hashlib.sha256).digest()
|
|
49
|
+
).decode("utf-8")
|
|
50
|
+
|
|
51
|
+
passed = False
|
|
52
|
+
for sig in msg_signature.split(" "):
|
|
53
|
+
sig_value = sig.split(",", 1)[-1] if "," in sig else sig
|
|
54
|
+
if hmac.compare_digest(expected, sig_value):
|
|
55
|
+
passed = True
|
|
56
|
+
break
|
|
57
|
+
|
|
58
|
+
if not passed:
|
|
59
|
+
raise WebhookVerificationError("Invalid signature")
|
|
60
|
+
|
|
61
|
+
return json.loads(payload)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: levelfour
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Requires-Python: >=3.9
|
|
5
|
+
Requires-Dist: httpx>=0.24.0
|
|
6
|
+
Requires-Dist: pydantic>=2.0
|
|
7
|
+
Provides-Extra: fastapi
|
|
8
|
+
Requires-Dist: fastapi>=0.100.0; extra == "fastapi"
|
|
9
|
+
Provides-Extra: django
|
|
10
|
+
Requires-Dist: django>=4.0; extra == "django"
|
|
11
|
+
Provides-Extra: telemetry
|
|
12
|
+
Requires-Dist: opentelemetry-api>=1.20.0; extra == "telemetry"
|