| 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.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.breached_password_detection_admin_notification_frequency_enum import ( |
| 18 |
BreachedPasswordDetectionAdminNotificationFrequencyEnum, |
| 19 |
) |
| 20 |
from ...types.breached_password_detection_method_enum import BreachedPasswordDetectionMethodEnum |
| 21 |
from ...types.breached_password_detection_shields_enum import BreachedPasswordDetectionShieldsEnum |
| 22 |
from ...types.breached_password_detection_stage import BreachedPasswordDetectionStage |
| 23 |
from ...types.get_breached_password_detection_settings_response_content import ( |
| 24 |
GetBreachedPasswordDetectionSettingsResponseContent, |
| 25 |
) |
| 26 |
from ...types.update_breached_password_detection_settings_response_content import ( |
| 27 |
UpdateBreachedPasswordDetectionSettingsResponseContent, |
| 28 |
) |
| 29 |
from pydantic import ValidationError |
| 30 |
|
| 31 |
|
| 32 |
OMIT = typing.cast(typing.Any, ...) |
| 33 |
|
| 34 |
|
| 35 |
class RawBreachedPasswordDetectionClient: |
| 36 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 37 |
self._client_wrapper = client_wrapper |
| 38 |
|
| 39 |
def get( |
| 40 |
self, *, request_options: typing.Optional[RequestOptions] = None |
| 41 |
) -> HttpResponse[GetBreachedPasswordDetectionSettingsResponseContent]: |
| 42 |
""" |
| 43 |
Retrieve details of the Breached Password Detection configuration of your tenant. |
| 44 |
|
| 45 |
Parameters |
| 46 |
---------- |
| 47 |
request_options : typing.Optional[RequestOptions] |
| 48 |
Request-specific configuration. |
| 49 |
|
| 50 |
Returns |
| 51 |
------- |
| 52 |
HttpResponse[GetBreachedPasswordDetectionSettingsResponseContent] |
| 53 |
Breached password detection settings successfully retrieved. |
| 54 |
""" |
| 55 |
_response = self._client_wrapper.httpx_client.request( |
| 56 |
"attack-protection/breached-password-detection", |
| 57 |
method="GET", |
| 58 |
request_options=request_options, |
| 59 |
) |
| 60 |
try: |
| 61 |
if 200 <= _response.status_code < 300: |
| 62 |
_data = typing.cast( |
| 63 |
GetBreachedPasswordDetectionSettingsResponseContent, |
| 64 |
parse_obj_as( |
| 65 |
type_=GetBreachedPasswordDetectionSettingsResponseContent, |
| 66 |
object_=_response.json(), |
| 67 |
), |
| 68 |
) |
| 69 |
return HttpResponse(response=_response, data=_data) |
| 70 |
if _response.status_code == 401: |
| 71 |
raise UnauthorizedError( |
| 72 |
headers=dict(_response.headers), |
| 73 |
body=typing.cast( |
| 74 |
typing.Any, |
| 75 |
parse_obj_as( |
| 76 |
type_=typing.Any, |
| 77 |
object_=_response.json(), |
| 78 |
), |
| 79 |
), |
| 80 |
) |
| 81 |
if _response.status_code == 403: |
| 82 |
raise ForbiddenError( |
| 83 |
headers=dict(_response.headers), |
| 84 |
body=typing.cast( |
| 85 |
typing.Any, |
| 86 |
parse_obj_as( |
| 87 |
type_=typing.Any, |
| 88 |
object_=_response.json(), |
| 89 |
), |
| 90 |
), |
| 91 |
) |
| 92 |
if _response.status_code == 429: |
| 93 |
raise TooManyRequestsError( |
| 94 |
headers=dict(_response.headers), |
| 95 |
body=typing.cast( |
| 96 |
typing.Any, |
| 97 |
parse_obj_as( |
| 98 |
type_=typing.Any, |
| 99 |
object_=_response.json(), |
| 100 |
), |
| 101 |
), |
| 102 |
) |
| 103 |
_response_json = _response.json() |
| 104 |
except JSONDecodeError: |
| 105 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 106 |
except ValidationError as e: |
| 107 |
raise ParsingError( |
| 108 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 109 |
) |
| 110 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 111 |
|
| 112 |
def update( |
| 113 |
self, |
| 114 |
*, |
| 115 |
enabled: typing.Optional[bool] = OMIT, |
| 116 |
shields: typing.Optional[typing.Sequence[BreachedPasswordDetectionShieldsEnum]] = OMIT, |
| 117 |
admin_notification_frequency: typing.Optional[ |
| 118 |
typing.Sequence[BreachedPasswordDetectionAdminNotificationFrequencyEnum] |
| 119 |
] = OMIT, |
| 120 |
method: typing.Optional[BreachedPasswordDetectionMethodEnum] = OMIT, |
| 121 |
stage: typing.Optional[BreachedPasswordDetectionStage] = OMIT, |
| 122 |
request_options: typing.Optional[RequestOptions] = None, |
| 123 |
) -> HttpResponse[UpdateBreachedPasswordDetectionSettingsResponseContent]: |
| 124 |
""" |
| 125 |
Update details of the Breached Password Detection configuration of your tenant. |
| 126 |
|
| 127 |
Parameters |
| 128 |
---------- |
| 129 |
enabled : typing.Optional[bool] |
| 130 |
Whether or not breached password detection is active. |
| 131 |
|
| 132 |
shields : typing.Optional[typing.Sequence[BreachedPasswordDetectionShieldsEnum]] |
| 133 |
Action to take when a breached password is detected during a login. |
| 134 |
Possible values: <code>block</code>, <code>user_notification</code>, <code>admin_notification</code>. |
| 135 |
|
| 136 |
admin_notification_frequency : typing.Optional[typing.Sequence[BreachedPasswordDetectionAdminNotificationFrequencyEnum]] |
| 137 |
When "admin_notification" is enabled, determines how often email notifications are sent. |
| 138 |
Possible values: <code>immediately</code>, <code>daily</code>, <code>weekly</code>, <code>monthly</code>. |
| 139 |
|
| 140 |
method : typing.Optional[BreachedPasswordDetectionMethodEnum] |
| 141 |
|
| 142 |
stage : typing.Optional[BreachedPasswordDetectionStage] |
| 143 |
|
| 144 |
request_options : typing.Optional[RequestOptions] |
| 145 |
Request-specific configuration. |
| 146 |
|
| 147 |
Returns |
| 148 |
------- |
| 149 |
HttpResponse[UpdateBreachedPasswordDetectionSettingsResponseContent] |
| 150 |
Breached password detection settings successfully updated. |
| 151 |
""" |
| 152 |
_response = self._client_wrapper.httpx_client.request( |
| 153 |
"attack-protection/breached-password-detection", |
| 154 |
method="PATCH", |
| 155 |
json={ |
| 156 |
"enabled": enabled, |
| 157 |
"shields": shields, |
| 158 |
"admin_notification_frequency": admin_notification_frequency, |
| 159 |
"method": method, |
| 160 |
"stage": convert_and_respect_annotation_metadata( |
| 161 |
object_=stage, annotation=BreachedPasswordDetectionStage, direction="write" |
| 162 |
), |
| 163 |
}, |
| 164 |
headers={ |
| 165 |
"content-type": "application/json", |
| 166 |
}, |
| 167 |
request_options=request_options, |
| 168 |
omit=OMIT, |
| 169 |
) |
| 170 |
try: |
| 171 |
if 200 <= _response.status_code < 300: |
| 172 |
_data = typing.cast( |
| 173 |
UpdateBreachedPasswordDetectionSettingsResponseContent, |
| 174 |
parse_obj_as( |
| 175 |
type_=UpdateBreachedPasswordDetectionSettingsResponseContent, |
| 176 |
object_=_response.json(), |
| 177 |
), |
| 178 |
) |
| 179 |
return HttpResponse(response=_response, data=_data) |
| 180 |
if _response.status_code == 400: |
| 181 |
raise BadRequestError( |
| 182 |
headers=dict(_response.headers), |
| 183 |
body=typing.cast( |
| 184 |
typing.Any, |
| 185 |
parse_obj_as( |
| 186 |
type_=typing.Any, |
| 187 |
object_=_response.json(), |
| 188 |
), |
| 189 |
), |
| 190 |
) |
| 191 |
if _response.status_code == 401: |
| 192 |
raise UnauthorizedError( |
| 193 |
headers=dict(_response.headers), |
| 194 |
body=typing.cast( |
| 195 |
typing.Any, |
| 196 |
parse_obj_as( |
| 197 |
type_=typing.Any, |
| 198 |
object_=_response.json(), |
| 199 |
), |
| 200 |
), |
| 201 |
) |
| 202 |
if _response.status_code == 403: |
| 203 |
raise ForbiddenError( |
| 204 |
headers=dict(_response.headers), |
| 205 |
body=typing.cast( |
| 206 |
typing.Any, |
| 207 |
parse_obj_as( |
| 208 |
type_=typing.Any, |
| 209 |
object_=_response.json(), |
| 210 |
), |
| 211 |
), |
| 212 |
) |
| 213 |
if _response.status_code == 429: |
| 214 |
raise TooManyRequestsError( |
| 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 |
_response_json = _response.json() |
| 225 |
except JSONDecodeError: |
| 226 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 227 |
except ValidationError as e: |
| 228 |
raise ParsingError( |
| 229 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 230 |
) |
| 231 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 232 |
|
| 233 |
|
| 234 |
class AsyncRawBreachedPasswordDetectionClient: |
| 235 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 236 |
self._client_wrapper = client_wrapper |
| 237 |
|
| 238 |
async def get( |
| 239 |
self, *, request_options: typing.Optional[RequestOptions] = None |
| 240 |
) -> AsyncHttpResponse[GetBreachedPasswordDetectionSettingsResponseContent]: |
| 241 |
""" |
| 242 |
Retrieve details of the Breached Password Detection configuration of your tenant. |
| 243 |
|
| 244 |
Parameters |
| 245 |
---------- |
| 246 |
request_options : typing.Optional[RequestOptions] |
| 247 |
Request-specific configuration. |
| 248 |
|
| 249 |
Returns |
| 250 |
------- |
| 251 |
AsyncHttpResponse[GetBreachedPasswordDetectionSettingsResponseContent] |
| 252 |
Breached password detection settings successfully retrieved. |
| 253 |
""" |
| 254 |
_response = await self._client_wrapper.httpx_client.request( |
| 255 |
"attack-protection/breached-password-detection", |
| 256 |
method="GET", |
| 257 |
request_options=request_options, |
| 258 |
) |
| 259 |
try: |
| 260 |
if 200 <= _response.status_code < 300: |
| 261 |
_data = typing.cast( |
| 262 |
GetBreachedPasswordDetectionSettingsResponseContent, |
| 263 |
parse_obj_as( |
| 264 |
type_=GetBreachedPasswordDetectionSettingsResponseContent, |
| 265 |
object_=_response.json(), |
| 266 |
), |
| 267 |
) |
| 268 |
return AsyncHttpResponse(response=_response, data=_data) |
| 269 |
if _response.status_code == 401: |
| 270 |
raise UnauthorizedError( |
| 271 |
headers=dict(_response.headers), |
| 272 |
body=typing.cast( |
| 273 |
typing.Any, |
| 274 |
parse_obj_as( |
| 275 |
type_=typing.Any, |
| 276 |
object_=_response.json(), |
| 277 |
), |
| 278 |
), |
| 279 |
) |
| 280 |
if _response.status_code == 403: |
| 281 |
raise ForbiddenError( |
| 282 |
headers=dict(_response.headers), |
| 283 |
body=typing.cast( |
| 284 |
typing.Any, |
| 285 |
parse_obj_as( |
| 286 |
type_=typing.Any, |
| 287 |
object_=_response.json(), |
| 288 |
), |
| 289 |
), |
| 290 |
) |
| 291 |
if _response.status_code == 429: |
| 292 |
raise TooManyRequestsError( |
| 293 |
headers=dict(_response.headers), |
| 294 |
body=typing.cast( |
| 295 |
typing.Any, |
| 296 |
parse_obj_as( |
| 297 |
type_=typing.Any, |
| 298 |
object_=_response.json(), |
| 299 |
), |
| 300 |
), |
| 301 |
) |
| 302 |
_response_json = _response.json() |
| 303 |
except JSONDecodeError: |
| 304 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 305 |
except ValidationError as e: |
| 306 |
raise ParsingError( |
| 307 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 308 |
) |
| 309 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 310 |
|
| 311 |
async def update( |
| 312 |
self, |
| 313 |
*, |
| 314 |
enabled: typing.Optional[bool] = OMIT, |
| 315 |
shields: typing.Optional[typing.Sequence[BreachedPasswordDetectionShieldsEnum]] = OMIT, |
| 316 |
admin_notification_frequency: typing.Optional[ |
| 317 |
typing.Sequence[BreachedPasswordDetectionAdminNotificationFrequencyEnum] |
| 318 |
] = OMIT, |
| 319 |
method: typing.Optional[BreachedPasswordDetectionMethodEnum] = OMIT, |
| 320 |
stage: typing.Optional[BreachedPasswordDetectionStage] = OMIT, |
| 321 |
request_options: typing.Optional[RequestOptions] = None, |
| 322 |
) -> AsyncHttpResponse[UpdateBreachedPasswordDetectionSettingsResponseContent]: |
| 323 |
""" |
| 324 |
Update details of the Breached Password Detection configuration of your tenant. |
| 325 |
|
| 326 |
Parameters |
| 327 |
---------- |
| 328 |
enabled : typing.Optional[bool] |
| 329 |
Whether or not breached password detection is active. |
| 330 |
|
| 331 |
shields : typing.Optional[typing.Sequence[BreachedPasswordDetectionShieldsEnum]] |
| 332 |
Action to take when a breached password is detected during a login. |
| 333 |
Possible values: <code>block</code>, <code>user_notification</code>, <code>admin_notification</code>. |
| 334 |
|
| 335 |
admin_notification_frequency : typing.Optional[typing.Sequence[BreachedPasswordDetectionAdminNotificationFrequencyEnum]] |
| 336 |
When "admin_notification" is enabled, determines how often email notifications are sent. |
| 337 |
Possible values: <code>immediately</code>, <code>daily</code>, <code>weekly</code>, <code>monthly</code>. |
| 338 |
|
| 339 |
method : typing.Optional[BreachedPasswordDetectionMethodEnum] |
| 340 |
|
| 341 |
stage : typing.Optional[BreachedPasswordDetectionStage] |
| 342 |
|
| 343 |
request_options : typing.Optional[RequestOptions] |
| 344 |
Request-specific configuration. |
| 345 |
|
| 346 |
Returns |
| 347 |
------- |
| 348 |
AsyncHttpResponse[UpdateBreachedPasswordDetectionSettingsResponseContent] |
| 349 |
Breached password detection settings successfully updated. |
| 350 |
""" |
| 351 |
_response = await self._client_wrapper.httpx_client.request( |
| 352 |
"attack-protection/breached-password-detection", |
| 353 |
method="PATCH", |
| 354 |
json={ |
| 355 |
"enabled": enabled, |
| 356 |
"shields": shields, |
| 357 |
"admin_notification_frequency": admin_notification_frequency, |
| 358 |
"method": method, |
| 359 |
"stage": convert_and_respect_annotation_metadata( |
| 360 |
object_=stage, annotation=BreachedPasswordDetectionStage, direction="write" |
| 361 |
), |
| 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 |
UpdateBreachedPasswordDetectionSettingsResponseContent, |
| 373 |
parse_obj_as( |
| 374 |
type_=UpdateBreachedPasswordDetectionSettingsResponseContent, |
| 375 |
object_=_response.json(), |
| 376 |
), |
| 377 |
) |
| 378 |
return AsyncHttpResponse(response=_response, data=_data) |
| 379 |
if _response.status_code == 400: |
| 380 |
raise BadRequestError( |
| 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 == 401: |
| 391 |
raise UnauthorizedError( |
| 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 == 403: |
| 402 |
raise ForbiddenError( |
| 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 |
if _response.status_code == 429: |
| 413 |
raise TooManyRequestsError( |
| 414 |
headers=dict(_response.headers), |
| 415 |
body=typing.cast( |
| 416 |
typing.Any, |
| 417 |
parse_obj_as( |
| 418 |
type_=typing.Any, |
| 419 |
object_=_response.json(), |
| 420 |
), |
| 421 |
), |
| 422 |
) |
| 423 |
_response_json = _response.json() |
| 424 |
except JSONDecodeError: |
| 425 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 426 |
except ValidationError as e: |
| 427 |
raise ParsingError( |
| 428 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 429 |
) |
| 430 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |