From 174a8bf87da40929e0d97ab6e178b2e4aff9f470 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Fri, 14 Jun 2024 16:45:44 +0400 Subject: [PATCH] more user api --- api/python/quilt3-admin/queries.graphql | 64 +++- api/python/quilt3/admin/__init__.py | 77 ++++- .../quilt3/admin/_graphql_client/__init__.py | 64 ++++ .../quilt3/admin/_graphql_client/client.py | 321 +++++++++++++++++- .../_graphql_client/reset_user_password.py | 49 +++ .../admin/_graphql_client/set_user_active.py | 47 +++ .../admin/_graphql_client/set_user_admin.py | 47 +++ .../admin/_graphql_client/set_user_email.py | 47 +++ docs/api-reference/Admin.md | 43 ++- 9 files changed, 731 insertions(+), 28 deletions(-) create mode 100644 api/python/quilt3/admin/_graphql_client/reset_user_password.py create mode 100644 api/python/quilt3/admin/_graphql_client/set_user_active.py create mode 100644 api/python/quilt3/admin/_graphql_client/set_user_admin.py create mode 100644 api/python/quilt3/admin/_graphql_client/set_user_email.py diff --git a/api/python/quilt3-admin/queries.graphql b/api/python/quilt3-admin/queries.graphql index beb9d608b9d..7ce6ff1af6d 100644 --- a/api/python/quilt3-admin/queries.graphql +++ b/api/python/quilt3-admin/queries.graphql @@ -29,6 +29,11 @@ fragment UserSelection on User { ...RoleSelection } } +fragment UserMutationSelection on UserResult { + ...UserSelection + ...InvalidInputSelection + ...OperationErrorSelection +} fragment InvalidInputSelection on InvalidInput { errors { path @@ -43,6 +48,12 @@ fragment OperationErrorSelection on OperationError { context } +query getRoles { + roles { + ...RoleSelection + } +} + query getUser($name: String!) { admin { user { @@ -67,9 +78,7 @@ mutation createUser($input: UserInput!) { admin { user { create(input: $input) { - ...UserSelection - ...InvalidInputSelection - ...OperationErrorSelection + ...UserMutationSelection } } } @@ -88,9 +97,52 @@ mutation deleteUser($name: String!) { } } -query getRoles { - roles { - ...RoleSelection +mutation setUserEmail($email: String!, $name: String!) { + admin { + user { + mutate(name: $name) { + setEmail(email: $email) { + ...UserMutationSelection + } + } + } + } +} + +mutation setUserAdmin($name: String!, $admin: Boolean!) { + admin { + user { + mutate(name: $name) { + setAdmin(admin: $admin) { + ...UserMutationSelection + } + } + } + } +} + +mutation setUserActive($active: Boolean!, $name: String!) { + admin { + user { + mutate(name: $name) { + setActive(active: $active) { + ...UserMutationSelection + } + } + } + } +} + +mutation resetUserPassword($name: String!) { + admin { + user { + mutate(name: $name) { + resetPassword { + ...InvalidInputSelection + ...OperationErrorSelection + } + } + } } } diff --git a/api/python/quilt3/admin/__init__.py b/api/python/quilt3/admin/__init__.py index da71fe8a49a..148604cd29e 100644 --- a/api/python/quilt3/admin/__init__.py +++ b/api/python/quilt3/admin/__init__.py @@ -57,16 +57,27 @@ def __init__(self): super().__init__(None) -def _handle_errors(result: _graphql_client.BaseModel) -> Any: +def _handle_errors(result: _graphql_client.BaseModel) -> _graphql_client.BaseModel: if isinstance(result, (_graphql_client.InvalidInputSelection, _graphql_client.OperationErrorSelection)): raise Quilt3AdminError(result) return result +def _handle_user_mutation(result: _graphql_client.BaseModel) -> User: + return User(**_handle_errors(result).model_dump()) + + def _get_client(): return _graphql_client.Client() +def get_roles() -> List[Role]: + """ + Get a list of all roles in the registry. + """ + return [role_adapter.validate_python(r.model_dump()) for r in _get_client().get_roles()] + + def get_user(name: str) -> Optional[User]: """ Get a specific user from the registry. Return `None` if the user does not exist. @@ -98,11 +109,11 @@ def create_user(name: str, email: str, role: str, extra_roles: Optional[List[str extra_roles: Additional roles to assign to the user. """ - return User(**_handle_errors( + return _handle_user_mutation( _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: @@ -118,11 +129,59 @@ def delete_user(name: str) -> None: _handle_errors(result.delete) -def get_roles() -> List[Role]: +def set_user_email(name: str, email: str) -> User: """ - Get a list of all roles in the registry. + Set the email for a user. + + Args: + name: Username of user to update. + email: Email to set for the user. """ - return [role_adapter.validate_python(r.model_dump()) for r in _get_client().get_roles()] + result = _get_client().set_user_email(name=name, email=email) + if result is None: + raise UserNotFoundError + return _handle_user_mutation(result.set_email) + + +def set_user_admin(name: str, admin: bool) -> User: + """ + Set the admin status for a user. + + Args: + name: Username of user to update. + admin: Admin status to set for the user. + """ + result = _get_client().set_user_admin(name=name, admin=admin) + if result is None: + raise UserNotFoundError + return _handle_user_mutation(result.set_admin) + + +def set_user_active(name: str, active: bool) -> User: + """ + Set the active status for a user. + + Args: + name: Username of user to update. + active: Active status to set for the user. + """ + result = _get_client().set_user_active(name=name, active=active) + if result is None: + raise UserNotFoundError + return _handle_user_mutation(result.set_active) + + +def reset_user_password(name: str) -> None: + """ + Reset the password for a user. + + Args: + name: Username of user to update. + """ + result = _get_client().reset_user_password(name=name) + if result is None: + raise UserNotFoundError + _handle_errors(result.reset_password) def set_role( @@ -144,7 +203,7 @@ def set_role( result = _get_client().set_role(name=name, role=role, extra_roles=extra_roles, append=append) if result is None: raise UserNotFoundError - return User(**_handle_errors(result.set_role).model_dump()) + return _handle_user_mutation(result.set_role) def add_roles(name: str, roles: List[str]) -> User: @@ -158,7 +217,7 @@ def add_roles(name: str, roles: List[str]) -> User: result = _get_client().add_roles(name=name, roles=roles) if result is None: raise UserNotFoundError - return User(**_handle_errors(result.add_roles).model_dump()) + return _handle_user_mutation(result.add_roles) def remove_roles( @@ -177,4 +236,4 @@ def remove_roles( result = _get_client().remove_roles(name=name, roles=roles, fallback=fallback) if result is None: raise UserNotFoundError - return User(**_handle_errors(result.remove_roles).model_dump()) + return _handle_user_mutation(result.remove_roles) diff --git a/api/python/quilt3/admin/_graphql_client/__init__.py b/api/python/quilt3/admin/_graphql_client/__init__.py index 3fce151f497..15a154c05ab 100644 --- a/api/python/quilt3/admin/_graphql_client/__init__.py +++ b/api/python/quilt3/admin/_graphql_client/__init__.py @@ -54,6 +54,15 @@ RemoveRolesAdminUserMutateRemoveRolesOperationError, RemoveRolesAdminUserMutateRemoveRolesUser, ) +from .reset_user_password import ( + ResetUserPassword, + ResetUserPasswordAdmin, + ResetUserPasswordAdminUser, + ResetUserPasswordAdminUserMutate, + ResetUserPasswordAdminUserMutateResetPasswordInvalidInput, + ResetUserPasswordAdminUserMutateResetPasswordOk, + ResetUserPasswordAdminUserMutateResetPasswordOperationError, +) from .set_role import ( SetRole, SetRoleAdmin, @@ -63,6 +72,33 @@ SetRoleAdminUserMutateSetRoleOperationError, SetRoleAdminUserMutateSetRoleUser, ) +from .set_user_active import ( + SetUserActive, + SetUserActiveAdmin, + SetUserActiveAdminUser, + SetUserActiveAdminUserMutate, + SetUserActiveAdminUserMutateSetActiveInvalidInput, + SetUserActiveAdminUserMutateSetActiveOperationError, + SetUserActiveAdminUserMutateSetActiveUser, +) +from .set_user_admin import ( + SetUserAdmin, + SetUserAdminAdmin, + SetUserAdminAdminUser, + SetUserAdminAdminUserMutate, + SetUserAdminAdminUserMutateSetAdminInvalidInput, + SetUserAdminAdminUserMutateSetAdminOperationError, + SetUserAdminAdminUserMutateSetAdminUser, +) +from .set_user_email import ( + SetUserEmail, + SetUserEmailAdmin, + SetUserEmailAdminUser, + SetUserEmailAdminUserMutate, + SetUserEmailAdminUserMutateSetEmailInvalidInput, + SetUserEmailAdminUserMutateSetEmailOperationError, + SetUserEmailAdminUserMutateSetEmailUser, +) __all__ = [ "AddRoles", @@ -110,6 +146,13 @@ "RemoveRolesAdminUserMutateRemoveRolesInvalidInput", "RemoveRolesAdminUserMutateRemoveRolesOperationError", "RemoveRolesAdminUserMutateRemoveRolesUser", + "ResetUserPassword", + "ResetUserPasswordAdmin", + "ResetUserPasswordAdminUser", + "ResetUserPasswordAdminUserMutate", + "ResetUserPasswordAdminUserMutateResetPasswordInvalidInput", + "ResetUserPasswordAdminUserMutateResetPasswordOk", + "ResetUserPasswordAdminUserMutateResetPasswordOperationError", "SetRole", "SetRoleAdmin", "SetRoleAdminUser", @@ -117,6 +160,27 @@ "SetRoleAdminUserMutateSetRoleInvalidInput", "SetRoleAdminUserMutateSetRoleOperationError", "SetRoleAdminUserMutateSetRoleUser", + "SetUserActive", + "SetUserActiveAdmin", + "SetUserActiveAdminUser", + "SetUserActiveAdminUserMutate", + "SetUserActiveAdminUserMutateSetActiveInvalidInput", + "SetUserActiveAdminUserMutateSetActiveOperationError", + "SetUserActiveAdminUserMutateSetActiveUser", + "SetUserAdmin", + "SetUserAdminAdmin", + "SetUserAdminAdminUser", + "SetUserAdminAdminUserMutate", + "SetUserAdminAdminUserMutateSetAdminInvalidInput", + "SetUserAdminAdminUserMutateSetAdminOperationError", + "SetUserAdminAdminUserMutateSetAdminUser", + "SetUserEmail", + "SetUserEmailAdmin", + "SetUserEmailAdminUser", + "SetUserEmailAdminUserMutate", + "SetUserEmailAdminUserMutateSetEmailInvalidInput", + "SetUserEmailAdminUserMutateSetEmailOperationError", + "SetUserEmailAdminUserMutateSetEmailUser", "UnmanagedRoleSelection", "Upload", "UserInput", diff --git a/api/python/quilt3/admin/_graphql_client/client.py b/api/python/quilt3/admin/_graphql_client/client.py index 1e7e3787bb7..648257d2637 100644 --- a/api/python/quilt3/admin/_graphql_client/client.py +++ b/api/python/quilt3/admin/_graphql_client/client.py @@ -18,7 +18,11 @@ from .get_users import GetUsers, GetUsersAdminUserList from .input_types import UserInput from .remove_roles import RemoveRoles, RemoveRolesAdminUserMutate +from .reset_user_password import ResetUserPassword, ResetUserPasswordAdminUserMutate from .set_role import SetRole, SetRoleAdminUserMutate +from .set_user_active import SetUserActive, SetUserActiveAdminUserMutate +from .set_user_admin import SetUserAdmin, SetUserAdminAdminUserMutate +from .set_user_email import SetUserEmail, SetUserEmailAdminUserMutate def gql(q: str) -> str: @@ -26,6 +30,43 @@ def gql(q: str) -> str: class Client(BaseClient): + def get_roles( + self, **kwargs: Any + ) -> List[Union[GetRolesRolesUnmanagedRole, GetRolesRolesManagedRole]]: + query = gql( + """ + query getRoles { + roles { + ...RoleSelection + } + } + + fragment ManagedRoleSelection on ManagedRole { + id + name + arn + } + + fragment RoleSelection on Role { + __typename + ...UnmanagedRoleSelection + ...ManagedRoleSelection + } + + fragment UnmanagedRoleSelection on UnmanagedRole { + id + name + arn + } + """ + ) + variables: Dict[str, object] = {} + response = self.execute( + query=query, operation_name="getRoles", variables=variables, **kwargs + ) + data = self.get_data(response) + return GetRoles.model_validate(data).roles + def get_user(self, name: str, **kwargs: Any) -> Optional[GetUserAdminUserGet]: query = gql( """ @@ -150,9 +191,7 @@ def create_user(self, input: UserInput, **kwargs: Any) -> Union[ user { create(input: $input) { __typename - ...UserSelection - ...InvalidInputSelection - ...OperationErrorSelection + ...UserMutationSelection } } } @@ -191,6 +230,12 @@ def create_user(self, input: UserInput, **kwargs: Any) -> Union[ arn } + fragment UserMutationSelection on UserResult { + ...UserSelection + ...InvalidInputSelection + ...OperationErrorSelection + } + fragment UserSelection on User { name email @@ -258,16 +303,196 @@ def delete_user( data = self.get_data(response) return DeleteUser.model_validate(data).admin.user.mutate - def get_roles( - self, **kwargs: Any - ) -> List[Union[GetRolesRolesUnmanagedRole, GetRolesRolesManagedRole]]: + def set_user_email( + self, email: str, name: str, **kwargs: Any + ) -> Optional[SetUserEmailAdminUserMutate]: query = gql( """ - query getRoles { - roles { + mutation setUserEmail($email: String!, $name: String!) { + admin { + user { + mutate(name: $name) { + setEmail(email: $email) { + __typename + ...UserMutationSelection + } + } + } + } + } + + fragment InvalidInputSelection on InvalidInput { + errors { + path + message + name + context + } + } + + 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 UserMutationSelection on UserResult { + ...UserSelection + ...InvalidInputSelection + ...OperationErrorSelection + } + + fragment UserSelection on User { + name + email + dateJoined + lastLogin + isActive + isAdmin + isSsoOnly + isService + role { + ...RoleSelection + } + extraRoles { + ...RoleSelection + } + } + """ + ) + variables: Dict[str, object] = {"email": email, "name": name} + response = self.execute( + query=query, operation_name="setUserEmail", variables=variables, **kwargs + ) + data = self.get_data(response) + return SetUserEmail.model_validate(data).admin.user.mutate + + def set_user_admin( + self, name: str, admin: bool, **kwargs: Any + ) -> Optional[SetUserAdminAdminUserMutate]: + query = gql( + """ + mutation setUserAdmin($name: String!, $admin: Boolean!) { + admin { + user { + mutate(name: $name) { + setAdmin(admin: $admin) { + __typename + ...UserMutationSelection + } + } + } + } + } + + fragment InvalidInputSelection on InvalidInput { + errors { + path + message + name + context + } + } + + 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 UserMutationSelection on UserResult { + ...UserSelection + ...InvalidInputSelection + ...OperationErrorSelection + } + + fragment UserSelection on User { + name + email + dateJoined + lastLogin + isActive + isAdmin + isSsoOnly + isService + role { + ...RoleSelection + } + extraRoles { ...RoleSelection } } + """ + ) + variables: Dict[str, object] = {"name": name, "admin": admin} + response = self.execute( + query=query, operation_name="setUserAdmin", variables=variables, **kwargs + ) + data = self.get_data(response) + return SetUserAdmin.model_validate(data).admin.user.mutate + + def set_user_active( + self, active: bool, name: str, **kwargs: Any + ) -> Optional[SetUserActiveAdminUserMutate]: + query = gql( + """ + mutation setUserActive($active: Boolean!, $name: String!) { + admin { + user { + mutate(name: $name) { + setActive(active: $active) { + __typename + ...UserMutationSelection + } + } + } + } + } + + fragment InvalidInputSelection on InvalidInput { + errors { + path + message + name + context + } + } fragment ManagedRoleSelection on ManagedRole { id @@ -275,6 +500,12 @@ def get_roles( arn } + fragment OperationErrorSelection on OperationError { + message + name + context + } + fragment RoleSelection on Role { __typename ...UnmanagedRoleSelection @@ -286,14 +517,82 @@ def get_roles( name arn } + + fragment UserMutationSelection on UserResult { + ...UserSelection + ...InvalidInputSelection + ...OperationErrorSelection + } + + fragment UserSelection on User { + name + email + dateJoined + lastLogin + isActive + isAdmin + isSsoOnly + isService + role { + ...RoleSelection + } + extraRoles { + ...RoleSelection + } + } """ ) - variables: Dict[str, object] = {} + variables: Dict[str, object] = {"active": active, "name": name} response = self.execute( - query=query, operation_name="getRoles", variables=variables, **kwargs + query=query, operation_name="setUserActive", variables=variables, **kwargs ) data = self.get_data(response) - return GetRoles.model_validate(data).roles + return SetUserActive.model_validate(data).admin.user.mutate + + def reset_user_password( + self, name: str, **kwargs: Any + ) -> Optional[ResetUserPasswordAdminUserMutate]: + query = gql( + """ + mutation resetUserPassword($name: String!) { + admin { + user { + mutate(name: $name) { + resetPassword { + __typename + ...InvalidInputSelection + ...OperationErrorSelection + } + } + } + } + } + + fragment InvalidInputSelection on InvalidInput { + errors { + path + message + name + context + } + } + + fragment OperationErrorSelection on OperationError { + message + name + context + } + """ + ) + variables: Dict[str, object] = {"name": name} + response = self.execute( + query=query, + operation_name="resetUserPassword", + variables=variables, + **kwargs + ) + data = self.get_data(response) + return ResetUserPassword.model_validate(data).admin.user.mutate def set_role( self, diff --git a/api/python/quilt3/admin/_graphql_client/reset_user_password.py b/api/python/quilt3/admin/_graphql_client/reset_user_password.py new file mode 100644 index 00000000000..9af8f4c750b --- /dev/null +++ b/api/python/quilt3/admin/_graphql_client/reset_user_password.py @@ -0,0 +1,49 @@ +# Generated by ariadne-codegen +# Source: queries.graphql + +from typing import Literal, Optional, Union + +from pydantic import Field + +from .base_model import BaseModel +from .fragments import InvalidInputSelection, OperationErrorSelection + + +class ResetUserPassword(BaseModel): + admin: "ResetUserPasswordAdmin" + + +class ResetUserPasswordAdmin(BaseModel): + user: "ResetUserPasswordAdminUser" + + +class ResetUserPasswordAdminUser(BaseModel): + mutate: Optional["ResetUserPasswordAdminUserMutate"] + + +class ResetUserPasswordAdminUserMutate(BaseModel): + reset_password: Union[ + "ResetUserPasswordAdminUserMutateResetPasswordOk", + "ResetUserPasswordAdminUserMutateResetPasswordInvalidInput", + "ResetUserPasswordAdminUserMutateResetPasswordOperationError", + ] = Field(alias="resetPassword", discriminator="typename__") + + +class ResetUserPasswordAdminUserMutateResetPasswordOk(BaseModel): + typename__: Literal["Ok"] = Field(alias="__typename") + + +class ResetUserPasswordAdminUserMutateResetPasswordInvalidInput(InvalidInputSelection): + typename__: Literal["InvalidInput"] = Field(alias="__typename") + + +class ResetUserPasswordAdminUserMutateResetPasswordOperationError( + OperationErrorSelection +): + typename__: Literal["OperationError"] = Field(alias="__typename") + + +ResetUserPassword.model_rebuild() +ResetUserPasswordAdmin.model_rebuild() +ResetUserPasswordAdminUser.model_rebuild() +ResetUserPasswordAdminUserMutate.model_rebuild() diff --git a/api/python/quilt3/admin/_graphql_client/set_user_active.py b/api/python/quilt3/admin/_graphql_client/set_user_active.py new file mode 100644 index 00000000000..4837abb921f --- /dev/null +++ b/api/python/quilt3/admin/_graphql_client/set_user_active.py @@ -0,0 +1,47 @@ +# Generated by ariadne-codegen +# Source: queries.graphql + +from typing import Literal, Optional, Union + +from pydantic import Field + +from .base_model import BaseModel +from .fragments import InvalidInputSelection, OperationErrorSelection, UserSelection + + +class SetUserActive(BaseModel): + admin: "SetUserActiveAdmin" + + +class SetUserActiveAdmin(BaseModel): + user: "SetUserActiveAdminUser" + + +class SetUserActiveAdminUser(BaseModel): + mutate: Optional["SetUserActiveAdminUserMutate"] + + +class SetUserActiveAdminUserMutate(BaseModel): + set_active: Union[ + "SetUserActiveAdminUserMutateSetActiveUser", + "SetUserActiveAdminUserMutateSetActiveInvalidInput", + "SetUserActiveAdminUserMutateSetActiveOperationError", + ] = Field(alias="setActive", discriminator="typename__") + + +class SetUserActiveAdminUserMutateSetActiveUser(UserSelection): + typename__: Literal["User"] = Field(alias="__typename") + + +class SetUserActiveAdminUserMutateSetActiveInvalidInput(InvalidInputSelection): + typename__: Literal["InvalidInput"] = Field(alias="__typename") + + +class SetUserActiveAdminUserMutateSetActiveOperationError(OperationErrorSelection): + typename__: Literal["OperationError"] = Field(alias="__typename") + + +SetUserActive.model_rebuild() +SetUserActiveAdmin.model_rebuild() +SetUserActiveAdminUser.model_rebuild() +SetUserActiveAdminUserMutate.model_rebuild() diff --git a/api/python/quilt3/admin/_graphql_client/set_user_admin.py b/api/python/quilt3/admin/_graphql_client/set_user_admin.py new file mode 100644 index 00000000000..ac3ac14ce2c --- /dev/null +++ b/api/python/quilt3/admin/_graphql_client/set_user_admin.py @@ -0,0 +1,47 @@ +# Generated by ariadne-codegen +# Source: queries.graphql + +from typing import Literal, Optional, Union + +from pydantic import Field + +from .base_model import BaseModel +from .fragments import InvalidInputSelection, OperationErrorSelection, UserSelection + + +class SetUserAdmin(BaseModel): + admin: "SetUserAdminAdmin" + + +class SetUserAdminAdmin(BaseModel): + user: "SetUserAdminAdminUser" + + +class SetUserAdminAdminUser(BaseModel): + mutate: Optional["SetUserAdminAdminUserMutate"] + + +class SetUserAdminAdminUserMutate(BaseModel): + set_admin: Union[ + "SetUserAdminAdminUserMutateSetAdminUser", + "SetUserAdminAdminUserMutateSetAdminInvalidInput", + "SetUserAdminAdminUserMutateSetAdminOperationError", + ] = Field(alias="setAdmin", discriminator="typename__") + + +class SetUserAdminAdminUserMutateSetAdminUser(UserSelection): + typename__: Literal["User"] = Field(alias="__typename") + + +class SetUserAdminAdminUserMutateSetAdminInvalidInput(InvalidInputSelection): + typename__: Literal["InvalidInput"] = Field(alias="__typename") + + +class SetUserAdminAdminUserMutateSetAdminOperationError(OperationErrorSelection): + typename__: Literal["OperationError"] = Field(alias="__typename") + + +SetUserAdmin.model_rebuild() +SetUserAdminAdmin.model_rebuild() +SetUserAdminAdminUser.model_rebuild() +SetUserAdminAdminUserMutate.model_rebuild() diff --git a/api/python/quilt3/admin/_graphql_client/set_user_email.py b/api/python/quilt3/admin/_graphql_client/set_user_email.py new file mode 100644 index 00000000000..f6b94005e57 --- /dev/null +++ b/api/python/quilt3/admin/_graphql_client/set_user_email.py @@ -0,0 +1,47 @@ +# Generated by ariadne-codegen +# Source: queries.graphql + +from typing import Literal, Optional, Union + +from pydantic import Field + +from .base_model import BaseModel +from .fragments import InvalidInputSelection, OperationErrorSelection, UserSelection + + +class SetUserEmail(BaseModel): + admin: "SetUserEmailAdmin" + + +class SetUserEmailAdmin(BaseModel): + user: "SetUserEmailAdminUser" + + +class SetUserEmailAdminUser(BaseModel): + mutate: Optional["SetUserEmailAdminUserMutate"] + + +class SetUserEmailAdminUserMutate(BaseModel): + set_email: Union[ + "SetUserEmailAdminUserMutateSetEmailUser", + "SetUserEmailAdminUserMutateSetEmailInvalidInput", + "SetUserEmailAdminUserMutateSetEmailOperationError", + ] = Field(alias="setEmail", discriminator="typename__") + + +class SetUserEmailAdminUserMutateSetEmailUser(UserSelection): + typename__: Literal["User"] = Field(alias="__typename") + + +class SetUserEmailAdminUserMutateSetEmailInvalidInput(InvalidInputSelection): + typename__: Literal["InvalidInput"] = Field(alias="__typename") + + +class SetUserEmailAdminUserMutateSetEmailOperationError(OperationErrorSelection): + typename__: Literal["OperationError"] = Field(alias="__typename") + + +SetUserEmail.model_rebuild() +SetUserEmailAdmin.model_rebuild() +SetUserEmailAdminUser.model_rebuild() +SetUserEmailAdminUserMutate.model_rebuild() diff --git a/docs/api-reference/Admin.md b/docs/api-reference/Admin.md index 15dde225d04..232433d9c0e 100644 --- a/docs/api-reference/Admin.md +++ b/docs/api-reference/Admin.md @@ -13,6 +13,11 @@ APIs for Quilt administrators. 'Registry' refers to Quilt stack backend services ## User(name: str, email: str, date\_joined: datetime.datetime, last\_login: datetime.datetime, is\_active: bool, is\_admin: bool, is\_sso\_only: bool, is\_service: bool, role: Optional[Annotated[Union[quilt3.admin.ManagedRole, quilt3.admin.UnmanagedRole], FieldInfo(annotation=NoneType, required=True, discriminator='typename\_\_')]], extra\_roles: List[Annotated[Union[quilt3.admin.ManagedRole, quilt3.admin.UnmanagedRole], FieldInfo(annotation=NoneType, required=True, discriminator='typename\_\_')]]) -> None {#User} +## get\_roles() -> List[Union[quilt3.admin.ManagedRole, quilt3.admin.UnmanagedRole]] {#get\_roles} + +Get a list of all roles in the registry. + + ## get\_user(name: str) -> Optional[quilt3.admin.User] {#get\_user} Get a specific user from the registry. Return `None` if the user does not exist. @@ -48,9 +53,43 @@ __Arguments__ * __name__: Username of user to delete. -## get\_roles() -> List[Union[quilt3.admin.ManagedRole, quilt3.admin.UnmanagedRole]] {#get\_roles} +## set\_user\_email(name: str, email: str) -> quilt3.admin.User {#set\_user\_email} -Get a list of all roles in the registry. +Set the email for a user. + +__Arguments__ + +* __name__: Username of user to update. +* __email__: Email to set for the user. + + +## set\_user\_admin(name: str, admin: bool) -> quilt3.admin.User {#set\_user\_admin} + +Set the admin status for a user. + +__Arguments__ + +* __name__: Username of user to update. +* __admin__: Admin status to set for the user. + + +## set\_user\_active(name: str, active: bool) -> quilt3.admin.User {#set\_user\_active} + +Set the active status for a user. + +__Arguments__ + +* __name__: Username of user to update. +* __active__: Active status to set for the user. + + +## reset\_user\_password(name: str) -> None {#reset\_user\_password} + +Reset the password for a user. + +__Arguments__ + +* __name__: Username of user to update. ## set\_role(name: str, role: str, extra\_roles: Optional[List[str]] = None, \*, append: bool = False) -> quilt3.admin.User {#set\_role}