Debian Codegraph @

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