Debian Codegraph @

src/auth0/management/users/effective_roles/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_user_effective_roles_response_content import ListUserEffectiveRolesResponseContent
19 from ...types.user_effective_role import UserEffectiveRole
20 from pydantic import ValidationError
21
22
23 class RawEffectiveRolesClient:
24 def __init__(self, *, client_wrapper: SyncClientWrapper):
25 self._client_wrapper = client_wrapper
26
27 def list(
28 self,
29 id: str,
30 *,
31 from_: typing.Optional[str] = None,
32 take: typing.Optional[int] = 50,
33 request_options: typing.Optional[RequestOptions] = None,
34 ) -> SyncPager[UserEffectiveRole, ListUserEffectiveRolesResponseContent]:
35 """
36 Retrieve detailed list of effective roles for a user, including roles assigned directly and through group memberships.
37
38 Parameters
39 ----------
40 id : str
41 ID of the user to list effective roles for.
42
43 from_ : typing.Optional[str]
44 Optional Id from which to start selection.
45
46 take : typing.Optional[int]
47 Number of results per page. Defaults to 50.
48
49 request_options : typing.Optional[RequestOptions]
50 Request-specific configuration.
51
52 Returns
53 -------
54 SyncPager[UserEffectiveRole, ListUserEffectiveRolesResponseContent]
55 User's effective roles successfully retrieved.
56 """
57 _response = self._client_wrapper.httpx_client.request(
58 f"users/{encode_path_param(id)}/effective-roles",
59 method="GET",
60 params={
61 "from": from_,
62 "take": take,
63 },
64 request_options=request_options,
65 )
66 try:
67 if 200 <= _response.status_code < 300:
68 _parsed_response = typing.cast(
69 ListUserEffectiveRolesResponseContent,
70 parse_obj_as(
71 type_=ListUserEffectiveRolesResponseContent, # type: ignore
72 object_=_response.json(),
73 ),
74 )
75 _items = _parsed_response.roles
76 _parsed_next = _parsed_response.next
77 _has_next = _parsed_next is not None and _parsed_next != ""
78 _get_next = lambda: self.list(
79 id,
80 from_=_parsed_next,
81 take=take,
82 request_options=request_options,
83 )
84 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
85 if _response.status_code == 400:
86 raise BadRequestError(
87 headers=dict(_response.headers),
88 body=typing.cast(
89 typing.Any,
90 parse_obj_as(
91 type_=typing.Any, # type: ignore
92 object_=_response.json(),
93 ),
94 ),
95 )
96 if _response.status_code == 401:
97 raise UnauthorizedError(
98 headers=dict(_response.headers),
99 body=typing.cast(
100 typing.Any,
101 parse_obj_as(
102 type_=typing.Any, # type: ignore
103 object_=_response.json(),
104 ),
105 ),
106 )
107 if _response.status_code == 403:
108 raise ForbiddenError(
109 headers=dict(_response.headers),
110 body=typing.cast(
111 typing.Any,
112 parse_obj_as(
113 type_=typing.Any, # type: ignore
114 object_=_response.json(),
115 ),
116 ),
117 )
118 if _response.status_code == 404:
119 raise NotFoundError(
120 headers=dict(_response.headers),
121 body=typing.cast(
122 typing.Any,
123 parse_obj_as(
124 type_=typing.Any, # type: ignore
125 object_=_response.json(),
126 ),
127 ),
128 )
129 if _response.status_code == 429:
130 raise TooManyRequestsError(
131 headers=dict(_response.headers),
132 body=typing.cast(
133 typing.Any,
134 parse_obj_as(
135 type_=typing.Any, # type: ignore
136 object_=_response.json(),
137 ),
138 ),
139 )
140 _response_json = _response.json()
141 except JSONDecodeError:
142 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
143 except ValidationError as e:
144 raise ParsingError(
145 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
146 )
147 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
148
149
150 class AsyncRawEffectiveRolesClient:
151 def __init__(self, *, client_wrapper: AsyncClientWrapper):
152 self._client_wrapper = client_wrapper
153
154 async def list(
155 self,
156 id: str,
157 *,
158 from_: typing.Optional[str] = None,
159 take: typing.Optional[int] = 50,
160 request_options: typing.Optional[RequestOptions] = None,
161 ) -> AsyncPager[UserEffectiveRole, ListUserEffectiveRolesResponseContent]:
162 """
163 Retrieve detailed list of effective roles for a user, including roles assigned directly and through group memberships.
164
165 Parameters
166 ----------
167 id : str
168 ID of the user to list effective roles for.
169
170 from_ : typing.Optional[str]
171 Optional Id from which to start selection.
172
173 take : typing.Optional[int]
174 Number of results per page. Defaults to 50.
175
176 request_options : typing.Optional[RequestOptions]
177 Request-specific configuration.
178
179 Returns
180 -------
181 AsyncPager[UserEffectiveRole, ListUserEffectiveRolesResponseContent]
182 User's effective roles successfully retrieved.
183 """
184 _response = await self._client_wrapper.httpx_client.request(
185 f"users/{encode_path_param(id)}/effective-roles",
186 method="GET",
187 params={
188 "from": from_,
189 "take": take,
190 },
191 request_options=request_options,
192 )
193 try:
194 if 200 <= _response.status_code < 300:
195 _parsed_response = typing.cast(
196 ListUserEffectiveRolesResponseContent,
197 parse_obj_as(
198 type_=ListUserEffectiveRolesResponseContent, # type: ignore
199 object_=_response.json(),
200 ),
201 )
202 _items = _parsed_response.roles
203 _parsed_next = _parsed_response.next
204 _has_next = _parsed_next is not None and _parsed_next != ""
205
206 async def _get_next():
207 return await self.list(
208 id,
209 from_=_parsed_next,
210 take=take,
211 request_options=request_options,
212 )
213
214 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
215 if _response.status_code == 400:
216 raise BadRequestError(
217 headers=dict(_response.headers),
218 body=typing.cast(
219 typing.Any,
220 parse_obj_as(
221 type_=typing.Any, # type: ignore
222 object_=_response.json(),
223 ),
224 ),
225 )
226 if _response.status_code == 401:
227 raise UnauthorizedError(
228 headers=dict(_response.headers),
229 body=typing.cast(
230 typing.Any,
231 parse_obj_as(
232 type_=typing.Any, # type: ignore
233 object_=_response.json(),
234 ),
235 ),
236 )
237 if _response.status_code == 403:
238 raise ForbiddenError(
239 headers=dict(_response.headers),
240 body=typing.cast(
241 typing.Any,
242 parse_obj_as(
243 type_=typing.Any, # type: ignore
244 object_=_response.json(),
245 ),
246 ),
247 )
248 if _response.status_code == 404:
249 raise NotFoundError(
250 headers=dict(_response.headers),
251 body=typing.cast(
252 typing.Any,
253 parse_obj_as(
254 type_=typing.Any, # type: ignore
255 object_=_response.json(),
256 ),
257 ),
258 )
259 if _response.status_code == 429:
260 raise TooManyRequestsError(
261 headers=dict(_response.headers),
262 body=typing.cast(
263 typing.Any,
264 parse_obj_as(
265 type_=typing.Any, # type: ignore
266 object_=_response.json(),
267 ),
268 ),
269 )
270 _response_json = _response.json()
271 except JSONDecodeError:
272 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
273 except ValidationError as e:
274 raise ParsingError(
275 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
276 )
277 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)