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