Debian Codegraph @

src/auth0/management/rules/client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import typing
4
5 from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
6 from ..core.pagination import AsyncPager, SyncPager
7 from ..core.request_options import RequestOptions
8 from ..types.create_rule_response_content import CreateRuleResponseContent
9 from ..types.get_rule_response_content import GetRuleResponseContent
10 from ..types.list_rules_offset_paginated_response_content import ListRulesOffsetPaginatedResponseContent
11 from ..types.rule import Rule
12 from ..types.update_rule_response_content import UpdateRuleResponseContent
13 from .raw_client import AsyncRawRulesClient, RawRulesClient
14
15 # this is used as the default value for optional parameters
16 OMIT = typing.cast(typing.Any, ...)
17
18
19 class RulesClient:
20 def __init__(self, *, client_wrapper: SyncClientWrapper):
21 self._raw_client = RawRulesClient(client_wrapper=client_wrapper)
22
23 @property
24 def with_raw_response(self) -> RawRulesClient:
25 """
26 Retrieves a raw implementation of this client that returns raw responses.
27
28 Returns
29 -------
30 RawRulesClient
31 """
32 return self._raw_client
33
34 def list(
35 self,
36 *,
37 page: typing.Optional[int] = 0,
38 per_page: typing.Optional[int] = 50,
39 include_totals: typing.Optional[bool] = True,
40 enabled: typing.Optional[bool] = None,
41 fields: typing.Optional[str] = None,
42 include_fields: typing.Optional[bool] = None,
43 request_options: typing.Optional[RequestOptions] = None,
44 ) -> SyncPager[Rule, ListRulesOffsetPaginatedResponseContent]:
45 """
46 Retrieve a filtered list of [rules](https://auth0.com/docs/rules). Accepts a list of fields to include or exclude.
47
48 Parameters
49 ----------
50 page : typing.Optional[int]
51 Page index of the results to return. First page is 0.
52
53 per_page : typing.Optional[int]
54 Number of results per page.
55
56 include_totals : typing.Optional[bool]
57 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
58
59 enabled : typing.Optional[bool]
60 Optional filter on whether a rule is enabled (true) or disabled (false).
61
62 fields : typing.Optional[str]
63 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.
64
65 include_fields : typing.Optional[bool]
66 Whether specified fields are to be included (true) or excluded (false).
67
68 request_options : typing.Optional[RequestOptions]
69 Request-specific configuration.
70
71 Returns
72 -------
73 SyncPager[Rule, ListRulesOffsetPaginatedResponseContent]
74 Rules successfully retrieved.
75
76 Examples
77 --------
78 from auth0 import Auth0
79
80 client = Auth0(
81 token="YOUR_TOKEN",
82 )
83 response = client.rules.list(
84 page=1,
85 per_page=1,
86 include_totals=True,
87 enabled=True,
88 fields="fields",
89 include_fields=True,
90 )
91 for item in response:
92 yield item
93 # alternatively, you can paginate page-by-page
94 for page in response.iter_pages():
95 yield page
96 """
97 return self._raw_client.list(
98 page=page,
99 per_page=per_page,
100 include_totals=include_totals,
101 enabled=enabled,
102 fields=fields,
103 include_fields=include_fields,
104 request_options=request_options,
105 )
106
107 def create(
108 self,
109 *,
110 name: str,
111 script: str,
112 order: typing.Optional[float] = OMIT,
113 enabled: typing.Optional[bool] = OMIT,
114 request_options: typing.Optional[RequestOptions] = None,
115 ) -> CreateRuleResponseContent:
116 """
117 Create a [new rule](https://auth0.com/docs/rules#create-a-new-rule-using-the-management-api).
118
119 Note: Changing a rule's stage of execution from the default `login_success` can change the rule's function signature to have user omitted.
120
121 Parameters
122 ----------
123 name : str
124 Name of this rule.
125
126 script : str
127 Code to be executed when this rule runs.
128
129 order : typing.Optional[float]
130 Order that this rule should execute in relative to other rules. Lower-valued rules execute first.
131
132 enabled : typing.Optional[bool]
133 Whether the rule is enabled (true), or disabled (false).
134
135 request_options : typing.Optional[RequestOptions]
136 Request-specific configuration.
137
138 Returns
139 -------
140 CreateRuleResponseContent
141 Rule successfully created.
142
143 Examples
144 --------
145 from auth0 import Auth0
146
147 client = Auth0(
148 token="YOUR_TOKEN",
149 )
150 client.rules.create(
151 name="name",
152 script="script",
153 )
154 """
155 _response = self._raw_client.create(
156 name=name, script=script, order=order, enabled=enabled, request_options=request_options
157 )
158 return _response.data
159
160 def get(
161 self,
162 id: str,
163 *,
164 fields: typing.Optional[str] = None,
165 include_fields: typing.Optional[bool] = None,
166 request_options: typing.Optional[RequestOptions] = None,
167 ) -> GetRuleResponseContent:
168 """
169 Retrieve [rule](https://auth0.com/docs/rules) details. Accepts a list of fields to include or exclude in the result.
170
171 Parameters
172 ----------
173 id : str
174 ID of the rule to retrieve.
175
176 fields : typing.Optional[str]
177 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.
178
179 include_fields : typing.Optional[bool]
180 Whether specified fields are to be included (true) or excluded (false).
181
182 request_options : typing.Optional[RequestOptions]
183 Request-specific configuration.
184
185 Returns
186 -------
187 GetRuleResponseContent
188 Rule successfully retrieved.
189
190 Examples
191 --------
192 from auth0 import Auth0
193
194 client = Auth0(
195 token="YOUR_TOKEN",
196 )
197 client.rules.get(
198 id="id",
199 fields="fields",
200 include_fields=True,
201 )
202 """
203 _response = self._raw_client.get(
204 id, fields=fields, include_fields=include_fields, request_options=request_options
205 )
206 return _response.data
207
208 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
209 """
210 Delete a rule.
211
212 Parameters
213 ----------
214 id : str
215 ID of the rule to delete.
216
217 request_options : typing.Optional[RequestOptions]
218 Request-specific configuration.
219
220 Returns
221 -------
222 None
223
224 Examples
225 --------
226 from auth0 import Auth0
227
228 client = Auth0(
229 token="YOUR_TOKEN",
230 )
231 client.rules.delete(
232 id="id",
233 )
234 """
235 _response = self._raw_client.delete(id, request_options=request_options)
236 return _response.data
237
238 def update(
239 self,
240 id: str,
241 *,
242 script: typing.Optional[str] = OMIT,
243 name: typing.Optional[str] = OMIT,
244 order: typing.Optional[float] = OMIT,
245 enabled: typing.Optional[bool] = OMIT,
246 request_options: typing.Optional[RequestOptions] = None,
247 ) -> UpdateRuleResponseContent:
248 """
249 Update an existing rule.
250
251 Parameters
252 ----------
253 id : str
254 ID of the rule to retrieve.
255
256 script : typing.Optional[str]
257 Code to be executed when this rule runs.
258
259 name : typing.Optional[str]
260 Name of this rule.
261
262 order : typing.Optional[float]
263 Order that this rule should execute in relative to other rules. Lower-valued rules execute first.
264
265 enabled : typing.Optional[bool]
266 Whether the rule is enabled (true), or disabled (false).
267
268 request_options : typing.Optional[RequestOptions]
269 Request-specific configuration.
270
271 Returns
272 -------
273 UpdateRuleResponseContent
274 Rule successfully updated.
275
276 Examples
277 --------
278 from auth0 import Auth0
279
280 client = Auth0(
281 token="YOUR_TOKEN",
282 )
283 client.rules.update(
284 id="id",
285 )
286 """
287 _response = self._raw_client.update(
288 id, script=script, name=name, order=order, enabled=enabled, request_options=request_options
289 )
290 return _response.data
291
292
293 class AsyncRulesClient:
294 def __init__(self, *, client_wrapper: AsyncClientWrapper):
295 self._raw_client = AsyncRawRulesClient(client_wrapper=client_wrapper)
296
297 @property
298 def with_raw_response(self) -> AsyncRawRulesClient:
299 """
300 Retrieves a raw implementation of this client that returns raw responses.
301
302 Returns
303 -------
304 AsyncRawRulesClient
305 """
306 return self._raw_client
307
308 async def list(
309 self,
310 *,
311 page: typing.Optional[int] = 0,
312 per_page: typing.Optional[int] = 50,
313 include_totals: typing.Optional[bool] = True,
314 enabled: typing.Optional[bool] = None,
315 fields: typing.Optional[str] = None,
316 include_fields: typing.Optional[bool] = None,
317 request_options: typing.Optional[RequestOptions] = None,
318 ) -> AsyncPager[Rule, ListRulesOffsetPaginatedResponseContent]:
319 """
320 Retrieve a filtered list of [rules](https://auth0.com/docs/rules). Accepts a list of fields to include or exclude.
321
322 Parameters
323 ----------
324 page : typing.Optional[int]
325 Page index of the results to return. First page is 0.
326
327 per_page : typing.Optional[int]
328 Number of results per page.
329
330 include_totals : typing.Optional[bool]
331 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
332
333 enabled : typing.Optional[bool]
334 Optional filter on whether a rule is enabled (true) or disabled (false).
335
336 fields : typing.Optional[str]
337 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.
338
339 include_fields : typing.Optional[bool]
340 Whether specified fields are to be included (true) or excluded (false).
341
342 request_options : typing.Optional[RequestOptions]
343 Request-specific configuration.
344
345 Returns
346 -------
347 AsyncPager[Rule, ListRulesOffsetPaginatedResponseContent]
348 Rules successfully retrieved.
349
350 Examples
351 --------
352 import asyncio
353
354 from auth0 import AsyncAuth0
355
356 client = AsyncAuth0(
357 token="YOUR_TOKEN",
358 )
359
360
361 async def main() -> None:
362 response = await client.rules.list(
363 page=1,
364 per_page=1,
365 include_totals=True,
366 enabled=True,
367 fields="fields",
368 include_fields=True,
369 )
370 async for item in response:
371 yield item
372
373 # alternatively, you can paginate page-by-page
374 async for page in response.iter_pages():
375 yield page
376
377
378 asyncio.run(main())
379 """
380 return await self._raw_client.list(
381 page=page,
382 per_page=per_page,
383 include_totals=include_totals,
384 enabled=enabled,
385 fields=fields,
386 include_fields=include_fields,
387 request_options=request_options,
388 )
389
390 async def create(
391 self,
392 *,
393 name: str,
394 script: str,
395 order: typing.Optional[float] = OMIT,
396 enabled: typing.Optional[bool] = OMIT,
397 request_options: typing.Optional[RequestOptions] = None,
398 ) -> CreateRuleResponseContent:
399 """
400 Create a [new rule](https://auth0.com/docs/rules#create-a-new-rule-using-the-management-api).
401
402 Note: Changing a rule's stage of execution from the default `login_success` can change the rule's function signature to have user omitted.
403
404 Parameters
405 ----------
406 name : str
407 Name of this rule.
408
409 script : str
410 Code to be executed when this rule runs.
411
412 order : typing.Optional[float]
413 Order that this rule should execute in relative to other rules. Lower-valued rules execute first.
414
415 enabled : typing.Optional[bool]
416 Whether the rule is enabled (true), or disabled (false).
417
418 request_options : typing.Optional[RequestOptions]
419 Request-specific configuration.
420
421 Returns
422 -------
423 CreateRuleResponseContent
424 Rule successfully created.
425
426 Examples
427 --------
428 import asyncio
429
430 from auth0 import AsyncAuth0
431
432 client = AsyncAuth0(
433 token="YOUR_TOKEN",
434 )
435
436
437 async def main() -> None:
438 await client.rules.create(
439 name="name",
440 script="script",
441 )
442
443
444 asyncio.run(main())
445 """
446 _response = await self._raw_client.create(
447 name=name, script=script, order=order, enabled=enabled, request_options=request_options
448 )
449 return _response.data
450
451 async def get(
452 self,
453 id: str,
454 *,
455 fields: typing.Optional[str] = None,
456 include_fields: typing.Optional[bool] = None,
457 request_options: typing.Optional[RequestOptions] = None,
458 ) -> GetRuleResponseContent:
459 """
460 Retrieve [rule](https://auth0.com/docs/rules) details. Accepts a list of fields to include or exclude in the result.
461
462 Parameters
463 ----------
464 id : str
465 ID of the rule to retrieve.
466
467 fields : typing.Optional[str]
468 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.
469
470 include_fields : typing.Optional[bool]
471 Whether specified fields are to be included (true) or excluded (false).
472
473 request_options : typing.Optional[RequestOptions]
474 Request-specific configuration.
475
476 Returns
477 -------
478 GetRuleResponseContent
479 Rule successfully retrieved.
480
481 Examples
482 --------
483 import asyncio
484
485 from auth0 import AsyncAuth0
486
487 client = AsyncAuth0(
488 token="YOUR_TOKEN",
489 )
490
491
492 async def main() -> None:
493 await client.rules.get(
494 id="id",
495 fields="fields",
496 include_fields=True,
497 )
498
499
500 asyncio.run(main())
501 """
502 _response = await self._raw_client.get(
503 id, fields=fields, include_fields=include_fields, request_options=request_options
504 )
505 return _response.data
506
507 async def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
508 """
509 Delete a rule.
510
511 Parameters
512 ----------
513 id : str
514 ID of the rule to delete.
515
516 request_options : typing.Optional[RequestOptions]
517 Request-specific configuration.
518
519 Returns
520 -------
521 None
522
523 Examples
524 --------
525 import asyncio
526
527 from auth0 import AsyncAuth0
528
529 client = AsyncAuth0(
530 token="YOUR_TOKEN",
531 )
532
533
534 async def main() -> None:
535 await client.rules.delete(
536 id="id",
537 )
538
539
540 asyncio.run(main())
541 """
542 _response = await self._raw_client.delete(id, request_options=request_options)
543 return _response.data
544
545 async def update(
546 self,
547 id: str,
548 *,
549 script: typing.Optional[str] = OMIT,
550 name: typing.Optional[str] = OMIT,
551 order: typing.Optional[float] = OMIT,
552 enabled: typing.Optional[bool] = OMIT,
553 request_options: typing.Optional[RequestOptions] = None,
554 ) -> UpdateRuleResponseContent:
555 """
556 Update an existing rule.
557
558 Parameters
559 ----------
560 id : str
561 ID of the rule to retrieve.
562
563 script : typing.Optional[str]
564 Code to be executed when this rule runs.
565
566 name : typing.Optional[str]
567 Name of this rule.
568
569 order : typing.Optional[float]
570 Order that this rule should execute in relative to other rules. Lower-valued rules execute first.
571
572 enabled : typing.Optional[bool]
573 Whether the rule is enabled (true), or disabled (false).
574
575 request_options : typing.Optional[RequestOptions]
576 Request-specific configuration.
577
578 Returns
579 -------
580 UpdateRuleResponseContent
581 Rule successfully updated.
582
583 Examples
584 --------
585 import asyncio
586
587 from auth0 import AsyncAuth0
588
589 client = AsyncAuth0(
590 token="YOUR_TOKEN",
591 )
592
593
594 async def main() -> None:
595 await client.rules.update(
596 id="id",
597 )
598
599
600 asyncio.run(main())
601 """
602 _response = await self._raw_client.update(
603 id, script=script, name=name, order=order, enabled=enabled, request_options=request_options
604 )
605 return _response.data