| 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.bad_request_error import BadRequestError |
| 14 |
from ...errors.forbidden_error import ForbiddenError |
| 15 |
from ...errors.too_many_requests_error import TooManyRequestsError |
| 16 |
from ...errors.unauthorized_error import UnauthorizedError |
| 17 |
from ...types.assessors_type_enum import AssessorsTypeEnum |
| 18 |
from pydantic import ValidationError |
| 19 |
|
| 20 |
|
| 21 |
OMIT = typing.cast(typing.Any, ...) |
| 22 |
|
| 23 |
|
| 24 |
class RawRiskAssessmentsClient: |
| 25 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 26 |
self._client_wrapper = client_wrapper |
| 27 |
|
| 28 |
def clear( |
| 29 |
self, |
| 30 |
id: str, |
| 31 |
*, |
| 32 |
connection: str, |
| 33 |
assessors: typing.Sequence[AssessorsTypeEnum], |
| 34 |
request_options: typing.Optional[RequestOptions] = None, |
| 35 |
) -> HttpResponse[None]: |
| 36 |
""" |
| 37 |
Clear risk assessment assessors for a specific user |
| 38 |
|
| 39 |
Parameters |
| 40 |
---------- |
| 41 |
id : str |
| 42 |
ID of the user to clear assessors for. |
| 43 |
|
| 44 |
connection : str |
| 45 |
The name of the connection containing the user whose assessors should be cleared. |
| 46 |
|
| 47 |
assessors : typing.Sequence[AssessorsTypeEnum] |
| 48 |
List of assessors to clear. |
| 49 |
|
| 50 |
request_options : typing.Optional[RequestOptions] |
| 51 |
Request-specific configuration. |
| 52 |
|
| 53 |
Returns |
| 54 |
------- |
| 55 |
HttpResponse[None] |
| 56 |
""" |
| 57 |
_response = self._client_wrapper.httpx_client.request( |
| 58 |
f"users/{encode_path_param(id)}/risk-assessments/clear", |
| 59 |
method="POST", |
| 60 |
json={ |
| 61 |
"connection": connection, |
| 62 |
"assessors": assessors, |
| 63 |
}, |
| 64 |
headers={ |
| 65 |
"content-type": "application/json", |
| 66 |
}, |
| 67 |
request_options=request_options, |
| 68 |
omit=OMIT, |
| 69 |
) |
| 70 |
try: |
| 71 |
if 200 <= _response.status_code < 300: |
| 72 |
return HttpResponse(response=_response, data=None) |
| 73 |
if _response.status_code == 400: |
| 74 |
raise BadRequestError( |
| 75 |
headers=dict(_response.headers), |
| 76 |
body=typing.cast( |
| 77 |
typing.Any, |
| 78 |
parse_obj_as( |
| 79 |
type_=typing.Any, |
| 80 |
object_=_response.json(), |
| 81 |
), |
| 82 |
), |
| 83 |
) |
| 84 |
if _response.status_code == 401: |
| 85 |
raise UnauthorizedError( |
| 86 |
headers=dict(_response.headers), |
| 87 |
body=typing.cast( |
| 88 |
typing.Any, |
| 89 |
parse_obj_as( |
| 90 |
type_=typing.Any, |
| 91 |
object_=_response.json(), |
| 92 |
), |
| 93 |
), |
| 94 |
) |
| 95 |
if _response.status_code == 403: |
| 96 |
raise ForbiddenError( |
| 97 |
headers=dict(_response.headers), |
| 98 |
body=typing.cast( |
| 99 |
typing.Any, |
| 100 |
parse_obj_as( |
| 101 |
type_=typing.Any, |
| 102 |
object_=_response.json(), |
| 103 |
), |
| 104 |
), |
| 105 |
) |
| 106 |
if _response.status_code == 429: |
| 107 |
raise TooManyRequestsError( |
| 108 |
headers=dict(_response.headers), |
| 109 |
body=typing.cast( |
| 110 |
typing.Any, |
| 111 |
parse_obj_as( |
| 112 |
type_=typing.Any, |
| 113 |
object_=_response.json(), |
| 114 |
), |
| 115 |
), |
| 116 |
) |
| 117 |
_response_json = _response.json() |
| 118 |
except JSONDecodeError: |
| 119 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 120 |
except ValidationError as e: |
| 121 |
raise ParsingError( |
| 122 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 123 |
) |
| 124 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 125 |
|
| 126 |
|
| 127 |
class AsyncRawRiskAssessmentsClient: |
| 128 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 129 |
self._client_wrapper = client_wrapper |
| 130 |
|
| 131 |
async def clear( |
| 132 |
self, |
| 133 |
id: str, |
| 134 |
*, |
| 135 |
connection: str, |
| 136 |
assessors: typing.Sequence[AssessorsTypeEnum], |
| 137 |
request_options: typing.Optional[RequestOptions] = None, |
| 138 |
) -> AsyncHttpResponse[None]: |
| 139 |
""" |
| 140 |
Clear risk assessment assessors for a specific user |
| 141 |
|
| 142 |
Parameters |
| 143 |
---------- |
| 144 |
id : str |
| 145 |
ID of the user to clear assessors for. |
| 146 |
|
| 147 |
connection : str |
| 148 |
The name of the connection containing the user whose assessors should be cleared. |
| 149 |
|
| 150 |
assessors : typing.Sequence[AssessorsTypeEnum] |
| 151 |
List of assessors to clear. |
| 152 |
|
| 153 |
request_options : typing.Optional[RequestOptions] |
| 154 |
Request-specific configuration. |
| 155 |
|
| 156 |
Returns |
| 157 |
------- |
| 158 |
AsyncHttpResponse[None] |
| 159 |
""" |
| 160 |
_response = await self._client_wrapper.httpx_client.request( |
| 161 |
f"users/{encode_path_param(id)}/risk-assessments/clear", |
| 162 |
method="POST", |
| 163 |
json={ |
| 164 |
"connection": connection, |
| 165 |
"assessors": assessors, |
| 166 |
}, |
| 167 |
headers={ |
| 168 |
"content-type": "application/json", |
| 169 |
}, |
| 170 |
request_options=request_options, |
| 171 |
omit=OMIT, |
| 172 |
) |
| 173 |
try: |
| 174 |
if 200 <= _response.status_code < 300: |
| 175 |
return AsyncHttpResponse(response=_response, data=None) |
| 176 |
if _response.status_code == 400: |
| 177 |
raise BadRequestError( |
| 178 |
headers=dict(_response.headers), |
| 179 |
body=typing.cast( |
| 180 |
typing.Any, |
| 181 |
parse_obj_as( |
| 182 |
type_=typing.Any, |
| 183 |
object_=_response.json(), |
| 184 |
), |
| 185 |
), |
| 186 |
) |
| 187 |
if _response.status_code == 401: |
| 188 |
raise UnauthorizedError( |
| 189 |
headers=dict(_response.headers), |
| 190 |
body=typing.cast( |
| 191 |
typing.Any, |
| 192 |
parse_obj_as( |
| 193 |
type_=typing.Any, |
| 194 |
object_=_response.json(), |
| 195 |
), |
| 196 |
), |
| 197 |
) |
| 198 |
if _response.status_code == 403: |
| 199 |
raise ForbiddenError( |
| 200 |
headers=dict(_response.headers), |
| 201 |
body=typing.cast( |
| 202 |
typing.Any, |
| 203 |
parse_obj_as( |
| 204 |
type_=typing.Any, |
| 205 |
object_=_response.json(), |
| 206 |
), |
| 207 |
), |
| 208 |
) |
| 209 |
if _response.status_code == 429: |
| 210 |
raise TooManyRequestsError( |
| 211 |
headers=dict(_response.headers), |
| 212 |
body=typing.cast( |
| 213 |
typing.Any, |
| 214 |
parse_obj_as( |
| 215 |
type_=typing.Any, |
| 216 |
object_=_response.json(), |
| 217 |
), |
| 218 |
), |
| 219 |
) |
| 220 |
_response_json = _response.json() |
| 221 |
except JSONDecodeError: |
| 222 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 223 |
except ValidationError as e: |
| 224 |
raise ParsingError( |
| 225 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 226 |
) |
| 227 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |