mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 06:21:15 +02:00
refactor: ruff autofixes
This commit is contained in:
455 files changed
+12322
-14762
No files matched your search
@@ -29,12 +29,11 @@ privilege_role_map = Table(
|
||||
"privilege_role_map",
|
||||
Base.metadata,
|
||||
Column("privilege_id", GUID, ForeignKey("privileges.privilege_id", ondelete="CASCADE")),
|
||||
Column("role_id", GUID, ForeignKey("roles.role_id", ondelete="CASCADE"))
|
||||
Column("role_id", GUID, ForeignKey("roles.role_id", ondelete="CASCADE")),
|
||||
)
|
||||
|
||||
|
||||
class Privilege(BaseTable):
|
||||
|
||||
__tablename__ = "privileges"
|
||||
|
||||
privilege_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
@@ -43,210 +42,60 @@ class Privilege(BaseTable):
|
||||
roles = relationship("Role", secondary=privilege_role_map, back_populates="privileges")
|
||||
|
||||
|
||||
@event.listens_for(Privilege.__table__, 'after_create')
|
||||
@event.listens_for(Privilege.__table__, "after_create")
|
||||
def create_default_roles(target, connection, **kw):
|
||||
|
||||
default_privileges = [
|
||||
{
|
||||
"description": "Create or delete a user",
|
||||
"name": "User.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a user",
|
||||
"name": "User.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a user",
|
||||
"name": "User.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a group",
|
||||
"name": "Group.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a group",
|
||||
"name": "Group.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a group",
|
||||
"name": "Group.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a role",
|
||||
"name": "Role.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a role",
|
||||
"name": "Role.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a role",
|
||||
"name": "Role.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete an ACE",
|
||||
"name": "ACE.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an ACE",
|
||||
"name": "ACE.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update an ACE",
|
||||
"name": "ACE.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a resource pool",
|
||||
"name": "Pool.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a resource pool",
|
||||
"name": "Pool.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a resource pool",
|
||||
"name": "Pool.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a template",
|
||||
"name": "Template.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a template",
|
||||
"name": "Template.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a template",
|
||||
"name": "Template.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a project",
|
||||
"name": "Project.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a project",
|
||||
"name": "Project.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a project",
|
||||
"name": "Project.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete project snapshots",
|
||||
"name": "Snapshot.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "Restore a snapshot",
|
||||
"name": "Snapshot.Restore"
|
||||
},
|
||||
{
|
||||
"description": "View a snapshot",
|
||||
"name": "Snapshot.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a node",
|
||||
"name": "Node.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a node",
|
||||
"name": "Node.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a node",
|
||||
"name": "Node.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Console access to a node",
|
||||
"name": "Node.Console"
|
||||
},
|
||||
{
|
||||
"description": "Power management for a node",
|
||||
"name": "Node.PowerMgmt"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a link",
|
||||
"name": "Link.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a link",
|
||||
"name": "Link.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a link",
|
||||
"name": "Link.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Capture packets on a link",
|
||||
"name": "Link.Capture"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a drawing",
|
||||
"name": "Drawing.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a drawing",
|
||||
"name": "Drawing.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a drawing",
|
||||
"name": "Drawing.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a symbol",
|
||||
"name": "Symbol.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a symbol",
|
||||
"name": "Symbol.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete an image",
|
||||
"name": "Image.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an image",
|
||||
"name": "Image.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a compute",
|
||||
"name": "Compute.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "Update a compute",
|
||||
"name": "Compute.Modify"
|
||||
},
|
||||
{
|
||||
"description": "View a compute",
|
||||
"name": "Compute.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Install an appliance",
|
||||
"name": "Appliance.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an appliance",
|
||||
"name": "Appliance.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete an LLM model configuration",
|
||||
"name": "LLMConfig.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an LLM model configuration",
|
||||
"name": "LLMConfig.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update an LLM model configuration",
|
||||
"name": "LLMConfig.Modify"
|
||||
},
|
||||
{
|
||||
"description": "View server settings",
|
||||
"name": "Server.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update server settings",
|
||||
"name": "Server.Modify"
|
||||
}
|
||||
{"description": "Create or delete a user", "name": "User.Allocate"},
|
||||
{"description": "View a user", "name": "User.Audit"},
|
||||
{"description": "Update a user", "name": "User.Modify"},
|
||||
{"description": "Create or delete a group", "name": "Group.Allocate"},
|
||||
{"description": "View a group", "name": "Group.Audit"},
|
||||
{"description": "Update a group", "name": "Group.Modify"},
|
||||
{"description": "Create or delete a role", "name": "Role.Allocate"},
|
||||
{"description": "View a role", "name": "Role.Audit"},
|
||||
{"description": "Update a role", "name": "Role.Modify"},
|
||||
{"description": "Create or delete an ACE", "name": "ACE.Allocate"},
|
||||
{"description": "View an ACE", "name": "ACE.Audit"},
|
||||
{"description": "Update an ACE", "name": "ACE.Modify"},
|
||||
{"description": "Create or delete a resource pool", "name": "Pool.Allocate"},
|
||||
{"description": "View a resource pool", "name": "Pool.Audit"},
|
||||
{"description": "Update a resource pool", "name": "Pool.Modify"},
|
||||
{"description": "Create or delete a template", "name": "Template.Allocate"},
|
||||
{"description": "View a template", "name": "Template.Audit"},
|
||||
{"description": "Update a template", "name": "Template.Modify"},
|
||||
{"description": "Create or delete a project", "name": "Project.Allocate"},
|
||||
{"description": "View a project", "name": "Project.Audit"},
|
||||
{"description": "Update a project", "name": "Project.Modify"},
|
||||
{"description": "Create or delete project snapshots", "name": "Snapshot.Allocate"},
|
||||
{"description": "Restore a snapshot", "name": "Snapshot.Restore"},
|
||||
{"description": "View a snapshot", "name": "Snapshot.Audit"},
|
||||
{"description": "Create or delete a node", "name": "Node.Allocate"},
|
||||
{"description": "View a node", "name": "Node.Audit"},
|
||||
{"description": "Update a node", "name": "Node.Modify"},
|
||||
{"description": "Console access to a node", "name": "Node.Console"},
|
||||
{"description": "Power management for a node", "name": "Node.PowerMgmt"},
|
||||
{"description": "Create or delete a link", "name": "Link.Allocate"},
|
||||
{"description": "View a link", "name": "Link.Audit"},
|
||||
{"description": "Update a link", "name": "Link.Modify"},
|
||||
{"description": "Capture packets on a link", "name": "Link.Capture"},
|
||||
{"description": "Create or delete a drawing", "name": "Drawing.Allocate"},
|
||||
{"description": "View a drawing", "name": "Drawing.Audit"},
|
||||
{"description": "Update a drawing", "name": "Drawing.Modify"},
|
||||
{"description": "Create or delete a symbol", "name": "Symbol.Allocate"},
|
||||
{"description": "View a symbol", "name": "Symbol.Audit"},
|
||||
{"description": "Create or delete an image", "name": "Image.Allocate"},
|
||||
{"description": "View an image", "name": "Image.Audit"},
|
||||
{"description": "Create or delete a compute", "name": "Compute.Allocate"},
|
||||
{"description": "Update a compute", "name": "Compute.Modify"},
|
||||
{"description": "View a compute", "name": "Compute.Audit"},
|
||||
{"description": "Install an appliance", "name": "Appliance.Allocate"},
|
||||
{"description": "View an appliance", "name": "Appliance.Audit"},
|
||||
{"description": "Create or delete an LLM model configuration", "name": "LLMConfig.Allocate"},
|
||||
{"description": "View an LLM model configuration", "name": "LLMConfig.Audit"},
|
||||
{"description": "Update an LLM model configuration", "name": "LLMConfig.Modify"},
|
||||
{"description": "View server settings", "name": "Server.Audit"},
|
||||
{"description": "Update server settings", "name": "Server.Modify"},
|
||||
]
|
||||
|
||||
stmt = target.insert().values(default_privileges)
|
||||
@@ -258,6 +107,7 @@ def create_default_roles(target, connection, **kw):
|
||||
def add_privileges_to_role(target, connection, role, privileges):
|
||||
|
||||
from .roles import Role
|
||||
|
||||
roles_table = Role.__table__
|
||||
privileges_table = Privilege.__table__
|
||||
|
||||
@@ -272,10 +122,11 @@ def add_privileges_to_role(target, connection, role, privileges):
|
||||
connection.execute(stmt)
|
||||
|
||||
|
||||
@event.listens_for(privilege_role_map, 'after_create')
|
||||
@event.listens_for(privilege_role_map, "after_create")
|
||||
def add_privileges_to_default_roles(target, connection, **kw):
|
||||
|
||||
from .roles import Role
|
||||
|
||||
roles_table = Role.__table__
|
||||
stmt = roles_table.select().where(roles_table.c.name == "Administrator")
|
||||
result = connection.execute(stmt)
|
||||
@@ -317,7 +168,7 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"Appliance.Allocate",
|
||||
"Appliance.Audit",
|
||||
"LLMConfig.Audit",
|
||||
"LLMConfig.Modify"
|
||||
"LLMConfig.Modify",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "User", user_privileges)
|
||||
@@ -333,7 +184,7 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"Symbol.Audit",
|
||||
"Image.Audit",
|
||||
"Compute.Audit",
|
||||
"Appliance.Audit"
|
||||
"Appliance.Audit",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "Auditor", auditor_privileges)
|
||||
@@ -348,7 +199,7 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"Image.Allocate",
|
||||
"Image.Audit",
|
||||
"Appliance.Allocate",
|
||||
"Appliance.Audit"
|
||||
"Appliance.Audit",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "Template manager", template_manager_privileges)
|
||||
@@ -360,20 +211,13 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"User.Modify",
|
||||
"Group.Allocate",
|
||||
"Group.Audit",
|
||||
"Group.Modify"
|
||||
"Group.Modify",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "User manager", user_manager_privileges)
|
||||
|
||||
# add required privileges to the "ACL manager" role
|
||||
acl_manager_privileges = (
|
||||
"Role.Allocate",
|
||||
"Role.Audit",
|
||||
"Role.Modify",
|
||||
"ACE.Allocate",
|
||||
"ACE.Audit",
|
||||
"ACE.Modify"
|
||||
)
|
||||
acl_manager_privileges = ("Role.Allocate", "Role.Audit", "Role.Modify", "ACE.Allocate", "ACE.Audit", "ACE.Modify")
|
||||
|
||||
add_privileges_to_role(target, connection, "ACL manager", acl_manager_privileges)
|
||||
|
||||
|
||||
Reference in new issue
Block a user