RegisterDefaultRoles 注册默认角色
()
| 38 | |
| 39 | // RegisterDefaultRoles 注册默认角色 |
| 40 | func (r *RBAC) RegisterDefaultRoles() { |
| 41 | // Admin 角色 - 完全权限 |
| 42 | r.AddRole(&Role{ |
| 43 | Name: "admin", |
| 44 | Description: "Administrator with full access", |
| 45 | Permissions: []Permission{ |
| 46 | {Resource: "*", Actions: []string{"*"}}, |
| 47 | }, |
| 48 | }) |
| 49 | |
| 50 | // User 角色 - 基础权限 |
| 51 | r.AddRole(&Role{ |
| 52 | Name: "user", |
| 53 | Description: "Regular user with basic access", |
| 54 | Permissions: []Permission{ |
| 55 | {Resource: "agents", Actions: []string{"create", "read", "update", "delete"}}, |
| 56 | {Resource: "memory", Actions: []string{"create", "read", "update", "delete"}}, |
| 57 | {Resource: "sessions", Actions: []string{"create", "read", "update", "delete"}}, |
| 58 | {Resource: "workflows", Actions: []string{"read", "execute"}}, |
| 59 | {Resource: "tools", Actions: []string{"read", "execute"}}, |
| 60 | }, |
| 61 | }) |
| 62 | |
| 63 | // Viewer 角色 - 只读权限 |
| 64 | r.AddRole(&Role{ |
| 65 | Name: "viewer", |
| 66 | Description: "Read-only access", |
| 67 | Permissions: []Permission{ |
| 68 | {Resource: "*", Actions: []string{"read"}}, |
| 69 | }, |
| 70 | }) |
| 71 | |
| 72 | // Developer 角色 - 开发者权限 |
| 73 | r.AddRole(&Role{ |
| 74 | Name: "developer", |
| 75 | Description: "Developer with extended access", |
| 76 | Permissions: []Permission{ |
| 77 | {Resource: "agents", Actions: []string{"*"}}, |
| 78 | {Resource: "workflows", Actions: []string{"*"}}, |
| 79 | {Resource: "tools", Actions: []string{"*"}}, |
| 80 | {Resource: "eval", Actions: []string{"*"}}, |
| 81 | }, |
| 82 | }) |
| 83 | } |
| 84 | |
| 85 | // AddRole 添加角色 |
| 86 | func (r *RBAC) AddRole(role *Role) { |