| 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_role_response_content import CreateRoleResponseContent |
| 11 |
from ..types.get_role_response_content import GetRoleResponseContent |
| 12 |
from ..types.list_roles_offset_paginated_response_content import ListRolesOffsetPaginatedResponseContent |
| 13 |
from ..types.role import Role |
| 14 |
from ..types.update_role_response_content import UpdateRoleResponseContent |
| 15 |
from .raw_client import AsyncRawRolesClient, RawRolesClient |
| 16 |
|
| 17 |
if typing.TYPE_CHECKING: |
| 18 |
from .groups.client import AsyncGroupsClient, GroupsClient |
| 19 |
from .permissions.client import AsyncPermissionsClient, PermissionsClient |
| 20 |
from .users.client import AsyncUsersClient, UsersClient |
| 21 |
|
| 22 |
OMIT = typing.cast(typing.Any, ...) |
| 23 |
|
| 24 |
|
| 25 |
class RolesClient: |
| 26 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 27 |
self._raw_client = RawRolesClient(client_wrapper=client_wrapper) |
| 28 |
self._client_wrapper = client_wrapper |
| 29 |
self._groups: typing.Optional[GroupsClient] = None |
| 30 |
self._permissions: typing.Optional[PermissionsClient] = None |
| 31 |
self._users: typing.Optional[UsersClient] = None |
| 32 |
|
| 33 |
@property |
| 34 |
def with_raw_response(self) -> RawRolesClient: |
| 35 |
""" |
| 36 |
Retrieves a raw implementation of this client that returns raw responses. |
| 37 |
|
| 38 |
Returns |
| 39 |
------- |
| 40 |
RawRolesClient |
| 41 |
""" |
| 42 |
return self._raw_client |
| 43 |
|
| 44 |
def list( |
| 45 |
self, |
| 46 |
*, |
| 47 |
per_page: typing.Optional[int] = 50, |
| 48 |
page: typing.Optional[int] = 0, |
| 49 |
include_totals: typing.Optional[bool] = True, |
| 50 |
name_filter: typing.Optional[str] = None, |
| 51 |
request_options: typing.Optional[RequestOptions] = None, |
| 52 |
) -> SyncPager[Role, ListRolesOffsetPaginatedResponseContent]: |
| 53 |
""" |
| 54 |
Retrieve detailed list of user roles created in your tenant. |
| 55 |
|
| 56 |
**Note**: The returned list does not include standard roles available for tenant members, such as Admin or Support Access. |
| 57 |
|
| 58 |
Parameters |
| 59 |
---------- |
| 60 |
per_page : typing.Optional[int] |
| 61 |
Number of results per page. Defaults to 50. |
| 62 |
|
| 63 |
page : typing.Optional[int] |
| 64 |
Page index of the results to return. First page is 0. |
| 65 |
|
| 66 |
include_totals : typing.Optional[bool] |
| 67 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 68 |
|
| 69 |
name_filter : typing.Optional[str] |
| 70 |
Optional filter on name (case-insensitive). |
| 71 |
|
| 72 |
request_options : typing.Optional[RequestOptions] |
| 73 |
Request-specific configuration. |
| 74 |
|
| 75 |
Returns |
| 76 |
------- |
| 77 |
SyncPager[Role, ListRolesOffsetPaginatedResponseContent] |
| 78 |
Roles successfully retrieved. |
| 79 |
|
| 80 |
Examples |
| 81 |
-------- |
| 82 |
from auth0 import Auth0 |
| 83 |
|
| 84 |
client = Auth0( |
| 85 |
token="YOUR_TOKEN", |
| 86 |
) |
| 87 |
response = client.roles.list( |
| 88 |
per_page=1, |
| 89 |
page=1, |
| 90 |
include_totals=True, |
| 91 |
name_filter="name_filter", |
| 92 |
) |
| 93 |
for item in response: |
| 94 |
yield item |
| 95 |
# alternatively, you can paginate page-by-page |
| 96 |
for page in response.iter_pages(): |
| 97 |
yield page |
| 98 |
""" |
| 99 |
return self._raw_client.list( |
| 100 |
per_page=per_page, |
| 101 |
page=page, |
| 102 |
include_totals=include_totals, |
| 103 |
name_filter=name_filter, |
| 104 |
request_options=request_options, |
| 105 |
) |
| 106 |
|
| 107 |
def create( |
| 108 |
self, |
| 109 |
*, |
| 110 |
name: str, |
| 111 |
description: typing.Optional[str] = OMIT, |
| 112 |
request_options: typing.Optional[RequestOptions] = None, |
| 113 |
) -> CreateRoleResponseContent: |
| 114 |
""" |
| 115 |
Create a user role for [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac). |
| 116 |
|
| 117 |
**Note**: New roles are not associated with any permissions by default. To assign existing permissions to your role, review Associate Permissions with a Role. To create new permissions, review Add API Permissions. |
| 118 |
|
| 119 |
Parameters |
| 120 |
---------- |
| 121 |
name : str |
| 122 |
Name of the role. |
| 123 |
|
| 124 |
description : typing.Optional[str] |
| 125 |
Description of the role. |
| 126 |
|
| 127 |
request_options : typing.Optional[RequestOptions] |
| 128 |
Request-specific configuration. |
| 129 |
|
| 130 |
Returns |
| 131 |
------- |
| 132 |
CreateRoleResponseContent |
| 133 |
Role successfully created. |
| 134 |
|
| 135 |
Examples |
| 136 |
-------- |
| 137 |
from auth0 import Auth0 |
| 138 |
|
| 139 |
client = Auth0( |
| 140 |
token="YOUR_TOKEN", |
| 141 |
) |
| 142 |
client.roles.create( |
| 143 |
name="name", |
| 144 |
) |
| 145 |
""" |
| 146 |
_response = self._raw_client.create(name=name, description=description, request_options=request_options) |
| 147 |
return _response.data |
| 148 |
|
| 149 |
def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetRoleResponseContent: |
| 150 |
""" |
| 151 |
Retrieve details about a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID. |
| 152 |
|
| 153 |
Parameters |
| 154 |
---------- |
| 155 |
id : str |
| 156 |
ID of the role to retrieve. |
| 157 |
|
| 158 |
request_options : typing.Optional[RequestOptions] |
| 159 |
Request-specific configuration. |
| 160 |
|
| 161 |
Returns |
| 162 |
------- |
| 163 |
GetRoleResponseContent |
| 164 |
Role successfully retrieved. |
| 165 |
|
| 166 |
Examples |
| 167 |
-------- |
| 168 |
from auth0 import Auth0 |
| 169 |
|
| 170 |
client = Auth0( |
| 171 |
token="YOUR_TOKEN", |
| 172 |
) |
| 173 |
client.roles.get( |
| 174 |
id="id", |
| 175 |
) |
| 176 |
""" |
| 177 |
_response = self._raw_client.get(id, request_options=request_options) |
| 178 |
return _response.data |
| 179 |
|
| 180 |
def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None: |
| 181 |
""" |
| 182 |
Delete a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) from your tenant. Once deleted, it is removed from any user who was previously assigned that role. This action cannot be undone. |
| 183 |
|
| 184 |
Parameters |
| 185 |
---------- |
| 186 |
id : str |
| 187 |
ID of the role to delete. |
| 188 |
|
| 189 |
request_options : typing.Optional[RequestOptions] |
| 190 |
Request-specific configuration. |
| 191 |
|
| 192 |
Returns |
| 193 |
------- |
| 194 |
None |
| 195 |
|
| 196 |
Examples |
| 197 |
-------- |
| 198 |
from auth0 import Auth0 |
| 199 |
|
| 200 |
client = Auth0( |
| 201 |
token="YOUR_TOKEN", |
| 202 |
) |
| 203 |
client.roles.delete( |
| 204 |
id="id", |
| 205 |
) |
| 206 |
""" |
| 207 |
_response = self._raw_client.delete(id, request_options=request_options) |
| 208 |
return _response.data |
| 209 |
|
| 210 |
def update( |
| 211 |
self, |
| 212 |
id: str, |
| 213 |
*, |
| 214 |
name: typing.Optional[str] = OMIT, |
| 215 |
description: typing.Optional[str] = OMIT, |
| 216 |
request_options: typing.Optional[RequestOptions] = None, |
| 217 |
) -> UpdateRoleResponseContent: |
| 218 |
""" |
| 219 |
Modify the details of a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID. |
| 220 |
|
| 221 |
Parameters |
| 222 |
---------- |
| 223 |
id : str |
| 224 |
ID of the role to update. |
| 225 |
|
| 226 |
name : typing.Optional[str] |
| 227 |
Name of this role. |
| 228 |
|
| 229 |
description : typing.Optional[str] |
| 230 |
Description of this role. |
| 231 |
|
| 232 |
request_options : typing.Optional[RequestOptions] |
| 233 |
Request-specific configuration. |
| 234 |
|
| 235 |
Returns |
| 236 |
------- |
| 237 |
UpdateRoleResponseContent |
| 238 |
Role successfully updated. |
| 239 |
|
| 240 |
Examples |
| 241 |
-------- |
| 242 |
from auth0 import Auth0 |
| 243 |
|
| 244 |
client = Auth0( |
| 245 |
token="YOUR_TOKEN", |
| 246 |
) |
| 247 |
client.roles.update( |
| 248 |
id="id", |
| 249 |
) |
| 250 |
""" |
| 251 |
_response = self._raw_client.update(id, name=name, description=description, request_options=request_options) |
| 252 |
return _response.data |
| 253 |
|
| 254 |
@property |
| 255 |
def groups(self): |
| 256 |
if self._groups is None: |
| 257 |
from .groups.client import GroupsClient |
| 258 |
|
| 259 |
self._groups = GroupsClient(client_wrapper=self._client_wrapper) |
| 260 |
return self._groups |
| 261 |
|
| 262 |
@property |
| 263 |
def permissions(self): |
| 264 |
if self._permissions is None: |
| 265 |
from .permissions.client import PermissionsClient |
| 266 |
|
| 267 |
self._permissions = PermissionsClient(client_wrapper=self._client_wrapper) |
| 268 |
return self._permissions |
| 269 |
|
| 270 |
@property |
| 271 |
def users(self): |
| 272 |
if self._users is None: |
| 273 |
from .users.client import UsersClient |
| 274 |
|
| 275 |
self._users = UsersClient(client_wrapper=self._client_wrapper) |
| 276 |
return self._users |
| 277 |
|
| 278 |
|
| 279 |
class AsyncRolesClient: |
| 280 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 281 |
self._raw_client = AsyncRawRolesClient(client_wrapper=client_wrapper) |
| 282 |
self._client_wrapper = client_wrapper |
| 283 |
self._groups: typing.Optional[AsyncGroupsClient] = None |
| 284 |
self._permissions: typing.Optional[AsyncPermissionsClient] = None |
| 285 |
self._users: typing.Optional[AsyncUsersClient] = None |
| 286 |
|
| 287 |
@property |
| 288 |
def with_raw_response(self) -> AsyncRawRolesClient: |
| 289 |
""" |
| 290 |
Retrieves a raw implementation of this client that returns raw responses. |
| 291 |
|
| 292 |
Returns |
| 293 |
------- |
| 294 |
AsyncRawRolesClient |
| 295 |
""" |
| 296 |
return self._raw_client |
| 297 |
|
| 298 |
async def list( |
| 299 |
self, |
| 300 |
*, |
| 301 |
per_page: typing.Optional[int] = 50, |
| 302 |
page: typing.Optional[int] = 0, |
| 303 |
include_totals: typing.Optional[bool] = True, |
| 304 |
name_filter: typing.Optional[str] = None, |
| 305 |
request_options: typing.Optional[RequestOptions] = None, |
| 306 |
) -> AsyncPager[Role, ListRolesOffsetPaginatedResponseContent]: |
| 307 |
""" |
| 308 |
Retrieve detailed list of user roles created in your tenant. |
| 309 |
|
| 310 |
**Note**: The returned list does not include standard roles available for tenant members, such as Admin or Support Access. |
| 311 |
|
| 312 |
Parameters |
| 313 |
---------- |
| 314 |
per_page : typing.Optional[int] |
| 315 |
Number of results per page. Defaults to 50. |
| 316 |
|
| 317 |
page : typing.Optional[int] |
| 318 |
Page index of the results to return. First page is 0. |
| 319 |
|
| 320 |
include_totals : typing.Optional[bool] |
| 321 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 322 |
|
| 323 |
name_filter : typing.Optional[str] |
| 324 |
Optional filter on name (case-insensitive). |
| 325 |
|
| 326 |
request_options : typing.Optional[RequestOptions] |
| 327 |
Request-specific configuration. |
| 328 |
|
| 329 |
Returns |
| 330 |
------- |
| 331 |
AsyncPager[Role, ListRolesOffsetPaginatedResponseContent] |
| 332 |
Roles successfully retrieved. |
| 333 |
|
| 334 |
Examples |
| 335 |
-------- |
| 336 |
import asyncio |
| 337 |
|
| 338 |
from auth0 import AsyncAuth0 |
| 339 |
|
| 340 |
client = AsyncAuth0( |
| 341 |
token="YOUR_TOKEN", |
| 342 |
) |
| 343 |
|
| 344 |
|
| 345 |
async def main() -> None: |
| 346 |
response = await client.roles.list( |
| 347 |
per_page=1, |
| 348 |
page=1, |
| 349 |
include_totals=True, |
| 350 |
name_filter="name_filter", |
| 351 |
) |
| 352 |
async for item in response: |
| 353 |
yield item |
| 354 |
|
| 355 |
# alternatively, you can paginate page-by-page |
| 356 |
async for page in response.iter_pages(): |
| 357 |
yield page |
| 358 |
|
| 359 |
|
| 360 |
asyncio.run(main()) |
| 361 |
""" |
| 362 |
return await self._raw_client.list( |
| 363 |
per_page=per_page, |
| 364 |
page=page, |
| 365 |
include_totals=include_totals, |
| 366 |
name_filter=name_filter, |
| 367 |
request_options=request_options, |
| 368 |
) |
| 369 |
|
| 370 |
async def create( |
| 371 |
self, |
| 372 |
*, |
| 373 |
name: str, |
| 374 |
description: typing.Optional[str] = OMIT, |
| 375 |
request_options: typing.Optional[RequestOptions] = None, |
| 376 |
) -> CreateRoleResponseContent: |
| 377 |
""" |
| 378 |
Create a user role for [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac). |
| 379 |
|
| 380 |
**Note**: New roles are not associated with any permissions by default. To assign existing permissions to your role, review Associate Permissions with a Role. To create new permissions, review Add API Permissions. |
| 381 |
|
| 382 |
Parameters |
| 383 |
---------- |
| 384 |
name : str |
| 385 |
Name of the role. |
| 386 |
|
| 387 |
description : typing.Optional[str] |
| 388 |
Description of the role. |
| 389 |
|
| 390 |
request_options : typing.Optional[RequestOptions] |
| 391 |
Request-specific configuration. |
| 392 |
|
| 393 |
Returns |
| 394 |
------- |
| 395 |
CreateRoleResponseContent |
| 396 |
Role successfully created. |
| 397 |
|
| 398 |
Examples |
| 399 |
-------- |
| 400 |
import asyncio |
| 401 |
|
| 402 |
from auth0 import AsyncAuth0 |
| 403 |
|
| 404 |
client = AsyncAuth0( |
| 405 |
token="YOUR_TOKEN", |
| 406 |
) |
| 407 |
|
| 408 |
|
| 409 |
async def main() -> None: |
| 410 |
await client.roles.create( |
| 411 |
name="name", |
| 412 |
) |
| 413 |
|
| 414 |
|
| 415 |
asyncio.run(main()) |
| 416 |
""" |
| 417 |
_response = await self._raw_client.create(name=name, description=description, request_options=request_options) |
| 418 |
return _response.data |
| 419 |
|
| 420 |
async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetRoleResponseContent: |
| 421 |
""" |
| 422 |
Retrieve details about a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID. |
| 423 |
|
| 424 |
Parameters |
| 425 |
---------- |
| 426 |
id : str |
| 427 |
ID of the role to retrieve. |
| 428 |
|
| 429 |
request_options : typing.Optional[RequestOptions] |
| 430 |
Request-specific configuration. |
| 431 |
|
| 432 |
Returns |
| 433 |
------- |
| 434 |
GetRoleResponseContent |
| 435 |
Role successfully retrieved. |
| 436 |
|
| 437 |
Examples |
| 438 |
-------- |
| 439 |
import asyncio |
| 440 |
|
| 441 |
from auth0 import AsyncAuth0 |
| 442 |
|
| 443 |
client = AsyncAuth0( |
| 444 |
token="YOUR_TOKEN", |
| 445 |
) |
| 446 |
|
| 447 |
|
| 448 |
async def main() -> None: |
| 449 |
await client.roles.get( |
| 450 |
id="id", |
| 451 |
) |
| 452 |
|
| 453 |
|
| 454 |
asyncio.run(main()) |
| 455 |
""" |
| 456 |
_response = await self._raw_client.get(id, request_options=request_options) |
| 457 |
return _response.data |
| 458 |
|
| 459 |
async def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None: |
| 460 |
""" |
| 461 |
Delete a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) from your tenant. Once deleted, it is removed from any user who was previously assigned that role. This action cannot be undone. |
| 462 |
|
| 463 |
Parameters |
| 464 |
---------- |
| 465 |
id : str |
| 466 |
ID of the role to delete. |
| 467 |
|
| 468 |
request_options : typing.Optional[RequestOptions] |
| 469 |
Request-specific configuration. |
| 470 |
|
| 471 |
Returns |
| 472 |
------- |
| 473 |
None |
| 474 |
|
| 475 |
Examples |
| 476 |
-------- |
| 477 |
import asyncio |
| 478 |
|
| 479 |
from auth0 import AsyncAuth0 |
| 480 |
|
| 481 |
client = AsyncAuth0( |
| 482 |
token="YOUR_TOKEN", |
| 483 |
) |
| 484 |
|
| 485 |
|
| 486 |
async def main() -> None: |
| 487 |
await client.roles.delete( |
| 488 |
id="id", |
| 489 |
) |
| 490 |
|
| 491 |
|
| 492 |
asyncio.run(main()) |
| 493 |
""" |
| 494 |
_response = await self._raw_client.delete(id, request_options=request_options) |
| 495 |
return _response.data |
| 496 |
|
| 497 |
async def update( |
| 498 |
self, |
| 499 |
id: str, |
| 500 |
*, |
| 501 |
name: typing.Optional[str] = OMIT, |
| 502 |
description: typing.Optional[str] = OMIT, |
| 503 |
request_options: typing.Optional[RequestOptions] = None, |
| 504 |
) -> UpdateRoleResponseContent: |
| 505 |
""" |
| 506 |
Modify the details of a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID. |
| 507 |
|
| 508 |
Parameters |
| 509 |
---------- |
| 510 |
id : str |
| 511 |
ID of the role to update. |
| 512 |
|
| 513 |
name : typing.Optional[str] |
| 514 |
Name of this role. |
| 515 |
|
| 516 |
description : typing.Optional[str] |
| 517 |
Description of this role. |
| 518 |
|
| 519 |
request_options : typing.Optional[RequestOptions] |
| 520 |
Request-specific configuration. |
| 521 |
|
| 522 |
Returns |
| 523 |
------- |
| 524 |
UpdateRoleResponseContent |
| 525 |
Role successfully updated. |
| 526 |
|
| 527 |
Examples |
| 528 |
-------- |
| 529 |
import asyncio |
| 530 |
|
| 531 |
from auth0 import AsyncAuth0 |
| 532 |
|
| 533 |
client = AsyncAuth0( |
| 534 |
token="YOUR_TOKEN", |
| 535 |
) |
| 536 |
|
| 537 |
|
| 538 |
async def main() -> None: |
| 539 |
await client.roles.update( |
| 540 |
id="id", |
| 541 |
) |
| 542 |
|
| 543 |
|
| 544 |
asyncio.run(main()) |
| 545 |
""" |
| 546 |
_response = await self._raw_client.update( |
| 547 |
id, name=name, description=description, request_options=request_options |
| 548 |
) |
| 549 |
return _response.data |
| 550 |
|
| 551 |
@property |
| 552 |
def groups(self): |
| 553 |
if self._groups is None: |
| 554 |
from .groups.client import AsyncGroupsClient |
| 555 |
|
| 556 |
self._groups = AsyncGroupsClient(client_wrapper=self._client_wrapper) |
| 557 |
return self._groups |
| 558 |
|
| 559 |
@property |
| 560 |
def permissions(self): |
| 561 |
if self._permissions is None: |
| 562 |
from .permissions.client import AsyncPermissionsClient |
| 563 |
|
| 564 |
self._permissions = AsyncPermissionsClient(client_wrapper=self._client_wrapper) |
| 565 |
return self._permissions |
| 566 |
|
| 567 |
@property |
| 568 |
def users(self): |
| 569 |
if self._users is None: |
| 570 |
from .users.client import AsyncUsersClient |
| 571 |
|
| 572 |
self._users = AsyncUsersClient(client_wrapper=self._client_wrapper) |
| 573 |
return self._users |