| 1 |
|
| 2 |
|
| 3 |
import typing |
| 4 |
from json.decoder import JSONDecodeError |
| 5 |
|
| 6 |
from ... import core |
| 7 |
from ...core.api_error import ApiError |
| 8 |
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 9 |
from ...core.http_response import AsyncHttpResponse, HttpResponse |
| 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.content_too_large_error import ContentTooLargeError |
| 15 |
from ...errors.forbidden_error import ForbiddenError |
| 16 |
from ...errors.internal_server_error import InternalServerError |
| 17 |
from ...errors.too_many_requests_error import TooManyRequestsError |
| 18 |
from ...errors.unauthorized_error import UnauthorizedError |
| 19 |
from ...types.create_import_users_response_content import CreateImportUsersResponseContent |
| 20 |
from pydantic import ValidationError |
| 21 |
|
| 22 |
|
| 23 |
OMIT = typing.cast(typing.Any, ...) |
| 24 |
|
| 25 |
|
| 26 |
class RawUsersImportsClient: |
| 27 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 28 |
self._client_wrapper = client_wrapper |
| 29 |
|
| 30 |
def create( |
| 31 |
self, |
| 32 |
*, |
| 33 |
users: core.File, |
| 34 |
connection_id: str, |
| 35 |
upsert: typing.Optional[bool] = OMIT, |
| 36 |
external_id: typing.Optional[str] = OMIT, |
| 37 |
send_completion_email: typing.Optional[bool] = OMIT, |
| 38 |
request_options: typing.Optional[RequestOptions] = None, |
| 39 |
) -> HttpResponse[CreateImportUsersResponseContent]: |
| 40 |
""" |
| 41 |
Import users from a <a href="https://auth0.com/docs/users/references/bulk-import-database-schema-examples">formatted file</a> into a connection via a long-running job. When importing users, with or without upsert, the `email_verified` is set to `false` when the email address is added or updated. Users must verify their email address. To avoid this behavior, set `email_verified` to `true` in the imported data. |
| 42 |
|
| 43 |
Parameters |
| 44 |
---------- |
| 45 |
users : core.File |
| 46 |
See core.File for more documentation |
| 47 |
|
| 48 |
connection_id : str |
| 49 |
connection_id of the connection to which users will be imported. |
| 50 |
|
| 51 |
upsert : typing.Optional[bool] |
| 52 |
Whether to update users if they already exist (true) or to ignore them (false). |
| 53 |
|
| 54 |
external_id : typing.Optional[str] |
| 55 |
Customer-defined ID. |
| 56 |
|
| 57 |
send_completion_email : typing.Optional[bool] |
| 58 |
Whether to send a completion email to all tenant owners when the job is finished (true) or not (false). |
| 59 |
|
| 60 |
request_options : typing.Optional[RequestOptions] |
| 61 |
Request-specific configuration. |
| 62 |
|
| 63 |
Returns |
| 64 |
------- |
| 65 |
HttpResponse[CreateImportUsersResponseContent] |
| 66 |
Job successfully created. |
| 67 |
""" |
| 68 |
_response = self._client_wrapper.httpx_client.request( |
| 69 |
"jobs/users-imports", |
| 70 |
method="POST", |
| 71 |
data={ |
| 72 |
"connection_id": connection_id, |
| 73 |
"upsert": upsert, |
| 74 |
"external_id": external_id, |
| 75 |
"send_completion_email": send_completion_email, |
| 76 |
}, |
| 77 |
files={ |
| 78 |
"users": users, |
| 79 |
}, |
| 80 |
request_options=request_options, |
| 81 |
omit=OMIT, |
| 82 |
force_multipart=True, |
| 83 |
) |
| 84 |
try: |
| 85 |
if 200 <= _response.status_code < 300: |
| 86 |
_data = typing.cast( |
| 87 |
CreateImportUsersResponseContent, |
| 88 |
parse_obj_as( |
| 89 |
type_=CreateImportUsersResponseContent, |
| 90 |
object_=_response.json(), |
| 91 |
), |
| 92 |
) |
| 93 |
return HttpResponse(response=_response, data=_data) |
| 94 |
if _response.status_code == 400: |
| 95 |
raise BadRequestError( |
| 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 == 401: |
| 106 |
raise UnauthorizedError( |
| 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 |
if _response.status_code == 403: |
| 117 |
raise ForbiddenError( |
| 118 |
headers=dict(_response.headers), |
| 119 |
body=typing.cast( |
| 120 |
typing.Any, |
| 121 |
parse_obj_as( |
| 122 |
type_=typing.Any, |
| 123 |
object_=_response.json(), |
| 124 |
), |
| 125 |
), |
| 126 |
) |
| 127 |
if _response.status_code == 413: |
| 128 |
raise ContentTooLargeError( |
| 129 |
headers=dict(_response.headers), |
| 130 |
body=typing.cast( |
| 131 |
typing.Any, |
| 132 |
parse_obj_as( |
| 133 |
type_=typing.Any, |
| 134 |
object_=_response.json(), |
| 135 |
), |
| 136 |
), |
| 137 |
) |
| 138 |
if _response.status_code == 429: |
| 139 |
raise TooManyRequestsError( |
| 140 |
headers=dict(_response.headers), |
| 141 |
body=typing.cast( |
| 142 |
typing.Any, |
| 143 |
parse_obj_as( |
| 144 |
type_=typing.Any, |
| 145 |
object_=_response.json(), |
| 146 |
), |
| 147 |
), |
| 148 |
) |
| 149 |
if _response.status_code == 500: |
| 150 |
raise InternalServerError( |
| 151 |
headers=dict(_response.headers), |
| 152 |
body=typing.cast( |
| 153 |
typing.Any, |
| 154 |
parse_obj_as( |
| 155 |
type_=typing.Any, |
| 156 |
object_=_response.json(), |
| 157 |
), |
| 158 |
), |
| 159 |
) |
| 160 |
_response_json = _response.json() |
| 161 |
except JSONDecodeError: |
| 162 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 163 |
except ValidationError as e: |
| 164 |
raise ParsingError( |
| 165 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 166 |
) |
| 167 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 168 |
|
| 169 |
|
| 170 |
class AsyncRawUsersImportsClient: |
| 171 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 172 |
self._client_wrapper = client_wrapper |
| 173 |
|
| 174 |
async def create( |
| 175 |
self, |
| 176 |
*, |
| 177 |
users: core.File, |
| 178 |
connection_id: str, |
| 179 |
upsert: typing.Optional[bool] = OMIT, |
| 180 |
external_id: typing.Optional[str] = OMIT, |
| 181 |
send_completion_email: typing.Optional[bool] = OMIT, |
| 182 |
request_options: typing.Optional[RequestOptions] = None, |
| 183 |
) -> AsyncHttpResponse[CreateImportUsersResponseContent]: |
| 184 |
""" |
| 185 |
Import users from a <a href="https://auth0.com/docs/users/references/bulk-import-database-schema-examples">formatted file</a> into a connection via a long-running job. When importing users, with or without upsert, the `email_verified` is set to `false` when the email address is added or updated. Users must verify their email address. To avoid this behavior, set `email_verified` to `true` in the imported data. |
| 186 |
|
| 187 |
Parameters |
| 188 |
---------- |
| 189 |
users : core.File |
| 190 |
See core.File for more documentation |
| 191 |
|
| 192 |
connection_id : str |
| 193 |
connection_id of the connection to which users will be imported. |
| 194 |
|
| 195 |
upsert : typing.Optional[bool] |
| 196 |
Whether to update users if they already exist (true) or to ignore them (false). |
| 197 |
|
| 198 |
external_id : typing.Optional[str] |
| 199 |
Customer-defined ID. |
| 200 |
|
| 201 |
send_completion_email : typing.Optional[bool] |
| 202 |
Whether to send a completion email to all tenant owners when the job is finished (true) or not (false). |
| 203 |
|
| 204 |
request_options : typing.Optional[RequestOptions] |
| 205 |
Request-specific configuration. |
| 206 |
|
| 207 |
Returns |
| 208 |
------- |
| 209 |
AsyncHttpResponse[CreateImportUsersResponseContent] |
| 210 |
Job successfully created. |
| 211 |
""" |
| 212 |
_response = await self._client_wrapper.httpx_client.request( |
| 213 |
"jobs/users-imports", |
| 214 |
method="POST", |
| 215 |
data={ |
| 216 |
"connection_id": connection_id, |
| 217 |
"upsert": upsert, |
| 218 |
"external_id": external_id, |
| 219 |
"send_completion_email": send_completion_email, |
| 220 |
}, |
| 221 |
files={ |
| 222 |
"users": users, |
| 223 |
}, |
| 224 |
request_options=request_options, |
| 225 |
omit=OMIT, |
| 226 |
force_multipart=True, |
| 227 |
) |
| 228 |
try: |
| 229 |
if 200 <= _response.status_code < 300: |
| 230 |
_data = typing.cast( |
| 231 |
CreateImportUsersResponseContent, |
| 232 |
parse_obj_as( |
| 233 |
type_=CreateImportUsersResponseContent, |
| 234 |
object_=_response.json(), |
| 235 |
), |
| 236 |
) |
| 237 |
return AsyncHttpResponse(response=_response, data=_data) |
| 238 |
if _response.status_code == 400: |
| 239 |
raise BadRequestError( |
| 240 |
headers=dict(_response.headers), |
| 241 |
body=typing.cast( |
| 242 |
typing.Any, |
| 243 |
parse_obj_as( |
| 244 |
type_=typing.Any, |
| 245 |
object_=_response.json(), |
| 246 |
), |
| 247 |
), |
| 248 |
) |
| 249 |
if _response.status_code == 401: |
| 250 |
raise UnauthorizedError( |
| 251 |
headers=dict(_response.headers), |
| 252 |
body=typing.cast( |
| 253 |
typing.Any, |
| 254 |
parse_obj_as( |
| 255 |
type_=typing.Any, |
| 256 |
object_=_response.json(), |
| 257 |
), |
| 258 |
), |
| 259 |
) |
| 260 |
if _response.status_code == 403: |
| 261 |
raise ForbiddenError( |
| 262 |
headers=dict(_response.headers), |
| 263 |
body=typing.cast( |
| 264 |
typing.Any, |
| 265 |
parse_obj_as( |
| 266 |
type_=typing.Any, |
| 267 |
object_=_response.json(), |
| 268 |
), |
| 269 |
), |
| 270 |
) |
| 271 |
if _response.status_code == 413: |
| 272 |
raise ContentTooLargeError( |
| 273 |
headers=dict(_response.headers), |
| 274 |
body=typing.cast( |
| 275 |
typing.Any, |
| 276 |
parse_obj_as( |
| 277 |
type_=typing.Any, |
| 278 |
object_=_response.json(), |
| 279 |
), |
| 280 |
), |
| 281 |
) |
| 282 |
if _response.status_code == 429: |
| 283 |
raise TooManyRequestsError( |
| 284 |
headers=dict(_response.headers), |
| 285 |
body=typing.cast( |
| 286 |
typing.Any, |
| 287 |
parse_obj_as( |
| 288 |
type_=typing.Any, |
| 289 |
object_=_response.json(), |
| 290 |
), |
| 291 |
), |
| 292 |
) |
| 293 |
if _response.status_code == 500: |
| 294 |
raise InternalServerError( |
| 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 |
_response_json = _response.json() |
| 305 |
except JSONDecodeError: |
| 306 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
| 307 |
except ValidationError as e: |
| 308 |
raise ParsingError( |
| 309 |
status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e |
| 310 |
) |
| 311 |
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |