Debian Codegraph @

src/auth0/management/attack_protection/bot_detection/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 ...errors.bad_request_error import BadRequestError
13 from ...errors.forbidden_error import ForbiddenError
14 from ...errors.not_found_error import NotFoundError
15 from ...errors.too_many_requests_error import TooManyRequestsError
16 from ...errors.unauthorized_error import UnauthorizedError
17 from ...types.bot_detection_allowlist import BotDetectionAllowlist
18 from ...types.bot_detection_challenge_policy_password_flow_enum import BotDetectionChallengePolicyPasswordFlowEnum
19 from ...types.bot_detection_challenge_policy_password_reset_flow_enum import (
20 BotDetectionChallengePolicyPasswordResetFlowEnum,
21 )
22 from ...types.bot_detection_challenge_policy_passwordless_flow_enum import (
23 BotDetectionChallengePolicyPasswordlessFlowEnum,
24 )
25 from ...types.bot_detection_level_enum import BotDetectionLevelEnum
26 from ...types.bot_detection_monitoring_mode_enabled import BotDetectionMonitoringModeEnabled
27 from ...types.get_bot_detection_settings_response_content import GetBotDetectionSettingsResponseContent
28 from ...types.update_bot_detection_settings_response_content import UpdateBotDetectionSettingsResponseContent
29 from pydantic import ValidationError
30
31 # this is used as the default value for optional parameters
32 OMIT = typing.cast(typing.Any, ...)
33
34
35 class RawBotDetectionClient:
36 def __init__(self, *, client_wrapper: SyncClientWrapper):
37 self._client_wrapper = client_wrapper
38
39 def get(
40 self, *, request_options: typing.Optional[RequestOptions] = None
41 ) -> HttpResponse[GetBotDetectionSettingsResponseContent]:
42 """
43 Get the Bot Detection configuration of your tenant.
44
45 Parameters
46 ----------
47 request_options : typing.Optional[RequestOptions]
48 Request-specific configuration.
49
50 Returns
51 -------
52 HttpResponse[GetBotDetectionSettingsResponseContent]
53 Bot detection configuration retrieved successfully.
54 """
55 _response = self._client_wrapper.httpx_client.request(
56 "attack-protection/bot-detection",
57 method="GET",
58 request_options=request_options,
59 )
60 try:
61 if 200 <= _response.status_code < 300:
62 _data = typing.cast(
63 GetBotDetectionSettingsResponseContent,
64 parse_obj_as(
65 type_=GetBotDetectionSettingsResponseContent, # type: ignore
66 object_=_response.json(),
67 ),
68 )
69 return HttpResponse(response=_response, data=_data)
70 if _response.status_code == 401:
71 raise UnauthorizedError(
72 headers=dict(_response.headers),
73 body=typing.cast(
74 typing.Any,
75 parse_obj_as(
76 type_=typing.Any, # type: ignore
77 object_=_response.json(),
78 ),
79 ),
80 )
81 if _response.status_code == 403:
82 raise ForbiddenError(
83 headers=dict(_response.headers),
84 body=typing.cast(
85 typing.Any,
86 parse_obj_as(
87 type_=typing.Any, # type: ignore
88 object_=_response.json(),
89 ),
90 ),
91 )
92 if _response.status_code == 404:
93 raise NotFoundError(
94 headers=dict(_response.headers),
95 body=typing.cast(
96 typing.Any,
97 parse_obj_as(
98 type_=typing.Any, # type: ignore
99 object_=_response.json(),
100 ),
101 ),
102 )
103 if _response.status_code == 429:
104 raise TooManyRequestsError(
105 headers=dict(_response.headers),
106 body=typing.cast(
107 typing.Any,
108 parse_obj_as(
109 type_=typing.Any, # type: ignore
110 object_=_response.json(),
111 ),
112 ),
113 )
114 _response_json = _response.json()
115 except JSONDecodeError:
116 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
117 except ValidationError as e:
118 raise ParsingError(
119 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
120 )
121 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
122
123 def update(
124 self,
125 *,
126 bot_detection_level: typing.Optional[BotDetectionLevelEnum] = OMIT,
127 challenge_password_policy: typing.Optional[BotDetectionChallengePolicyPasswordFlowEnum] = OMIT,
128 challenge_passwordless_policy: typing.Optional[BotDetectionChallengePolicyPasswordlessFlowEnum] = OMIT,
129 challenge_password_reset_policy: typing.Optional[BotDetectionChallengePolicyPasswordResetFlowEnum] = OMIT,
130 allowlist: typing.Optional[BotDetectionAllowlist] = OMIT,
131 monitoring_mode_enabled: typing.Optional[BotDetectionMonitoringModeEnabled] = OMIT,
132 request_options: typing.Optional[RequestOptions] = None,
133 ) -> HttpResponse[UpdateBotDetectionSettingsResponseContent]:
134 """
135 Update the Bot Detection configuration of your tenant.
136
137 Parameters
138 ----------
139 bot_detection_level : typing.Optional[BotDetectionLevelEnum]
140
141 challenge_password_policy : typing.Optional[BotDetectionChallengePolicyPasswordFlowEnum]
142
143 challenge_passwordless_policy : typing.Optional[BotDetectionChallengePolicyPasswordlessFlowEnum]
144
145 challenge_password_reset_policy : typing.Optional[BotDetectionChallengePolicyPasswordResetFlowEnum]
146
147 allowlist : typing.Optional[BotDetectionAllowlist]
148
149 monitoring_mode_enabled : typing.Optional[BotDetectionMonitoringModeEnabled]
150
151 request_options : typing.Optional[RequestOptions]
152 Request-specific configuration.
153
154 Returns
155 -------
156 HttpResponse[UpdateBotDetectionSettingsResponseContent]
157 Bot detection configuration successfully updated.
158 """
159 _response = self._client_wrapper.httpx_client.request(
160 "attack-protection/bot-detection",
161 method="PATCH",
162 json={
163 "bot_detection_level": bot_detection_level,
164 "challenge_password_policy": challenge_password_policy,
165 "challenge_passwordless_policy": challenge_passwordless_policy,
166 "challenge_password_reset_policy": challenge_password_reset_policy,
167 "allowlist": allowlist,
168 "monitoring_mode_enabled": monitoring_mode_enabled,
169 },
170 headers={
171 "content-type": "application/json",
172 },
173 request_options=request_options,
174 omit=OMIT,
175 )
176 try:
177 if 200 <= _response.status_code < 300:
178 _data = typing.cast(
179 UpdateBotDetectionSettingsResponseContent,
180 parse_obj_as(
181 type_=UpdateBotDetectionSettingsResponseContent, # type: ignore
182 object_=_response.json(),
183 ),
184 )
185 return HttpResponse(response=_response, data=_data)
186 if _response.status_code == 400:
187 raise BadRequestError(
188 headers=dict(_response.headers),
189 body=typing.cast(
190 typing.Any,
191 parse_obj_as(
192 type_=typing.Any, # type: ignore
193 object_=_response.json(),
194 ),
195 ),
196 )
197 if _response.status_code == 401:
198 raise UnauthorizedError(
199 headers=dict(_response.headers),
200 body=typing.cast(
201 typing.Any,
202 parse_obj_as(
203 type_=typing.Any, # type: ignore
204 object_=_response.json(),
205 ),
206 ),
207 )
208 if _response.status_code == 403:
209 raise ForbiddenError(
210 headers=dict(_response.headers),
211 body=typing.cast(
212 typing.Any,
213 parse_obj_as(
214 type_=typing.Any, # type: ignore
215 object_=_response.json(),
216 ),
217 ),
218 )
219 if _response.status_code == 404:
220 raise NotFoundError(
221 headers=dict(_response.headers),
222 body=typing.cast(
223 typing.Any,
224 parse_obj_as(
225 type_=typing.Any, # type: ignore
226 object_=_response.json(),
227 ),
228 ),
229 )
230 if _response.status_code == 429:
231 raise TooManyRequestsError(
232 headers=dict(_response.headers),
233 body=typing.cast(
234 typing.Any,
235 parse_obj_as(
236 type_=typing.Any, # type: ignore
237 object_=_response.json(),
238 ),
239 ),
240 )
241 _response_json = _response.json()
242 except JSONDecodeError:
243 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
244 except ValidationError as e:
245 raise ParsingError(
246 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
247 )
248 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
249
250
251 class AsyncRawBotDetectionClient:
252 def __init__(self, *, client_wrapper: AsyncClientWrapper):
253 self._client_wrapper = client_wrapper
254
255 async def get(
256 self, *, request_options: typing.Optional[RequestOptions] = None
257 ) -> AsyncHttpResponse[GetBotDetectionSettingsResponseContent]:
258 """
259 Get the Bot Detection configuration of your tenant.
260
261 Parameters
262 ----------
263 request_options : typing.Optional[RequestOptions]
264 Request-specific configuration.
265
266 Returns
267 -------
268 AsyncHttpResponse[GetBotDetectionSettingsResponseContent]
269 Bot detection configuration retrieved successfully.
270 """
271 _response = await self._client_wrapper.httpx_client.request(
272 "attack-protection/bot-detection",
273 method="GET",
274 request_options=request_options,
275 )
276 try:
277 if 200 <= _response.status_code < 300:
278 _data = typing.cast(
279 GetBotDetectionSettingsResponseContent,
280 parse_obj_as(
281 type_=GetBotDetectionSettingsResponseContent, # type: ignore
282 object_=_response.json(),
283 ),
284 )
285 return AsyncHttpResponse(response=_response, data=_data)
286 if _response.status_code == 401:
287 raise UnauthorizedError(
288 headers=dict(_response.headers),
289 body=typing.cast(
290 typing.Any,
291 parse_obj_as(
292 type_=typing.Any, # type: ignore
293 object_=_response.json(),
294 ),
295 ),
296 )
297 if _response.status_code == 403:
298 raise ForbiddenError(
299 headers=dict(_response.headers),
300 body=typing.cast(
301 typing.Any,
302 parse_obj_as(
303 type_=typing.Any, # type: ignore
304 object_=_response.json(),
305 ),
306 ),
307 )
308 if _response.status_code == 404:
309 raise NotFoundError(
310 headers=dict(_response.headers),
311 body=typing.cast(
312 typing.Any,
313 parse_obj_as(
314 type_=typing.Any, # type: ignore
315 object_=_response.json(),
316 ),
317 ),
318 )
319 if _response.status_code == 429:
320 raise TooManyRequestsError(
321 headers=dict(_response.headers),
322 body=typing.cast(
323 typing.Any,
324 parse_obj_as(
325 type_=typing.Any, # type: ignore
326 object_=_response.json(),
327 ),
328 ),
329 )
330 _response_json = _response.json()
331 except JSONDecodeError:
332 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
333 except ValidationError as e:
334 raise ParsingError(
335 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
336 )
337 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
338
339 async def update(
340 self,
341 *,
342 bot_detection_level: typing.Optional[BotDetectionLevelEnum] = OMIT,
343 challenge_password_policy: typing.Optional[BotDetectionChallengePolicyPasswordFlowEnum] = OMIT,
344 challenge_passwordless_policy: typing.Optional[BotDetectionChallengePolicyPasswordlessFlowEnum] = OMIT,
345 challenge_password_reset_policy: typing.Optional[BotDetectionChallengePolicyPasswordResetFlowEnum] = OMIT,
346 allowlist: typing.Optional[BotDetectionAllowlist] = OMIT,
347 monitoring_mode_enabled: typing.Optional[BotDetectionMonitoringModeEnabled] = OMIT,
348 request_options: typing.Optional[RequestOptions] = None,
349 ) -> AsyncHttpResponse[UpdateBotDetectionSettingsResponseContent]:
350 """
351 Update the Bot Detection configuration of your tenant.
352
353 Parameters
354 ----------
355 bot_detection_level : typing.Optional[BotDetectionLevelEnum]
356
357 challenge_password_policy : typing.Optional[BotDetectionChallengePolicyPasswordFlowEnum]
358
359 challenge_passwordless_policy : typing.Optional[BotDetectionChallengePolicyPasswordlessFlowEnum]
360
361 challenge_password_reset_policy : typing.Optional[BotDetectionChallengePolicyPasswordResetFlowEnum]
362
363 allowlist : typing.Optional[BotDetectionAllowlist]
364
365 monitoring_mode_enabled : typing.Optional[BotDetectionMonitoringModeEnabled]
366
367 request_options : typing.Optional[RequestOptions]
368 Request-specific configuration.
369
370 Returns
371 -------
372 AsyncHttpResponse[UpdateBotDetectionSettingsResponseContent]
373 Bot detection configuration successfully updated.
374 """
375 _response = await self._client_wrapper.httpx_client.request(
376 "attack-protection/bot-detection",
377 method="PATCH",
378 json={
379 "bot_detection_level": bot_detection_level,
380 "challenge_password_policy": challenge_password_policy,
381 "challenge_passwordless_policy": challenge_passwordless_policy,
382 "challenge_password_reset_policy": challenge_password_reset_policy,
383 "allowlist": allowlist,
384 "monitoring_mode_enabled": monitoring_mode_enabled,
385 },
386 headers={
387 "content-type": "application/json",
388 },
389 request_options=request_options,
390 omit=OMIT,
391 )
392 try:
393 if 200 <= _response.status_code < 300:
394 _data = typing.cast(
395 UpdateBotDetectionSettingsResponseContent,
396 parse_obj_as(
397 type_=UpdateBotDetectionSettingsResponseContent, # type: ignore
398 object_=_response.json(),
399 ),
400 )
401 return AsyncHttpResponse(response=_response, data=_data)
402 if _response.status_code == 400:
403 raise BadRequestError(
404 headers=dict(_response.headers),
405 body=typing.cast(
406 typing.Any,
407 parse_obj_as(
408 type_=typing.Any, # type: ignore
409 object_=_response.json(),
410 ),
411 ),
412 )
413 if _response.status_code == 401:
414 raise UnauthorizedError(
415 headers=dict(_response.headers),
416 body=typing.cast(
417 typing.Any,
418 parse_obj_as(
419 type_=typing.Any, # type: ignore
420 object_=_response.json(),
421 ),
422 ),
423 )
424 if _response.status_code == 403:
425 raise ForbiddenError(
426 headers=dict(_response.headers),
427 body=typing.cast(
428 typing.Any,
429 parse_obj_as(
430 type_=typing.Any, # type: ignore
431 object_=_response.json(),
432 ),
433 ),
434 )
435 if _response.status_code == 404:
436 raise NotFoundError(
437 headers=dict(_response.headers),
438 body=typing.cast(
439 typing.Any,
440 parse_obj_as(
441 type_=typing.Any, # type: ignore
442 object_=_response.json(),
443 ),
444 ),
445 )
446 if _response.status_code == 429:
447 raise TooManyRequestsError(
448 headers=dict(_response.headers),
449 body=typing.cast(
450 typing.Any,
451 parse_obj_as(
452 type_=typing.Any, # type: ignore
453 object_=_response.json(),
454 ),
455 ),
456 )
457 _response_json = _response.json()
458 except JSONDecodeError:
459 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
460 except ValidationError as e:
461 raise ParsingError(
462 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
463 )
464 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)