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