Debian Codegraph @

src/auth0/management/connections/scim_configuration/tokens/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.jsonable_encoder import encode_path_param
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.conflict_error import ConflictError
15 from ....errors.not_found_error import NotFoundError
16 from ....types.create_scim_token_response_content import CreateScimTokenResponseContent
17 from ....types.get_scim_tokens_response_content import GetScimTokensResponseContent
18 from pydantic import ValidationError
19
20 # this is used as the default value for optional parameters
21 OMIT = typing.cast(typing.Any, ...)
22
23
24 class RawTokensClient:
25 def __init__(self, *, client_wrapper: SyncClientWrapper):
26 self._client_wrapper = client_wrapper
27
28 def get(
29 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
30 ) -> HttpResponse[GetScimTokensResponseContent]:
31 """
32 Retrieves all scim tokens by its connection `id`.
33
34 Parameters
35 ----------
36 id : str
37 The id of the connection to retrieve its SCIM configuration
38
39 request_options : typing.Optional[RequestOptions]
40 Request-specific configuration.
41
42 Returns
43 -------
44 HttpResponse[GetScimTokensResponseContent]
45 The connection's SCIM tokens were retrieved. See <strong>Response Schemas</strong> for schema.
46 """
47 _response = self._client_wrapper.httpx_client.request(
48 f"connections/{encode_path_param(id)}/scim-configuration/tokens",
49 method="GET",
50 request_options=request_options,
51 )
52 try:
53 if 200 <= _response.status_code < 300:
54 _data = typing.cast(
55 GetScimTokensResponseContent,
56 parse_obj_as(
57 type_=GetScimTokensResponseContent, # type: ignore
58 object_=_response.json(),
59 ),
60 )
61 return HttpResponse(response=_response, data=_data)
62 if _response.status_code == 400:
63 raise BadRequestError(
64 headers=dict(_response.headers),
65 body=typing.cast(
66 typing.Any,
67 parse_obj_as(
68 type_=typing.Any, # type: ignore
69 object_=_response.json(),
70 ),
71 ),
72 )
73 if _response.status_code == 404:
74 raise NotFoundError(
75 headers=dict(_response.headers),
76 body=typing.cast(
77 typing.Any,
78 parse_obj_as(
79 type_=typing.Any, # type: ignore
80 object_=_response.json(),
81 ),
82 ),
83 )
84 _response_json = _response.json()
85 except JSONDecodeError:
86 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
87 except ValidationError as e:
88 raise ParsingError(
89 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
90 )
91 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
92
93 def create(
94 self,
95 id: str,
96 *,
97 scopes: typing.Optional[typing.Sequence[str]] = OMIT,
98 token_lifetime: typing.Optional[int] = OMIT,
99 request_options: typing.Optional[RequestOptions] = None,
100 ) -> HttpResponse[CreateScimTokenResponseContent]:
101 """
102 Create a scim token for a scim client.
103
104 Parameters
105 ----------
106 id : str
107 The id of the connection to create its SCIM token
108
109 scopes : typing.Optional[typing.Sequence[str]]
110 The scopes of the scim token
111
112 token_lifetime : typing.Optional[int]
113 Lifetime of the token in seconds. Must be greater than 900
114
115 request_options : typing.Optional[RequestOptions]
116 Request-specific configuration.
117
118 Returns
119 -------
120 HttpResponse[CreateScimTokenResponseContent]
121 The connection's SCIM token was created. See <strong>Response Schemas</strong> for schema.
122 """
123 _response = self._client_wrapper.httpx_client.request(
124 f"connections/{encode_path_param(id)}/scim-configuration/tokens",
125 method="POST",
126 json={
127 "scopes": scopes,
128 "token_lifetime": token_lifetime,
129 },
130 headers={
131 "content-type": "application/json",
132 },
133 request_options=request_options,
134 omit=OMIT,
135 )
136 try:
137 if 200 <= _response.status_code < 300:
138 _data = typing.cast(
139 CreateScimTokenResponseContent,
140 parse_obj_as(
141 type_=CreateScimTokenResponseContent, # type: ignore
142 object_=_response.json(),
143 ),
144 )
145 return HttpResponse(response=_response, data=_data)
146 if _response.status_code == 400:
147 raise BadRequestError(
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 if _response.status_code == 404:
158 raise NotFoundError(
159 headers=dict(_response.headers),
160 body=typing.cast(
161 typing.Any,
162 parse_obj_as(
163 type_=typing.Any, # type: ignore
164 object_=_response.json(),
165 ),
166 ),
167 )
168 if _response.status_code == 409:
169 raise ConflictError(
170 headers=dict(_response.headers),
171 body=typing.cast(
172 typing.Any,
173 parse_obj_as(
174 type_=typing.Any, # type: ignore
175 object_=_response.json(),
176 ),
177 ),
178 )
179 _response_json = _response.json()
180 except JSONDecodeError:
181 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
182 except ValidationError as e:
183 raise ParsingError(
184 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
185 )
186 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
187
188 def delete(
189 self, id: str, token_id: str, *, request_options: typing.Optional[RequestOptions] = None
190 ) -> HttpResponse[None]:
191 """
192 Deletes a scim token by its connection `id` and `tokenId`.
193
194 Parameters
195 ----------
196 id : str
197 The connection id that owns the SCIM token to delete
198
199 token_id : str
200 The id of the scim token to delete
201
202 request_options : typing.Optional[RequestOptions]
203 Request-specific configuration.
204
205 Returns
206 -------
207 HttpResponse[None]
208 """
209 _response = self._client_wrapper.httpx_client.request(
210 f"connections/{encode_path_param(id)}/scim-configuration/tokens/{encode_path_param(token_id)}",
211 method="DELETE",
212 request_options=request_options,
213 )
214 try:
215 if 200 <= _response.status_code < 300:
216 return HttpResponse(response=_response, data=None)
217 if _response.status_code == 400:
218 raise BadRequestError(
219 headers=dict(_response.headers),
220 body=typing.cast(
221 typing.Any,
222 parse_obj_as(
223 type_=typing.Any, # type: ignore
224 object_=_response.json(),
225 ),
226 ),
227 )
228 if _response.status_code == 404:
229 raise NotFoundError(
230 headers=dict(_response.headers),
231 body=typing.cast(
232 typing.Any,
233 parse_obj_as(
234 type_=typing.Any, # type: ignore
235 object_=_response.json(),
236 ),
237 ),
238 )
239 _response_json = _response.json()
240 except JSONDecodeError:
241 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
242 except ValidationError as e:
243 raise ParsingError(
244 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
245 )
246 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
247
248
249 class AsyncRawTokensClient:
250 def __init__(self, *, client_wrapper: AsyncClientWrapper):
251 self._client_wrapper = client_wrapper
252
253 async def get(
254 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
255 ) -> AsyncHttpResponse[GetScimTokensResponseContent]:
256 """
257 Retrieves all scim tokens by its connection `id`.
258
259 Parameters
260 ----------
261 id : str
262 The id of the connection to retrieve its SCIM configuration
263
264 request_options : typing.Optional[RequestOptions]
265 Request-specific configuration.
266
267 Returns
268 -------
269 AsyncHttpResponse[GetScimTokensResponseContent]
270 The connection's SCIM tokens were retrieved. See <strong>Response Schemas</strong> for schema.
271 """
272 _response = await self._client_wrapper.httpx_client.request(
273 f"connections/{encode_path_param(id)}/scim-configuration/tokens",
274 method="GET",
275 request_options=request_options,
276 )
277 try:
278 if 200 <= _response.status_code < 300:
279 _data = typing.cast(
280 GetScimTokensResponseContent,
281 parse_obj_as(
282 type_=GetScimTokensResponseContent, # type: ignore
283 object_=_response.json(),
284 ),
285 )
286 return AsyncHttpResponse(response=_response, data=_data)
287 if _response.status_code == 400:
288 raise BadRequestError(
289 headers=dict(_response.headers),
290 body=typing.cast(
291 typing.Any,
292 parse_obj_as(
293 type_=typing.Any, # type: ignore
294 object_=_response.json(),
295 ),
296 ),
297 )
298 if _response.status_code == 404:
299 raise NotFoundError(
300 headers=dict(_response.headers),
301 body=typing.cast(
302 typing.Any,
303 parse_obj_as(
304 type_=typing.Any, # type: ignore
305 object_=_response.json(),
306 ),
307 ),
308 )
309 _response_json = _response.json()
310 except JSONDecodeError:
311 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
312 except ValidationError as e:
313 raise ParsingError(
314 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
315 )
316 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
317
318 async def create(
319 self,
320 id: str,
321 *,
322 scopes: typing.Optional[typing.Sequence[str]] = OMIT,
323 token_lifetime: typing.Optional[int] = OMIT,
324 request_options: typing.Optional[RequestOptions] = None,
325 ) -> AsyncHttpResponse[CreateScimTokenResponseContent]:
326 """
327 Create a scim token for a scim client.
328
329 Parameters
330 ----------
331 id : str
332 The id of the connection to create its SCIM token
333
334 scopes : typing.Optional[typing.Sequence[str]]
335 The scopes of the scim token
336
337 token_lifetime : typing.Optional[int]
338 Lifetime of the token in seconds. Must be greater than 900
339
340 request_options : typing.Optional[RequestOptions]
341 Request-specific configuration.
342
343 Returns
344 -------
345 AsyncHttpResponse[CreateScimTokenResponseContent]
346 The connection's SCIM token was created. See <strong>Response Schemas</strong> for schema.
347 """
348 _response = await self._client_wrapper.httpx_client.request(
349 f"connections/{encode_path_param(id)}/scim-configuration/tokens",
350 method="POST",
351 json={
352 "scopes": scopes,
353 "token_lifetime": token_lifetime,
354 },
355 headers={
356 "content-type": "application/json",
357 },
358 request_options=request_options,
359 omit=OMIT,
360 )
361 try:
362 if 200 <= _response.status_code < 300:
363 _data = typing.cast(
364 CreateScimTokenResponseContent,
365 parse_obj_as(
366 type_=CreateScimTokenResponseContent, # type: ignore
367 object_=_response.json(),
368 ),
369 )
370 return AsyncHttpResponse(response=_response, data=_data)
371 if _response.status_code == 400:
372 raise BadRequestError(
373 headers=dict(_response.headers),
374 body=typing.cast(
375 typing.Any,
376 parse_obj_as(
377 type_=typing.Any, # type: ignore
378 object_=_response.json(),
379 ),
380 ),
381 )
382 if _response.status_code == 404:
383 raise NotFoundError(
384 headers=dict(_response.headers),
385 body=typing.cast(
386 typing.Any,
387 parse_obj_as(
388 type_=typing.Any, # type: ignore
389 object_=_response.json(),
390 ),
391 ),
392 )
393 if _response.status_code == 409:
394 raise ConflictError(
395 headers=dict(_response.headers),
396 body=typing.cast(
397 typing.Any,
398 parse_obj_as(
399 type_=typing.Any, # type: ignore
400 object_=_response.json(),
401 ),
402 ),
403 )
404 _response_json = _response.json()
405 except JSONDecodeError:
406 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
407 except ValidationError as e:
408 raise ParsingError(
409 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
410 )
411 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
412
413 async def delete(
414 self, id: str, token_id: str, *, request_options: typing.Optional[RequestOptions] = None
415 ) -> AsyncHttpResponse[None]:
416 """
417 Deletes a scim token by its connection `id` and `tokenId`.
418
419 Parameters
420 ----------
421 id : str
422 The connection id that owns the SCIM token to delete
423
424 token_id : str
425 The id of the scim token to delete
426
427 request_options : typing.Optional[RequestOptions]
428 Request-specific configuration.
429
430 Returns
431 -------
432 AsyncHttpResponse[None]
433 """
434 _response = await self._client_wrapper.httpx_client.request(
435 f"connections/{encode_path_param(id)}/scim-configuration/tokens/{encode_path_param(token_id)}",
436 method="DELETE",
437 request_options=request_options,
438 )
439 try:
440 if 200 <= _response.status_code < 300:
441 return AsyncHttpResponse(response=_response, data=None)
442 if _response.status_code == 400:
443 raise BadRequestError(
444 headers=dict(_response.headers),
445 body=typing.cast(
446 typing.Any,
447 parse_obj_as(
448 type_=typing.Any, # type: ignore
449 object_=_response.json(),
450 ),
451 ),
452 )
453 if _response.status_code == 404:
454 raise NotFoundError(
455 headers=dict(_response.headers),
456 body=typing.cast(
457 typing.Any,
458 parse_obj_as(
459 type_=typing.Any, # type: ignore
460 object_=_response.json(),
461 ),
462 ),
463 )
464 _response_json = _response.json()
465 except JSONDecodeError:
466 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
467 except ValidationError as e:
468 raise ParsingError(
469 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
470 )
471 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)