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