Debian Codegraph @

src/auth0/management/anomaly/blocks/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.jsonable_encoder import encode_path_param
10 from ...core.parse_error import ParsingError
11 from ...core.pydantic_utilities import parse_obj_as
12 from ...core.request_options import RequestOptions
13 from ...errors.bad_request_error import BadRequestError
14 from ...errors.forbidden_error import ForbiddenError
15 from ...errors.not_found_error import NotFoundError
16 from ...errors.too_many_requests_error import TooManyRequestsError
17 from ...errors.unauthorized_error import UnauthorizedError
18 from ...types.anomaly_ip_format import AnomalyIpFormat
19 from pydantic import ValidationError
20
21
22 class RawBlocksClient:
23 def __init__(self, *, client_wrapper: SyncClientWrapper):
24 self._client_wrapper = client_wrapper
25
26 def check_ip(
27 self, id: AnomalyIpFormat, *, request_options: typing.Optional[RequestOptions] = None
28 ) -> HttpResponse[None]:
29 """
30 Check if the given IP address is blocked via the <a href="https://auth0.com/docs/configure/attack-protection/suspicious-ip-throttling">Suspicious IP Throttling</a> due to multiple suspicious attempts.
31
32 Parameters
33 ----------
34 id : AnomalyIpFormat
35 IP address to check.
36
37 request_options : typing.Optional[RequestOptions]
38 Request-specific configuration.
39
40 Returns
41 -------
42 HttpResponse[None]
43 """
44 _response = self._client_wrapper.httpx_client.request(
45 f"anomaly/blocks/ips/{encode_path_param(id)}",
46 method="GET",
47 request_options=request_options,
48 )
49 try:
50 if 200 <= _response.status_code < 300:
51 return HttpResponse(response=_response, data=None)
52 if _response.status_code == 400:
53 raise BadRequestError(
54 headers=dict(_response.headers),
55 body=typing.cast(
56 typing.Any,
57 parse_obj_as(
58 type_=typing.Any, # type: ignore
59 object_=_response.json(),
60 ),
61 ),
62 )
63 if _response.status_code == 401:
64 raise UnauthorizedError(
65 headers=dict(_response.headers),
66 body=typing.cast(
67 typing.Any,
68 parse_obj_as(
69 type_=typing.Any, # type: ignore
70 object_=_response.json(),
71 ),
72 ),
73 )
74 if _response.status_code == 403:
75 raise ForbiddenError(
76 headers=dict(_response.headers),
77 body=typing.cast(
78 typing.Any,
79 parse_obj_as(
80 type_=typing.Any, # type: ignore
81 object_=_response.json(),
82 ),
83 ),
84 )
85 if _response.status_code == 404:
86 raise NotFoundError(
87 headers=dict(_response.headers),
88 body=typing.cast(
89 typing.Any,
90 parse_obj_as(
91 type_=typing.Any, # type: ignore
92 object_=_response.json(),
93 ),
94 ),
95 )
96 if _response.status_code == 429:
97 raise TooManyRequestsError(
98 headers=dict(_response.headers),
99 body=typing.cast(
100 typing.Any,
101 parse_obj_as(
102 type_=typing.Any, # type: ignore
103 object_=_response.json(),
104 ),
105 ),
106 )
107 _response_json = _response.json()
108 except JSONDecodeError:
109 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
110 except ValidationError as e:
111 raise ParsingError(
112 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
113 )
114 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
115
116 def unblock_ip(
117 self, id: AnomalyIpFormat, *, request_options: typing.Optional[RequestOptions] = None
118 ) -> HttpResponse[None]:
119 """
120 Remove a block imposed by <a href="https://auth0.com/docs/configure/attack-protection/suspicious-ip-throttling">Suspicious IP Throttling</a> for the given IP address.
121
122 Parameters
123 ----------
124 id : AnomalyIpFormat
125 IP address to unblock.
126
127 request_options : typing.Optional[RequestOptions]
128 Request-specific configuration.
129
130 Returns
131 -------
132 HttpResponse[None]
133 """
134 _response = self._client_wrapper.httpx_client.request(
135 f"anomaly/blocks/ips/{encode_path_param(id)}",
136 method="DELETE",
137 request_options=request_options,
138 )
139 try:
140 if 200 <= _response.status_code < 300:
141 return HttpResponse(response=_response, data=None)
142 if _response.status_code == 400:
143 raise BadRequestError(
144 headers=dict(_response.headers),
145 body=typing.cast(
146 typing.Any,
147 parse_obj_as(
148 type_=typing.Any, # type: ignore
149 object_=_response.json(),
150 ),
151 ),
152 )
153 if _response.status_code == 401:
154 raise UnauthorizedError(
155 headers=dict(_response.headers),
156 body=typing.cast(
157 typing.Any,
158 parse_obj_as(
159 type_=typing.Any, # type: ignore
160 object_=_response.json(),
161 ),
162 ),
163 )
164 if _response.status_code == 403:
165 raise ForbiddenError(
166 headers=dict(_response.headers),
167 body=typing.cast(
168 typing.Any,
169 parse_obj_as(
170 type_=typing.Any, # type: ignore
171 object_=_response.json(),
172 ),
173 ),
174 )
175 if _response.status_code == 429:
176 raise TooManyRequestsError(
177 headers=dict(_response.headers),
178 body=typing.cast(
179 typing.Any,
180 parse_obj_as(
181 type_=typing.Any, # type: ignore
182 object_=_response.json(),
183 ),
184 ),
185 )
186 _response_json = _response.json()
187 except JSONDecodeError:
188 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
189 except ValidationError as e:
190 raise ParsingError(
191 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
192 )
193 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
194
195
196 class AsyncRawBlocksClient:
197 def __init__(self, *, client_wrapper: AsyncClientWrapper):
198 self._client_wrapper = client_wrapper
199
200 async def check_ip(
201 self, id: AnomalyIpFormat, *, request_options: typing.Optional[RequestOptions] = None
202 ) -> AsyncHttpResponse[None]:
203 """
204 Check if the given IP address is blocked via the <a href="https://auth0.com/docs/configure/attack-protection/suspicious-ip-throttling">Suspicious IP Throttling</a> due to multiple suspicious attempts.
205
206 Parameters
207 ----------
208 id : AnomalyIpFormat
209 IP address to check.
210
211 request_options : typing.Optional[RequestOptions]
212 Request-specific configuration.
213
214 Returns
215 -------
216 AsyncHttpResponse[None]
217 """
218 _response = await self._client_wrapper.httpx_client.request(
219 f"anomaly/blocks/ips/{encode_path_param(id)}",
220 method="GET",
221 request_options=request_options,
222 )
223 try:
224 if 200 <= _response.status_code < 300:
225 return AsyncHttpResponse(response=_response, data=None)
226 if _response.status_code == 400:
227 raise BadRequestError(
228 headers=dict(_response.headers),
229 body=typing.cast(
230 typing.Any,
231 parse_obj_as(
232 type_=typing.Any, # type: ignore
233 object_=_response.json(),
234 ),
235 ),
236 )
237 if _response.status_code == 401:
238 raise UnauthorizedError(
239 headers=dict(_response.headers),
240 body=typing.cast(
241 typing.Any,
242 parse_obj_as(
243 type_=typing.Any, # type: ignore
244 object_=_response.json(),
245 ),
246 ),
247 )
248 if _response.status_code == 403:
249 raise ForbiddenError(
250 headers=dict(_response.headers),
251 body=typing.cast(
252 typing.Any,
253 parse_obj_as(
254 type_=typing.Any, # type: ignore
255 object_=_response.json(),
256 ),
257 ),
258 )
259 if _response.status_code == 404:
260 raise NotFoundError(
261 headers=dict(_response.headers),
262 body=typing.cast(
263 typing.Any,
264 parse_obj_as(
265 type_=typing.Any, # type: ignore
266 object_=_response.json(),
267 ),
268 ),
269 )
270 if _response.status_code == 429:
271 raise TooManyRequestsError(
272 headers=dict(_response.headers),
273 body=typing.cast(
274 typing.Any,
275 parse_obj_as(
276 type_=typing.Any, # type: ignore
277 object_=_response.json(),
278 ),
279 ),
280 )
281 _response_json = _response.json()
282 except JSONDecodeError:
283 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
284 except ValidationError as e:
285 raise ParsingError(
286 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
287 )
288 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
289
290 async def unblock_ip(
291 self, id: AnomalyIpFormat, *, request_options: typing.Optional[RequestOptions] = None
292 ) -> AsyncHttpResponse[None]:
293 """
294 Remove a block imposed by <a href="https://auth0.com/docs/configure/attack-protection/suspicious-ip-throttling">Suspicious IP Throttling</a> for the given IP address.
295
296 Parameters
297 ----------
298 id : AnomalyIpFormat
299 IP address to unblock.
300
301 request_options : typing.Optional[RequestOptions]
302 Request-specific configuration.
303
304 Returns
305 -------
306 AsyncHttpResponse[None]
307 """
308 _response = await self._client_wrapper.httpx_client.request(
309 f"anomaly/blocks/ips/{encode_path_param(id)}",
310 method="DELETE",
311 request_options=request_options,
312 )
313 try:
314 if 200 <= _response.status_code < 300:
315 return AsyncHttpResponse(response=_response, data=None)
316 if _response.status_code == 400:
317 raise BadRequestError(
318 headers=dict(_response.headers),
319 body=typing.cast(
320 typing.Any,
321 parse_obj_as(
322 type_=typing.Any, # type: ignore
323 object_=_response.json(),
324 ),
325 ),
326 )
327 if _response.status_code == 401:
328 raise UnauthorizedError(
329 headers=dict(_response.headers),
330 body=typing.cast(
331 typing.Any,
332 parse_obj_as(
333 type_=typing.Any, # type: ignore
334 object_=_response.json(),
335 ),
336 ),
337 )
338 if _response.status_code == 403:
339 raise ForbiddenError(
340 headers=dict(_response.headers),
341 body=typing.cast(
342 typing.Any,
343 parse_obj_as(
344 type_=typing.Any, # type: ignore
345 object_=_response.json(),
346 ),
347 ),
348 )
349 if _response.status_code == 429:
350 raise TooManyRequestsError(
351 headers=dict(_response.headers),
352 body=typing.cast(
353 typing.Any,
354 parse_obj_as(
355 type_=typing.Any, # type: ignore
356 object_=_response.json(),
357 ),
358 ),
359 )
360 _response_json = _response.json()
361 except JSONDecodeError:
362 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
363 except ValidationError as e:
364 raise ParsingError(
365 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
366 )
367 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)