Debian Codegraph @

src/auth0/management/organizations/roles/members/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.jsonable_encoder import encode_path_param
9 from ....core.pagination import AsyncPager, SyncPager
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.not_found_error import NotFoundError
16 from ....errors.too_many_requests_error import TooManyRequestsError
17 from ....errors.unauthorized_error import UnauthorizedError
18 from ....types.list_organization_role_members_response_content import ListOrganizationRoleMembersResponseContent
19 from ....types.role_member import RoleMember
20 from pydantic import ValidationError
21
22
23 class RawMembersClient:
24 def __init__(self, *, client_wrapper: SyncClientWrapper):
25 self._client_wrapper = client_wrapper
26
27 def list(
28 self,
29 id: str,
30 role_id: str,
31 *,
32 from_: typing.Optional[str] = None,
33 take: typing.Optional[int] = 50,
34 fields: typing.Optional[str] = None,
35 include_fields: typing.Optional[bool] = True,
36 request_options: typing.Optional[RequestOptions] = None,
37 ) -> SyncPager[RoleMember, ListOrganizationRoleMembersResponseContent]:
38 """
39 List the organization members assigned a specific role within the context of an organization.
40
41 Parameters
42 ----------
43 id : str
44 ID of the organization.
45
46 role_id : str
47 ID of the role to retrieve the assigned members for.
48
49 from_ : typing.Optional[str]
50 Optional Id from which to start selection.
51
52 take : typing.Optional[int]
53 Number of results per page. Defaults to 50. Values above the maximum permitted size are capped.
54
55 fields : typing.Optional[str]
56 Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields.
57
58 include_fields : typing.Optional[bool]
59 Whether specified fields are to be included (true) or excluded (false). Defaults to true.
60
61 request_options : typing.Optional[RequestOptions]
62 Request-specific configuration.
63
64 Returns
65 -------
66 SyncPager[RoleMember, ListOrganizationRoleMembersResponseContent]
67 Role members successfully retrieved.
68 """
69 _response = self._client_wrapper.httpx_client.request(
70 f"organizations/{encode_path_param(id)}/roles/{encode_path_param(role_id)}/members",
71 method="GET",
72 params={
73 "from": from_,
74 "take": take,
75 "fields": fields,
76 "include_fields": include_fields,
77 },
78 request_options=request_options,
79 )
80 try:
81 if 200 <= _response.status_code < 300:
82 _parsed_response = typing.cast(
83 ListOrganizationRoleMembersResponseContent,
84 parse_obj_as(
85 type_=ListOrganizationRoleMembersResponseContent, # type: ignore
86 object_=_response.json(),
87 ),
88 )
89 _items = _parsed_response.members
90 _parsed_next = _parsed_response.next
91 _has_next = _parsed_next is not None and _parsed_next != ""
92 _get_next = lambda: self.list(
93 id,
94 role_id,
95 from_=_parsed_next,
96 take=take,
97 fields=fields,
98 include_fields=include_fields,
99 request_options=request_options,
100 )
101 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
102 if _response.status_code == 400:
103 raise BadRequestError(
104 headers=dict(_response.headers),
105 body=typing.cast(
106 typing.Any,
107 parse_obj_as(
108 type_=typing.Any, # type: ignore
109 object_=_response.json(),
110 ),
111 ),
112 )
113 if _response.status_code == 401:
114 raise UnauthorizedError(
115 headers=dict(_response.headers),
116 body=typing.cast(
117 typing.Any,
118 parse_obj_as(
119 type_=typing.Any, # type: ignore
120 object_=_response.json(),
121 ),
122 ),
123 )
124 if _response.status_code == 403:
125 raise ForbiddenError(
126 headers=dict(_response.headers),
127 body=typing.cast(
128 typing.Any,
129 parse_obj_as(
130 type_=typing.Any, # type: ignore
131 object_=_response.json(),
132 ),
133 ),
134 )
135 if _response.status_code == 404:
136 raise NotFoundError(
137 headers=dict(_response.headers),
138 body=typing.cast(
139 typing.Any,
140 parse_obj_as(
141 type_=typing.Any, # type: ignore
142 object_=_response.json(),
143 ),
144 ),
145 )
146 if _response.status_code == 429:
147 raise TooManyRequestsError(
148 headers=dict(_response.headers),
149 body=typing.cast(
150 typing.Any,
151 parse_obj_as(
152 type_=typing.Any, # type: ignore
153 object_=_response.json(),
154 ),
155 ),
156 )
157 _response_json = _response.json()
158 except JSONDecodeError:
159 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
160 except ValidationError as e:
161 raise ParsingError(
162 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
163 )
164 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
165
166
167 class AsyncRawMembersClient:
168 def __init__(self, *, client_wrapper: AsyncClientWrapper):
169 self._client_wrapper = client_wrapper
170
171 async def list(
172 self,
173 id: str,
174 role_id: str,
175 *,
176 from_: typing.Optional[str] = None,
177 take: typing.Optional[int] = 50,
178 fields: typing.Optional[str] = None,
179 include_fields: typing.Optional[bool] = True,
180 request_options: typing.Optional[RequestOptions] = None,
181 ) -> AsyncPager[RoleMember, ListOrganizationRoleMembersResponseContent]:
182 """
183 List the organization members assigned a specific role within the context of an organization.
184
185 Parameters
186 ----------
187 id : str
188 ID of the organization.
189
190 role_id : str
191 ID of the role to retrieve the assigned members for.
192
193 from_ : typing.Optional[str]
194 Optional Id from which to start selection.
195
196 take : typing.Optional[int]
197 Number of results per page. Defaults to 50. Values above the maximum permitted size are capped.
198
199 fields : typing.Optional[str]
200 Comma-separated list of fields to include or exclude (based on value provided for include_fields) in the result. Leave empty to retrieve all fields.
201
202 include_fields : typing.Optional[bool]
203 Whether specified fields are to be included (true) or excluded (false). Defaults to true.
204
205 request_options : typing.Optional[RequestOptions]
206 Request-specific configuration.
207
208 Returns
209 -------
210 AsyncPager[RoleMember, ListOrganizationRoleMembersResponseContent]
211 Role members successfully retrieved.
212 """
213 _response = await self._client_wrapper.httpx_client.request(
214 f"organizations/{encode_path_param(id)}/roles/{encode_path_param(role_id)}/members",
215 method="GET",
216 params={
217 "from": from_,
218 "take": take,
219 "fields": fields,
220 "include_fields": include_fields,
221 },
222 request_options=request_options,
223 )
224 try:
225 if 200 <= _response.status_code < 300:
226 _parsed_response = typing.cast(
227 ListOrganizationRoleMembersResponseContent,
228 parse_obj_as(
229 type_=ListOrganizationRoleMembersResponseContent, # type: ignore
230 object_=_response.json(),
231 ),
232 )
233 _items = _parsed_response.members
234 _parsed_next = _parsed_response.next
235 _has_next = _parsed_next is not None and _parsed_next != ""
236
237 async def _get_next():
238 return await self.list(
239 id,
240 role_id,
241 from_=_parsed_next,
242 take=take,
243 fields=fields,
244 include_fields=include_fields,
245 request_options=request_options,
246 )
247
248 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
249 if _response.status_code == 400:
250 raise BadRequestError(
251 headers=dict(_response.headers),
252 body=typing.cast(
253 typing.Any,
254 parse_obj_as(
255 type_=typing.Any, # type: ignore
256 object_=_response.json(),
257 ),
258 ),
259 )
260 if _response.status_code == 401:
261 raise UnauthorizedError(
262 headers=dict(_response.headers),
263 body=typing.cast(
264 typing.Any,
265 parse_obj_as(
266 type_=typing.Any, # type: ignore
267 object_=_response.json(),
268 ),
269 ),
270 )
271 if _response.status_code == 403:
272 raise ForbiddenError(
273 headers=dict(_response.headers),
274 body=typing.cast(
275 typing.Any,
276 parse_obj_as(
277 type_=typing.Any, # type: ignore
278 object_=_response.json(),
279 ),
280 ),
281 )
282 if _response.status_code == 404:
283 raise NotFoundError(
284 headers=dict(_response.headers),
285 body=typing.cast(
286 typing.Any,
287 parse_obj_as(
288 type_=typing.Any, # type: ignore
289 object_=_response.json(),
290 ),
291 ),
292 )
293 if _response.status_code == 429:
294 raise TooManyRequestsError(
295 headers=dict(_response.headers),
296 body=typing.cast(
297 typing.Any,
298 parse_obj_as(
299 type_=typing.Any, # type: ignore
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)