src.models.iam module#

Data models for user management

class src.models.iam.Token(*, access_token: str, refresh_token: str, token_type: Literal['bearer'])[source]#

Bases: BaseModel

Data model for user tokens

_abc_impl = <_abc._abc_data object>#
access_token: str#
refresh_token: str#
token_type: Literal['bearer']#
class src.models.iam.TokenData(*, user_id: Optional[str] = None, name: Optional[str] = None, role: Optional[UserRoles] = None, exp: Optional[datetime] = None)[source]#

Bases: BaseModel

Decoded JWT token data.

_abc_impl = <_abc._abc_data object>#
exp: Optional[datetime]#
name: Optional[str]#
role: Optional[UserRoles]#
user_id: Optional[str]#
class src.models.iam.User(*, userId: str, adminPriv: bool)[source]#

Bases: BaseModel

Data model for user.

_abc_impl = <_abc._abc_data object>#
adminPriv: bool#
userId: str#
class src.models.iam.UserInDB(*, userId: str, adminPriv: bool, hashed_password: SecretStr)[source]#

Bases: User

Data model for user in database.

_abc_impl = <_abc._abc_data object>#
hashed_password: SecretStr#
class src.models.iam.UserInsert(*, name: str, user_id: str, password: SecretStr, password_confirm: SecretStr, admin_priv: bool = False)[source]#

Bases: BaseModel

Request model for creating a user.

_abc_impl = <_abc._abc_data object>#
admin_priv: bool#
classmethod generate_if_empty(v: Optional[str], values: Dict, **kwargs) str[source]#

Generates a user id if one is not provided and sanitize the id for URL safe usage.

Parameters:
  • v (Optional[str]) – The user id.

  • values (Dict) – User data.

Returns:

Generated user id.

Return type:

str

classmethod match_passwords(v: SecretStr, values: Dict, **kwargs) SecretStr[source]#

Checks that password is strong and check confirm password matches.

Parameters:
  • v (SecretStr) – Password

  • values (Dict) – User data.

Raises:
  • ValueError – If confirmation password does not match password.

  • ValueError – If password is not strong.

Returns:

_description_

Return type:

str

name: str#
password: SecretStr#
password_confirm: SecretStr#
user_id: str#
class src.models.iam.UserPage(*, page_num: int = 1, user_num: int = 5, name: str = '', userId: str = '', admin_priv: int = 2, last_modified_range: Optional[Union[str, dict]] = {'from': '', 'to': ''}, date_created_range: Optional[Union[str, dict]] = {'from': '', 'to': ''})[source]#

Bases: BaseModel

Request model for finding users

_abc_impl = <_abc._abc_data object>#
admin_priv: int#
classmethod admin_priv_check(v: int) Optional[bool][source]#

Validate if user is admin

Parameters:

v (int) – Admin priv level

Returns:

True if admin, False if not admin, None if not set

Return type:

Optional[bool]

classmethod date_created_check(v: Dict) Optional[Dict][source]#

Check if date created search range is empty

Parameters:

v (Dict) – Search range

Returns:

Search range if not empty, None if empty

Return type:

Optional[Dict]

date_created_range: Optional[Union[str, dict]]#
classmethod id_is_empty(v: str) Optional[str][source]#

Validate user id search field is not empty

Parameters:

v (str) – User id

Returns:

user id if not empty, None if empty

Return type:

Optional[str]

classmethod last_modified_check(v: Dict) Optional[Dict][source]#

Check if last modified search range is empty

Parameters:

v (Dict) – Last modified search range

Returns:

Search range if not empty, None if empty

Return type:

Optional[Dict]

last_modified_range: Optional[Union[str, dict]]#
name: str#
classmethod name_is_empty(v: str) Optional[str][source]#

Check if search name field is empty

Parameters:

v (str) – Search name field

Returns:

name if not empty, None if empty

Return type:

Optional[str]

classmethod num_of_user_more_than_one(v: int) int[source]#

Validate number of users displayed is one or more

Parameters:

v (int) – Number of users displayed

Raises:

ValueError – If number of users displayed is less than 1

Returns:

Number of users displayed

Return type:

int

page_num: int#
classmethod page_number_check(v: int) int[source]#

Validate pagination page number is valid

Parameters:

v (int) – Page number

Raises:

ValueError – If page number is less than 1

Returns:

Page number

Return type:

int

userId: str#
user_num: int#
class src.models.iam.UserRemoval(*, users: List[str])[source]#

Bases: BaseModel

Request model for removing many users.

_abc_impl = <_abc._abc_data object>#
users: List[str]#
class src.models.iam.UserRoles(value)[source]#

Bases: str, Enum

Possible user roles.

_generate_next_value_(start, count, last_values)#

Generate the next value when not given.

name: the name of the member start: the initial start value or None count: the number of existing members last_value: the last value assigned or None

_member_map_ = {'admin': UserRoles.admin, 'user': UserRoles.user}#
_member_names_ = ['user', 'admin']#
_member_type_#

alias of str

_value2member_map_ = {'admin': UserRoles.admin, 'user': UserRoles.user}#
admin = 'admin'#
user = 'user'#
class src.models.iam.UsersEdit(*, users: List[str] = [], priv: bool = False)[source]#

Bases: BaseModel

Request model for editing many users.

_abc_impl = <_abc._abc_data object>#
priv: bool#
users: List[str]#