Debian Codegraph @

src/auth0/management/attack_protection/suspicious_ip_throttling/raw_client.py

raw symbols SCIP
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.parse_error import ParsingError
10 from ...core.pydantic_utilities import parse_obj_as
11 from ...core.request_options import RequestOptions
12 from ...core.serialization import convert_and_respect_annotation_metadata
13 from ...errors.bad_request_error import BadRequestError
14 from ...errors.forbidden_error import ForbiddenError
15 from ...errors.too_many_requests_error import TooManyRequestsError
16 from ...errors.unauthorized_error import UnauthorizedError
17 from ...types.get_suspicious_ip_throttling_settings_response_content import (
18 GetSuspiciousIpThrottlingSettingsResponseContent,
19 )
20 from ...types.suspicious_ip_throttling_allowlist import SuspiciousIpThrottlingAllowlist
21 from ...types.suspicious_ip_throttling_shields_enum import SuspiciousIpThrottlingShieldsEnum
22 from ...types.suspicious_ip_throttling_stage import SuspiciousIpThrottlingStage
23 from ...types.update_suspicious_ip_throttling_settings_response_content import (
24 UpdateSuspiciousIpThrottlingSettingsResponseContent,
25 )
26 from pydantic import ValidationError
27
28 # this is used as the default value for optional parameters
29 OMIT = typing.cast(typing.Any, ...)
30
31
32 class RawSuspiciousIpThrottlingClient:
33 def __init__(self, *, client_wrapper: SyncClientWrapper):
34 self._client_wrapper = client_wrapper
35
36 def get(
37 self, *, request_options: typing.Optional[RequestOptions] = None
38 ) -> HttpResponse[GetSuspiciousIpThrottlingSettingsResponseContent]:
39 """
40 Retrieve details of the Suspicious IP Throttling configuration of your tenant.
41
42 Parameters
43 ----------
44 request_options : typing.Optional[RequestOptions]
45 Request-specific configuration.
46
47 Returns
48 -------
49 HttpResponse[GetSuspiciousIpThrottlingSettingsResponseContent]
50 Suspicious IP throttling configuration successfully retrieved.
51 """
52 _response = self._client_wrapper.httpx_client.request(
53 "attack-protection/suspicious-ip-throttling",
54 method="GET",
55 request_options=request_options,
56 )
57 try:
58 if 200 <= _response.status_code < 300:
59 _data = typing.cast(
60 GetSuspiciousIpThrottlingSettingsResponseContent,
61 parse_obj_as(
62 type_=GetSuspiciousIpThrottlingSettingsResponseContent, # type: ignore
63 object_=_response.json(),
64 ),
65 )
66 return HttpResponse(response=_response, data=_data)
67 if _response.status_code == 401:
68 raise UnauthorizedError(
69 headers=dict(_response.headers),
70 body=typing.cast(
71 typing.Any,
72 parse_obj_as(
73 type_=typing.Any, # type: ignore
74 object_=_response.json(),
75 ),
76 ),
77 )
78 if _response.status_code == 403:
79 raise ForbiddenError(
80 headers=dict(_response.headers),
81 body=typing.cast(
82 typing.Any,
83 parse_obj_as(
84 type_=typing.Any, # type: ignore
85 object_=_response.json(),
86 ),
87 ),
88 )
89 if _response.status_code == 429:
90 raise TooManyRequestsError(
91 headers=dict(_response.headers),
92 body=typing.cast(
93 typing.Any,
94 parse_obj_as(
95 type_=typing.Any, # type: ignore
96 object_=_response.json(),
97 ),
98 ),
99 )
100 _response_json = _response.json()
101 except JSONDecodeError:
102 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
103 except ValidationError as e:
104 raise ParsingError(
105 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
106 )
107 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
108
109 def update(
110 self,
111 *,
112 enabled: typing.Optional[bool] = OMIT,
113 shields: typing.Optional[typing.Sequence[SuspiciousIpThrottlingShieldsEnum]] = OMIT,
114 allowlist: typing.Optional[SuspiciousIpThrottlingAllowlist] = OMIT,
115 stage: typing.Optional[SuspiciousIpThrottlingStage] = OMIT,
116 request_options: typing.Optional[RequestOptions] = None,
117 ) -> HttpResponse[UpdateSuspiciousIpThrottlingSettingsResponseContent]:
118 """
119 Update the details of the Suspicious IP Throttling configuration of your tenant.
120
121 Parameters
122 ----------
123 enabled : typing.Optional[bool]
124 Whether or not suspicious IP throttling attack protections are active.
125
126 shields : typing.Optional[typing.Sequence[SuspiciousIpThrottlingShieldsEnum]]
127 Action to take when a suspicious IP throttling threshold is violated.
128 Possible values: <code>block</code>, <code>admin_notification</code>.
129
130 allowlist : typing.Optional[SuspiciousIpThrottlingAllowlist]
131
132 stage : typing.Optional[SuspiciousIpThrottlingStage]
133
134 request_options : typing.Optional[RequestOptions]
135 Request-specific configuration.
136
137 Returns
138 -------
139 HttpResponse[UpdateSuspiciousIpThrottlingSettingsResponseContent]
140 Suspicious IP throttling configuration successfully updated.
141 """
142 _response = self._client_wrapper.httpx_client.request(
143 "attack-protection/suspicious-ip-throttling",
144 method="PATCH",
145 json={
146 "enabled": enabled,
147 "shields": shields,
148 "allowlist": allowlist,
149 "stage": convert_and_respect_annotation_metadata(
150 object_=stage, annotation=SuspiciousIpThrottlingStage, direction="write"
151 ),
152 },
153 headers={
154 "content-type": "application/json",
155 },
156 request_options=request_options,
157 omit=OMIT,
158 )
159 try:
160 if 200 <= _response.status_code < 300:
161 _data = typing.cast(
162 UpdateSuspiciousIpThrottlingSettingsResponseContent,
163 parse_obj_as(
164 type_=UpdateSuspiciousIpThrottlingSettingsResponseContent, # type: ignore
165 object_=_response.json(),
166 ),
167 )
168 return HttpResponse(response=_response, data=_data)
169 if _response.status_code == 400:
170 raise BadRequestError(
171 headers=dict(_response.headers),
172 body=typing.cast(
173 typing.Any,
174 parse_obj_as(
175 type_=typing.Any, # type: ignore
176 object_=_response.json(),
177 ),
178 ),
179 )
180 if _response.status_code == 401:
181 raise UnauthorizedError(
182 headers=dict(_response.headers),
183 body=typing.cast(
184 typing.Any,
185 parse_obj_as(
186 type_=typing.Any, # type: ignore
187 object_=_response.json(),
188 ),
189 ),
190 )
191 if _response.status_code == 403:
192 raise ForbiddenError(
193 headers=dict(_response.headers),
194 body=typing.cast(
195 typing.Any,
196 parse_obj_as(
197 type_=typing.Any, # type: ignore
198 object_=_response.json(),
199 ),
200 ),
201 )
202 if _response.status_code == 429:
203 raise TooManyRequestsError(
204 headers=dict(_response.headers),
205 body=typing.cast(
206 typing.Any,
207 parse_obj_as(
208 type_=typing.Any, # type: ignore
209 object_=_response.json(),
210 ),
211 ),
212 )
213 _response_json = _response.json()
214 except JSONDecodeError:
215 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
216 except ValidationError as e:
217 raise ParsingError(
218 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
219 )
220 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
221
222
223 class AsyncRawSuspiciousIpThrottlingClient:
224 def __init__(self, *, client_wrapper: AsyncClientWrapper):
225 self._client_wrapper = client_wrapper
226
227 async def get(
228 self, *, request_options: typing.Optional[RequestOptions] = None
229 ) -> AsyncHttpResponse[GetSuspiciousIpThrottlingSettingsResponseContent]:
230 """
231 Retrieve details of the Suspicious IP Throttling configuration of your tenant.
232
233 Parameters
234 ----------
235 request_options : typing.Optional[RequestOptions]
236 Request-specific configuration.
237
238 Returns
239 -------
240 AsyncHttpResponse[GetSuspiciousIpThrottlingSettingsResponseContent]
241 Suspicious IP throttling configuration successfully retrieved.
242 """
243 _response = await self._client_wrapper.httpx_client.request(
244 "attack-protection/suspicious-ip-throttling",
245 method="GET",
246 request_options=request_options,
247 )
248 try:
249 if 200 <= _response.status_code < 300:
250 _data = typing.cast(
251 GetSuspiciousIpThrottlingSettingsResponseContent,
252 parse_obj_as(
253 type_=GetSuspiciousIpThrottlingSettingsResponseContent, # type: ignore
254 object_=_response.json(),
255 ),
256 )
257 return AsyncHttpResponse(response=_response, data=_data)
258 if _response.status_code == 401:
259 raise UnauthorizedError(
260 headers=dict(_response.headers),
261 body=typing.cast(
262 typing.Any,
263 parse_obj_as(
264 type_=typing.Any, # type: ignore
265 object_=_response.json(),
266 ),
267 ),
268 )
269 if _response.status_code == 403:
270 raise ForbiddenError(
271 headers=dict(_response.headers),
272 body=typing.cast(
273 typing.Any,
274 parse_obj_as(
275 type_=typing.Any, # type: ignore
276 object_=_response.json(),
277 ),
278 ),
279 )
280 if _response.status_code == 429:
281 raise TooManyRequestsError(
282 headers=dict(_response.headers),
283 body=typing.cast(
284 typing.Any,
285 parse_obj_as(
286 type_=typing.Any, # type: ignore
287 object_=_response.json(),
288 ),
289 ),
290 )
291 _response_json = _response.json()
292 except JSONDecodeError:
293 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
294 except ValidationError as e:
295 raise ParsingError(
296 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
297 )
298 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
299
300 async def update(
301 self,
302 *,
303 enabled: typing.Optional[bool] = OMIT,
304 shields: typing.Optional[typing.Sequence[SuspiciousIpThrottlingShieldsEnum]] = OMIT,
305 allowlist: typing.Optional[SuspiciousIpThrottlingAllowlist] = OMIT,
306 stage: typing.Optional[SuspiciousIpThrottlingStage] = OMIT,
307 request_options: typing.Optional[RequestOptions] = None,
308 ) -> AsyncHttpResponse[UpdateSuspiciousIpThrottlingSettingsResponseContent]:
309 """
310 Update the details of the Suspicious IP Throttling configuration of your tenant.
311
312 Parameters
313 ----------
314 enabled : typing.Optional[bool]
315 Whether or not suspicious IP throttling attack protections are active.
316
317 shields : typing.Optional[typing.Sequence[SuspiciousIpThrottlingShieldsEnum]]
318 Action to take when a suspicious IP throttling threshold is violated.
319 Possible values: <code>block</code>, <code>admin_notification</code>.
320
321 allowlist : typing.Optional[SuspiciousIpThrottlingAllowlist]
322
323 stage : typing.Optional[SuspiciousIpThrottlingStage]
324
325 request_options : typing.Optional[RequestOptions]
326 Request-specific configuration.
327
328 Returns
329 -------
330 AsyncHttpResponse[UpdateSuspiciousIpThrottlingSettingsResponseContent]
331 Suspicious IP throttling configuration successfully updated.
332 """
333 _response = await self._client_wrapper.httpx_client.request(
334 "attack-protection/suspicious-ip-throttling",
335 method="PATCH",
336 json={
337 "enabled": enabled,
338 "shields": shields,
339 "allowlist": allowlist,
340 "stage": convert_and_respect_annotation_metadata(
341 object_=stage, annotation=SuspiciousIpThrottlingStage, direction="write"
342 ),
343 },
344 headers={
345 "content-type": "application/json",
346 },
347 request_options=request_options,
348 omit=OMIT,
349 )
350 try:
351 if 200 <= _response.status_code < 300:
352 _data = typing.cast(
353 UpdateSuspiciousIpThrottlingSettingsResponseContent,
354 parse_obj_as(
355 type_=UpdateSuspiciousIpThrottlingSettingsResponseContent, # type: ignore
356 object_=_response.json(),
357 ),
358 )
359 return AsyncHttpResponse(response=_response, data=_data)
360 if _response.status_code == 400:
361 raise BadRequestError(
362 headers=dict(_response.headers),
363 body=typing.cast(
364 typing.Any,
365 parse_obj_as(
366 type_=typing.Any, # type: ignore
367 object_=_response.json(),
368 ),
369 ),
370 )
371 if _response.status_code == 401:
372 raise UnauthorizedError(
373 headers=dict(_response.headers),
374 body=typing.cast(
375 typing.Any,
376 parse_obj_as(
377 type_=typing.Any, # type: ignore
378 object_=_response.json(),
379 ),
380 ),
381 )
382 if _response.status_code == 403:
383 raise ForbiddenError(
384 headers=dict(_response.headers),
385 body=typing.cast(
386 typing.Any,
387 parse_obj_as(
388 type_=typing.Any, # type: ignore
389 object_=_response.json(),
390 ),
391 ),
392 )
393 if _response.status_code == 429:
394 raise TooManyRequestsError(
395 headers=dict(_response.headers),
396 body=typing.cast(
397 typing.Any,
398 parse_obj_as(
399 type_=typing.Any, # type: ignore
400 object_=_response.json(),
401 ),
402 ),
403 )
404 _response_json = _response.json()
405 except JSONDecodeError:
406 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
407 except ValidationError as e:
408 raise ParsingError(
409 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
410 )
411 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)