1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-29 03:38:06 +00:00
gns3-server/gns3server/schemas/controller/rbac.py

114 lines
2.3 KiB
Python
Raw Normal View History

2021-05-25 09:04:59 +00:00
#
# Copyright (C) 2020 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from typing import Optional, List
from pydantic import ConfigDict, BaseModel, Field
2021-05-25 09:04:59 +00:00
from uuid import UUID
from enum import Enum
from .base import DateTimeModelMixin
class PrivilegeBase(BaseModel):
2021-05-25 09:04:59 +00:00
"""
Common privilege properties.
2021-05-25 09:04:59 +00:00
"""
name: str
description: Optional[str] = None
2021-05-25 09:04:59 +00:00
class Privilege(DateTimeModelMixin, PrivilegeBase):
privilege_id: UUID
model_config = ConfigDict(from_attributes=True)
2021-05-25 09:04:59 +00:00
class ACEType(str, Enum):
2021-05-25 09:04:59 +00:00
user = "user"
group = "group"
class ACEBase(BaseModel):
2021-05-25 09:04:59 +00:00
"""
Common ACE properties.
2021-05-25 09:04:59 +00:00
"""
path: str
propagate: Optional[bool] = True
allowed: Optional[bool] = True
type: ACEType = Field(..., description="Type of the ACE")
user_id: Optional[UUID] = None
group_id: Optional[UUID] = None
role_id: UUID
2023-08-04 08:20:06 +00:00
model_config = ConfigDict(use_enum_values=True)
2021-05-25 09:04:59 +00:00
class ACECreate(ACEBase):
2021-05-25 09:04:59 +00:00
"""
Properties to create an ACE.
2021-05-25 09:04:59 +00:00
"""
pass
class ACEUpdate(ACEBase):
2021-05-25 09:04:59 +00:00
"""
Properties to update an ACE.
2021-05-25 09:04:59 +00:00
"""
pass
class ACE(DateTimeModelMixin, ACEBase):
2021-05-25 09:04:59 +00:00
ace_id: UUID
2023-08-04 08:20:06 +00:00
model_config = ConfigDict(from_attributes=True)
2021-05-25 09:04:59 +00:00
class RoleBase(BaseModel):
"""
Common role properties.
"""
name: Optional[str] = None
description: Optional[str] = None
class RoleCreate(RoleBase):
"""
Properties to create a role.
"""
name: str
class RoleUpdate(RoleBase):
"""
Properties to update a role.
"""
pass
class Role(DateTimeModelMixin, RoleBase):
role_id: UUID
is_builtin: bool
privileges: List[Privilege]
2023-08-04 08:20:06 +00:00
model_config = ConfigDict(from_attributes=True)