- 新增 ldap_ad.go,支持 AD 密码编码、字段映射与目录类型判断 - 重构 ldap/ldap_users/ldap_ou,兼容 OpenLDAP 与 AD 登录、导入、OU 浏览 - 前端系统设置增加目录类型选择与 AD 配置项 - Dockerfile 按 TARGETARCH 单架构编译 Agent,限制 Node 内存防 OOM - run.sh 新增 docker fast/upgrade,README 补充 LDAP/AD 与常见问题
213 lines
8.4 KiB
Go
213 lines
8.4 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
)
|
|
|
|
// User 用户模型
|
|
type User struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Username string `gorm:"size:64;uniqueIndex;not null" json:"username"`
|
|
Password string `gorm:"size:255;not null" json:"-"`
|
|
Email string `gorm:"size:128" json:"email"`
|
|
Phone string `gorm:"size:32" json:"phone"`
|
|
RealName string `gorm:"size:64" json:"real_name"`
|
|
Avatar string `gorm:"size:255" json:"avatar"`
|
|
Status int `gorm:"default:1" json:"status"` // 0:禁用 1:启用
|
|
IsAdmin bool `gorm:"default:false" json:"is_admin"`
|
|
AuthSource string `gorm:"size:20;default:'local'" json:"auth_source"` // local / ldap
|
|
LastLogin *time.Time `json:"last_login"`
|
|
// CI/CD Webhook 长期访问密钥(每用户仅一条,明文仅生成时返回一次)// Logan.Li
|
|
ApiAccessKeyHash string `gorm:"size:255" json:"-"`
|
|
ApiAccessKeyPrefix string `gorm:"size:32;index" json:"api_access_key_prefix,omitempty"`
|
|
ApiAccessKeyID string `gorm:"size:32" json:"api_access_key_id,omitempty"`
|
|
ApiAccessKeyDescription string `gorm:"size:255" json:"api_access_key_description,omitempty"`
|
|
ApiAccessKeyDurationMonths int `gorm:"default:12" json:"api_access_key_duration_months,omitempty"`
|
|
ApiAccessKeyAt *time.Time `json:"api_access_key_at,omitempty"`
|
|
ApiAccessKeyExpiresAt *time.Time `json:"api_access_key_expires_at,omitempty"`
|
|
ApiAccessKeyLastUsedAt *time.Time `json:"api_access_key_last_used_at,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联
|
|
Roles []Role `gorm:"many2many:iam_user_roles;" json:"roles,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (User) TableName() string {
|
|
return "iam_users"
|
|
}
|
|
|
|
// Role 角色模型
|
|
type Role struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
|
|
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
|
Description string `gorm:"size:255" json:"description"`
|
|
Status int `gorm:"default:1" json:"status"`
|
|
IsSystem bool `gorm:"default:false" json:"is_system"` // 系统默认角色,禁止删除
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联
|
|
Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Role) TableName() string {
|
|
return "iam_roles"
|
|
}
|
|
|
|
// Permission 权限模型
|
|
type Permission struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:64;not null" json:"name"`
|
|
Code string `gorm:"size:128;uniqueIndex;not null" json:"code"`
|
|
Type string `gorm:"size:32" json:"type"` // menu, button, api
|
|
Path string `gorm:"size:255" json:"path"`
|
|
Method string `gorm:"size:32" json:"method"`
|
|
ParentID *uint `json:"parent_id"`
|
|
Sort int `gorm:"default:0" json:"sort"`
|
|
Status int `gorm:"default:1" json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Permission) TableName() string {
|
|
return "iam_permissions"
|
|
}
|
|
|
|
// ItemRole Jenkins-style Item Role — regex pipeline code matching
|
|
type ItemRole struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:64;not null" json:"name"`
|
|
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
|
Pattern string `gorm:"size:255;not null;comment:正则表达式匹配流水线code" json:"pattern"`
|
|
Role string `gorm:"size:16;default:'editor';comment:角色owner/editor/viewer" json:"role"`
|
|
Description string `gorm:"size:255" json:"description"`
|
|
Status int `gorm:"default:1;comment:0禁用1启用" json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (ItemRole) TableName() string {
|
|
return "iam_item_roles"
|
|
}
|
|
|
|
// UserItemRole user ↔ item_role association
|
|
type UserItemRole struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
UserID uint `gorm:"uniqueIndex:idx_user_item_role;not null" json:"user_id"`
|
|
ItemRoleID uint `gorm:"uniqueIndex:idx_user_item_role;not null" json:"item_role_id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
User *User `json:"user,omitempty" gorm:"foreignKey:UserID"`
|
|
ItemRole *ItemRole `json:"item_role,omitempty" gorm:"foreignKey:ItemRoleID"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (UserItemRole) TableName() string {
|
|
return "iam_user_item_roles"
|
|
}
|
|
|
|
// LoginRequest 登录请求
|
|
type LoginRequest struct {
|
|
Username string `json:"username" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
}
|
|
|
|
// LoginResponse 登录响应
|
|
type LoginResponse struct {
|
|
Token string `json:"token"`
|
|
ExpiresIn int `json:"expires_in"`
|
|
User *User `json:"user"`
|
|
}
|
|
|
|
// CreateUserRequest 创建用户请求
|
|
type CreateUserRequest struct {
|
|
Username string `json:"username" binding:"required,min=3,max=64"`
|
|
Password string `json:"password" binding:"required,min=6,max=32"`
|
|
Email string `json:"email" binding:"required,email"`
|
|
Phone string `json:"phone"`
|
|
RealName string `json:"real_name"`
|
|
RoleIDs []uint `json:"role_ids"`
|
|
}
|
|
|
|
// UpdateUserRequest 更新用户请求
|
|
type UpdateUserRequest struct {
|
|
Email string `json:"email" binding:"omitempty,email"`
|
|
Phone string `json:"phone"`
|
|
RealName string `json:"real_name"`
|
|
Status *int `json:"status"`
|
|
RoleIDs []uint `json:"role_ids"`
|
|
}
|
|
|
|
// CreateRoleRequest 创建角色请求 // Logan.Li
|
|
type CreateRoleRequest struct {
|
|
Name string `json:"name" binding:"required,min=1,max=64"`
|
|
Code string `json:"code" binding:"required,min=1,max=64"`
|
|
Description string `json:"description"`
|
|
PermissionIDs []uint `json:"permission_ids"`
|
|
}
|
|
|
|
// UpdateRoleRequest 更新角色请求 // Logan.Li
|
|
type UpdateRoleRequest struct {
|
|
Name string `json:"name" binding:"omitempty,min=1,max=64"`
|
|
Code string `json:"code" binding:"omitempty,min=1,max=64"`
|
|
Description *string `json:"description"`
|
|
Status *int `json:"status"`
|
|
PermissionIDs []uint `json:"permission_ids"`
|
|
}
|
|
|
|
// CreateItemRoleRequest 创建Item Role请求
|
|
type CreateItemRoleRequest struct {
|
|
Name string `json:"name" binding:"required,min=1,max=64"`
|
|
Code string `json:"code" binding:"required,min=1,max=64"`
|
|
Pattern string `json:"pattern" binding:"required,max=255"`
|
|
Role string `json:"role" binding:"oneof=owner editor viewer"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
// UpdateItemRoleRequest 更新Item Role请求
|
|
type UpdateItemRoleRequest struct {
|
|
Name string `json:"name" binding:"omitempty,min=1,max=64"`
|
|
Code string `json:"code" binding:"omitempty,min=1,max=64"`
|
|
Pattern string `json:"pattern" binding:"omitempty,max=255"`
|
|
Role string `json:"role" binding:"omitempty,oneof=owner editor viewer"`
|
|
Description string `json:"description"`
|
|
Status *int `json:"status"`
|
|
}
|
|
|
|
// AssignItemRoleRequest 分配Item Role给用户
|
|
type AssignItemRoleRequest struct {
|
|
UserID uint `json:"user_id" binding:"required"`
|
|
ItemRoleID uint `json:"item_role_id" binding:"required"`
|
|
}
|
|
|
|
// ChangePasswordRequest 修改密码请求
|
|
type ChangePasswordRequest struct {
|
|
OldPassword string `json:"old_password" binding:"required"`
|
|
NewPassword string `json:"new_password" binding:"required,min=6,max=32"`
|
|
}
|
|
|
|
// LDAPConfig LDAP配置
|
|
type LDAPConfig struct {
|
|
ID int `gorm:"primarykey" json:"id"`
|
|
ServerType string `gorm:"size:20;default:openldap" json:"server_type"` // openldap | ad // Logan.Li
|
|
LDAPHost string `gorm:"size:200;not null" json:"ldap_host"`
|
|
LDAPPort *int `json:"ldap_port"`
|
|
UseLDAPS *bool `json:"use_ldaps"`
|
|
AdminDN string `gorm:"size:500;not null" json:"admin_dn"`
|
|
AdminPassword string `gorm:"size:500;not null" json:"admin_password"`
|
|
SearchFilter *string `gorm:"size:500" json:"search_filter"`
|
|
BaseDN string `gorm:"size:500;not null" json:"base_dn"`
|
|
UserMapping *string `gorm:"type:text" json:"user_mapping"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (LDAPConfig) TableName() string { return "iam_ldap_configs" }
|