Debian Codegraph @

src/auth0/management/jobs/users_exports/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
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.create_export_users_fields import CreateExportUsersFields
18 from ...types.create_export_users_response_content import CreateExportUsersResponseContent
19 from ...types.job_file_format_enum import JobFileFormatEnum
20 from pydantic import ValidationError
21
22 # this is used as the default value for optional parameters
23 OMIT = typing.cast(typing.Any, ...)
24
25
26 class RawUsersExportsClient:
27 def __init__(self, *, client_wrapper: SyncClientWrapper):
28 self._client_wrapper = client_wrapper
29
30 def create(
31 self,
32 *,
33 connection_id: typing.Optional[str] = OMIT,
34 format: typing.Optional[JobFileFormatEnum] = OMIT,
35 limit: typing.Optional[int] = OMIT,
36 fields: typing.Optional[typing.Sequence[CreateExportUsersFields]] = OMIT,
37 request_options: typing.Optional[RequestOptions] = None,
38 ) -> HttpResponse[CreateExportUsersResponseContent]:
39 """
40 Export all users to a file via a long-running job.
41
42 Parameters
43 ----------
44 connection_id : typing.Optional[str]
45 connection_id of the connection from which users will be exported.
46
47 format : typing.Optional[JobFileFormatEnum]
48
49 limit : typing.Optional[int]
50 Limit the number of records.
51
52 fields : typing.Optional[typing.Sequence[CreateExportUsersFields]]
53 List of fields to be included in the CSV. Defaults to a predefined set of fields.
54
55 request_options : typing.Optional[RequestOptions]
56 Request-specific configuration.
57
58 Returns
59 -------
60 HttpResponse[CreateExportUsersResponseContent]
61 Job created successfully.
62 """
63 _response = self._client_wrapper.httpx_client.request(
64 "jobs/users-exports",
65 method="POST",
66 json={
67 "connection_id": connection_id,
68 "format": format,
69 "limit": limit,
70 "fields": convert_and_respect_annotation_metadata(
71 object_=fields, annotation=typing.Sequence[CreateExportUsersFields], direction="write"
72 ),
73 },
74 headers={
75 "content-type": "application/json",
76 },
77 request_options=request_options,
78 omit=OMIT,
79 )
80 try:
81 if 200 <= _response.status_code < 300:
82 _data = typing.cast(
83 CreateExportUsersResponseContent,
84 parse_obj_as(
85 type_=CreateExportUsersResponseContent, # type: ignore
86 object_=_response.json(),
87 ),
88 )
89 return HttpResponse(response=_response, data=_data)
90 if _response.status_code == 400:
91 raise BadRequestError(
92 headers=dict(_response.headers),
93 body=typing.cast(
94 typing.Any,
95 parse_obj_as(
96 type_=typing.Any, # type: ignore
97 object_=_response.json(),
98 ),
99 ),
100 )
101 if _response.status_code == 401:
102 raise UnauthorizedError(
103 headers=dict(_response.headers),
104 body=typing.cast(
105 typing.Any,
106 parse_obj_as(
107 type_=typing.Any, # type: ignore
108 object_=_response.json(),
109 ),
110 ),
111 )
112 if _response.status_code == 403:
113 raise ForbiddenError(
114 headers=dict(_response.headers),
115 body=typing.cast(
116 typing.Any,
117 parse_obj_as(
118 type_=typing.Any, # type: ignore
119 object_=_response.json(),
120 ),
121 ),
122 )
123 if _response.status_code == 429:
124 raise TooManyRequestsError(
125 headers=dict(_response.headers),
126 body=typing.cast(
127 typing.Any,
128 parse_obj_as(
129 type_=typing.Any, # type: ignore
130 object_=_response.json(),
131 ),
132 ),
133 )
134 _response_json = _response.json()
135 except JSONDecodeError:
136 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
137 except ValidationError as e:
138 raise ParsingError(
139 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
140 )
141 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
142
143
144 class AsyncRawUsersExportsClient:
145 def __init__(self, *, client_wrapper: AsyncClientWrapper):
146 self._client_wrapper = client_wrapper
147
148 async def create(
149 self,
150 *,
151 connection_id: typing.Optional[str] = OMIT,
152 format: typing.Optional[JobFileFormatEnum] = OMIT,
153 limit: typing.Optional[int] = OMIT,
154 fields: typing.Optional[typing.Sequence[CreateExportUsersFields]] = OMIT,
155 request_options: typing.Optional[RequestOptions] = None,
156 ) -> AsyncHttpResponse[CreateExportUsersResponseContent]:
157 """
158 Export all users to a file via a long-running job.
159
160 Parameters
161 ----------
162 connection_id : typing.Optional[str]
163 connection_id of the connection from which users will be exported.
164
165 format : typing.Optional[JobFileFormatEnum]
166
167 limit : typing.Optional[int]
168 Limit the number of records.
169
170 fields : typing.Optional[typing.Sequence[CreateExportUsersFields]]
171 List of fields to be included in the CSV. Defaults to a predefined set of fields.
172
173 request_options : typing.Optional[RequestOptions]
174 Request-specific configuration.
175
176 Returns
177 -------
178 AsyncHttpResponse[CreateExportUsersResponseContent]
179 Job created successfully.
180 """
181 _response = await self._client_wrapper.httpx_client.request(
182 "jobs/users-exports",
183 method="POST",
184 json={
185 "connection_id": connection_id,
186 "format": format,
187 "limit": limit,
188 "fields": convert_and_respect_annotation_metadata(
189 object_=fields, annotation=typing.Sequence[CreateExportUsersFields], direction="write"
190 ),
191 },
192 headers={
193 "content-type": "application/json",
194 },
195 request_options=request_options,
196 omit=OMIT,
197 )
198 try:
199 if 200 <= _response.status_code < 300:
200 _data = typing.cast(
201 CreateExportUsersResponseContent,
202 parse_obj_as(
203 type_=CreateExportUsersResponseContent, # type: ignore
204 object_=_response.json(),
205 ),
206 )
207 return AsyncHttpResponse(response=_response, data=_data)
208 if _response.status_code == 400:
209 raise BadRequestError(
210 headers=dict(_response.headers),
211 body=typing.cast(
212 typing.Any,
213 parse_obj_as(
214 type_=typing.Any, # type: ignore
215 object_=_response.json(),
216 ),
217 ),
218 )
219 if _response.status_code == 401:
220 raise UnauthorizedError(
221 headers=dict(_response.headers),
222 body=typing.cast(
223 typing.Any,
224 parse_obj_as(
225 type_=typing.Any, # type: ignore
226 object_=_response.json(),
227 ),
228 ),
229 )
230 if _response.status_code == 403:
231 raise ForbiddenError(
232 headers=dict(_response.headers),
233 body=typing.cast(
234 typing.Any,
235 parse_obj_as(
236 type_=typing.Any, # type: ignore
237 object_=_response.json(),
238 ),
239 ),
240 )
241 if _response.status_code == 429:
242 raise TooManyRequestsError(
243 headers=dict(_response.headers),
244 body=typing.cast(
245 typing.Any,
246 parse_obj_as(
247 type_=typing.Any, # type: ignore
248 object_=_response.json(),
249 ),
250 ),
251 )
252 _response_json = _response.json()
253 except JSONDecodeError:
254 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
255 except ValidationError as e:
256 raise ParsingError(
257 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
258 )
259 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)