From 11a4fe0af4f6730c568cc408817df0203bbc6e8e Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Fri, 14 Jun 2024 15:53:40 +0400 Subject: [PATCH] return user from mutations --- api/python/quilt3-admin/queries.graphql | 4 + api/python/quilt3/admin/__init__.py | 18 +-- .../quilt3/admin/_graphql_client/add_roles.py | 4 +- .../quilt3/admin/_graphql_client/client.py | 144 ++++++++++++++++++ .../admin/_graphql_client/create_user.py | 4 +- .../admin/_graphql_client/remove_roles.py | 4 +- .../quilt3/admin/_graphql_client/set_role.py | 4 +- docs/api-reference/Admin.md | 8 +- 8 files changed, 169 insertions(+), 21 deletions(-) diff --git a/api/python/quilt3-admin/queries.graphql b/api/python/quilt3-admin/queries.graphql index cd296f85a59..beb9d608b9d 100644 --- a/api/python/quilt3-admin/queries.graphql +++ b/api/python/quilt3-admin/queries.graphql @@ -67,6 +67,7 @@ mutation createUser($input: UserInput!) { admin { user { create(input: $input) { + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } @@ -98,6 +99,7 @@ mutation setRole($name: String!, $role: String!, $extraRoles: [String!], $append user { mutate(name: $name) { setRole(role: $role, extraRoles: $extraRoles, append: $append) { + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } @@ -111,6 +113,7 @@ mutation addRoles($name: String!, $roles: [String!]!) { user { mutate(name: $name) { addRoles(roles: $roles) { + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } @@ -124,6 +127,7 @@ mutation removeRoles($name: String!, $roles: [String!]!, $fallback: String) { user { mutate(name: $name) { removeRoles(roles: $roles, fallback: $fallback) { + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } diff --git a/api/python/quilt3/admin/__init__.py b/api/python/quilt3/admin/__init__.py index defb245dc08..da71fe8a49a 100644 --- a/api/python/quilt3/admin/__init__.py +++ b/api/python/quilt3/admin/__init__.py @@ -87,7 +87,7 @@ def get_users() -> List[User]: return [User(**u.model_dump()) for u in _get_client().get_users()] -def create_user(name: str, email: str, role: str, extra_roles: Optional[List[str]] = None) -> None: +def create_user(name: str, email: str, role: str, extra_roles: Optional[List[str]] = None) -> User: """ Create a new user in the registry. @@ -98,11 +98,11 @@ def create_user(name: str, email: str, role: str, extra_roles: Optional[List[str extra_roles: Additional roles to assign to the user. """ - _handle_errors( + return User(**_handle_errors( _get_client().create_user( input=_graphql_client.UserInput(name=name, email=email, role=role, extraRoles=extra_roles) ) - ) + ).model_dump()) def delete_user(name: str) -> None: @@ -131,7 +131,7 @@ def set_role( extra_roles: Optional[List[str]] = None, *, append: bool = False, -) -> None: +) -> User: """ Set the active and extra roles for a user. @@ -144,10 +144,10 @@ def set_role( result = _get_client().set_role(name=name, role=role, extra_roles=extra_roles, append=append) if result is None: raise UserNotFoundError - _handle_errors(result.set_role) + return User(**_handle_errors(result.set_role).model_dump()) -def add_roles(name: str, roles: List[str]) -> None: +def add_roles(name: str, roles: List[str]) -> User: """ Add roles to a user. @@ -158,14 +158,14 @@ def add_roles(name: str, roles: List[str]) -> None: result = _get_client().add_roles(name=name, roles=roles) if result is None: raise UserNotFoundError - _handle_errors(result.add_roles) + return User(**_handle_errors(result.add_roles).model_dump()) def remove_roles( name: str, roles: List[str], fallback: Optional[str] = None, -) -> None: +) -> User: """ Remove roles from a user. @@ -177,4 +177,4 @@ def remove_roles( result = _get_client().remove_roles(name=name, roles=roles, fallback=fallback) if result is None: raise UserNotFoundError - _handle_errors(result.remove_roles) + return User(**_handle_errors(result.remove_roles).model_dump()) diff --git a/api/python/quilt3/admin/_graphql_client/add_roles.py b/api/python/quilt3/admin/_graphql_client/add_roles.py index e93622bca57..04aa9c3952e 100644 --- a/api/python/quilt3/admin/_graphql_client/add_roles.py +++ b/api/python/quilt3/admin/_graphql_client/add_roles.py @@ -6,7 +6,7 @@ from pydantic import Field from .base_model import BaseModel -from .fragments import InvalidInputSelection, OperationErrorSelection +from .fragments import InvalidInputSelection, OperationErrorSelection, UserSelection class AddRoles(BaseModel): @@ -29,7 +29,7 @@ class AddRolesAdminUserMutate(BaseModel): ] = Field(alias="addRoles", discriminator="typename__") -class AddRolesAdminUserMutateAddRolesUser(BaseModel): +class AddRolesAdminUserMutateAddRolesUser(UserSelection): typename__: Literal["User"] = Field(alias="__typename") diff --git a/api/python/quilt3/admin/_graphql_client/client.py b/api/python/quilt3/admin/_graphql_client/client.py index 21738387d2a..1e7e3787bb7 100644 --- a/api/python/quilt3/admin/_graphql_client/client.py +++ b/api/python/quilt3/admin/_graphql_client/client.py @@ -150,6 +150,7 @@ def create_user(self, input: UserInput, **kwargs: Any) -> Union[ user { create(input: $input) { __typename + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } @@ -166,11 +167,46 @@ def create_user(self, input: UserInput, **kwargs: Any) -> Union[ } } + fragment ManagedRoleSelection on ManagedRole { + id + name + arn + } + fragment OperationErrorSelection on OperationError { message name context } + + fragment RoleSelection on Role { + __typename + ...UnmanagedRoleSelection + ...ManagedRoleSelection + } + + fragment UnmanagedRoleSelection on UnmanagedRole { + id + name + arn + } + + fragment UserSelection on User { + name + email + dateJoined + lastLogin + isActive + isAdmin + isSsoOnly + isService + role { + ...RoleSelection + } + extraRoles { + ...RoleSelection + } + } """ ) variables: Dict[str, object] = {"input": input} @@ -275,6 +311,7 @@ def set_role( mutate(name: $name) { setRole(role: $role, extraRoles: $extraRoles, append: $append) { __typename + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } @@ -292,11 +329,46 @@ def set_role( } } + fragment ManagedRoleSelection on ManagedRole { + id + name + arn + } + fragment OperationErrorSelection on OperationError { message name context } + + fragment RoleSelection on Role { + __typename + ...UnmanagedRoleSelection + ...ManagedRoleSelection + } + + fragment UnmanagedRoleSelection on UnmanagedRole { + id + name + arn + } + + fragment UserSelection on User { + name + email + dateJoined + lastLogin + isActive + isAdmin + isSsoOnly + isService + role { + ...RoleSelection + } + extraRoles { + ...RoleSelection + } + } """ ) variables: Dict[str, object] = { @@ -322,6 +394,7 @@ def add_roles( mutate(name: $name) { addRoles(roles: $roles) { __typename + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } @@ -339,11 +412,46 @@ def add_roles( } } + fragment ManagedRoleSelection on ManagedRole { + id + name + arn + } + fragment OperationErrorSelection on OperationError { message name context } + + fragment RoleSelection on Role { + __typename + ...UnmanagedRoleSelection + ...ManagedRoleSelection + } + + fragment UnmanagedRoleSelection on UnmanagedRole { + id + name + arn + } + + fragment UserSelection on User { + name + email + dateJoined + lastLogin + isActive + isAdmin + isSsoOnly + isService + role { + ...RoleSelection + } + extraRoles { + ...RoleSelection + } + } """ ) variables: Dict[str, object] = {"name": name, "roles": roles} @@ -368,6 +476,7 @@ def remove_roles( mutate(name: $name) { removeRoles(roles: $roles, fallback: $fallback) { __typename + ...UserSelection ...InvalidInputSelection ...OperationErrorSelection } @@ -385,11 +494,46 @@ def remove_roles( } } + fragment ManagedRoleSelection on ManagedRole { + id + name + arn + } + fragment OperationErrorSelection on OperationError { message name context } + + fragment RoleSelection on Role { + __typename + ...UnmanagedRoleSelection + ...ManagedRoleSelection + } + + fragment UnmanagedRoleSelection on UnmanagedRole { + id + name + arn + } + + fragment UserSelection on User { + name + email + dateJoined + lastLogin + isActive + isAdmin + isSsoOnly + isService + role { + ...RoleSelection + } + extraRoles { + ...RoleSelection + } + } """ ) variables: Dict[str, object] = { diff --git a/api/python/quilt3/admin/_graphql_client/create_user.py b/api/python/quilt3/admin/_graphql_client/create_user.py index 44d162a6550..348dafb49cc 100644 --- a/api/python/quilt3/admin/_graphql_client/create_user.py +++ b/api/python/quilt3/admin/_graphql_client/create_user.py @@ -6,7 +6,7 @@ from pydantic import Field from .base_model import BaseModel -from .fragments import InvalidInputSelection, OperationErrorSelection +from .fragments import InvalidInputSelection, OperationErrorSelection, UserSelection class CreateUser(BaseModel): @@ -25,7 +25,7 @@ class CreateUserAdminUser(BaseModel): ] = Field(discriminator="typename__") -class CreateUserAdminUserCreateUser(BaseModel): +class CreateUserAdminUserCreateUser(UserSelection): typename__: Literal["User"] = Field(alias="__typename") diff --git a/api/python/quilt3/admin/_graphql_client/remove_roles.py b/api/python/quilt3/admin/_graphql_client/remove_roles.py index 323bab0deaa..62c010f2617 100644 --- a/api/python/quilt3/admin/_graphql_client/remove_roles.py +++ b/api/python/quilt3/admin/_graphql_client/remove_roles.py @@ -6,7 +6,7 @@ from pydantic import Field from .base_model import BaseModel -from .fragments import InvalidInputSelection, OperationErrorSelection +from .fragments import InvalidInputSelection, OperationErrorSelection, UserSelection class RemoveRoles(BaseModel): @@ -29,7 +29,7 @@ class RemoveRolesAdminUserMutate(BaseModel): ] = Field(alias="removeRoles", discriminator="typename__") -class RemoveRolesAdminUserMutateRemoveRolesUser(BaseModel): +class RemoveRolesAdminUserMutateRemoveRolesUser(UserSelection): typename__: Literal["User"] = Field(alias="__typename") diff --git a/api/python/quilt3/admin/_graphql_client/set_role.py b/api/python/quilt3/admin/_graphql_client/set_role.py index d0c4bd46601..f28929f830c 100644 --- a/api/python/quilt3/admin/_graphql_client/set_role.py +++ b/api/python/quilt3/admin/_graphql_client/set_role.py @@ -6,7 +6,7 @@ from pydantic import Field from .base_model import BaseModel -from .fragments import InvalidInputSelection, OperationErrorSelection +from .fragments import InvalidInputSelection, OperationErrorSelection, UserSelection class SetRole(BaseModel): @@ -29,7 +29,7 @@ class SetRoleAdminUserMutate(BaseModel): ] = Field(alias="setRole", discriminator="typename__") -class SetRoleAdminUserMutateSetRoleUser(BaseModel): +class SetRoleAdminUserMutateSetRoleUser(UserSelection): typename__: Literal["User"] = Field(alias="__typename") diff --git a/docs/api-reference/Admin.md b/docs/api-reference/Admin.md index 446ec6e3450..15dde225d04 100644 --- a/docs/api-reference/Admin.md +++ b/docs/api-reference/Admin.md @@ -27,7 +27,7 @@ __Arguments__ Get a list of all users in the registry. -## create\_user(name: str, email: str, role: str, extra\_roles: Optional[List[str]] = None) -> None {#create\_user} +## create\_user(name: str, email: str, role: str, extra\_roles: Optional[List[str]] = None) -> quilt3.admin.User {#create\_user} Create a new user in the registry. @@ -53,7 +53,7 @@ __Arguments__ Get a list of all roles in the registry. -## set\_role(name: str, role: str, extra\_roles: Optional[List[str]] = None, \*, append: bool = False) -> None {#set\_role} +## set\_role(name: str, role: str, extra\_roles: Optional[List[str]] = None, \*, append: bool = False) -> quilt3.admin.User {#set\_role} Set the active and extra roles for a user. @@ -65,7 +65,7 @@ __Arguments__ * __append__: If True, append the extra roles to the existing roles. If False, replace the existing roles. -## add\_roles(name: str, roles: List[str]) -> None {#add\_roles} +## add\_roles(name: str, roles: List[str]) -> quilt3.admin.User {#add\_roles} Add roles to a user. @@ -75,7 +75,7 @@ __Arguments__ * __roles__: Roles to add to the user. -## remove\_roles(name: str, roles: List[str], fallback: Optional[str] = None) -> None {#remove\_roles} +## remove\_roles(name: str, roles: List[str], fallback: Optional[str] = None) -> quilt3.admin.User {#remove\_roles} Remove roles from a user.