fix
This commit is contained in:
@@ -2,14 +2,34 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/conf"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AccessService struct{ uc *biz.AccessUsecase }
|
||||
type AccessService struct {
|
||||
uc *biz.AccessUsecase
|
||||
runtime *conf.Runtime
|
||||
}
|
||||
|
||||
func NewAccessService(uc *biz.AccessUsecase) *AccessService { return &AccessService{uc: uc} }
|
||||
func NewAccessService(uc *biz.AccessUsecase, runtime *conf.Runtime) *AccessService {
|
||||
return &AccessService{uc: uc, runtime: runtime}
|
||||
}
|
||||
|
||||
func (s *AccessService) NormalizeRoutePath(path string) string {
|
||||
config := s.runtime.Admin()
|
||||
if config == nil || config.RouterPrefix == "" {
|
||||
return path
|
||||
}
|
||||
prefix := strings.TrimSuffix(config.RouterPrefix, "/")
|
||||
normalized := strings.TrimPrefix(path, prefix)
|
||||
if normalized == "" {
|
||||
return "/"
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
func (s *AccessService) Authorize(ctx context.Context, aid uint, path, method string) (bool, error) {
|
||||
return s.uc.Authorize(ctx, aid, path, method)
|
||||
}
|
||||
|
||||
@@ -88,6 +88,16 @@ func (s *AccessService) PolicyPathResponses(ctx context.Context, authorityID uin
|
||||
func (s *AccessService) SyncAPIResponses(ctx context.Context, routes []dto.APIRequest) (*dto.APISyncResponse, error) {
|
||||
items := make([]*biz.API, 0, len(routes))
|
||||
for i := range routes {
|
||||
routes[i].Path = s.NormalizeRoutePath(routes[i].Path)
|
||||
if routes[i].APIGroup == "" || routes[i].Description == "" {
|
||||
group, description := routeMetadata(routes[i].Method, routes[i].Path)
|
||||
if routes[i].APIGroup == "" {
|
||||
routes[i].APIGroup = group
|
||||
}
|
||||
if routes[i].Description == "" {
|
||||
routes[i].Description = description
|
||||
}
|
||||
}
|
||||
items = append(items, apiDomain(&routes[i]))
|
||||
}
|
||||
return s.SyncAPIs(ctx, items)
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
package service
|
||||
|
||||
import "strings"
|
||||
|
||||
type apiMetadataValue struct{ group, description string }
|
||||
|
||||
var apiMetadata = map[string]apiMetadataValue{
|
||||
"DELETE /api/deleteApisByIds": {group: "api", description: "批量删除api"},
|
||||
"DELETE /customer/customer": {group: "客户", description: "删除客户"},
|
||||
"DELETE /dataAccessLog/deleteDataAccessLogByIds": {group: "数据权限审计", description: "批量删除数据权限审计日志"},
|
||||
"DELETE /department/deleteDepartment": {group: "部门", description: "删除部门"},
|
||||
"DELETE /info/deleteInfo": {group: "公告", description: "删除公告"},
|
||||
"DELETE /info/deleteInfoByIds": {group: "公告", description: "批量删除公告"},
|
||||
"DELETE /mediaUpload/:uploadId": {group: "媒体上传", description: "取消大文件上传"},
|
||||
"DELETE /position/deletePosition": {group: "岗位", description: "删除岗位"},
|
||||
"DELETE /sysDictionary/deleteSysDictionary": {group: "系统字典", description: "删除字典"},
|
||||
"DELETE /sysDictionaryDetail/deleteSysDictionaryDetail": {group: "系统字典详情", description: "删除字典内容"},
|
||||
"DELETE /sysError/deleteSysError": {group: "错误日志", description: "删除错误日志"},
|
||||
"DELETE /sysError/deleteSysErrorByIds": {group: "错误日志", description: "批量删除错误日志"},
|
||||
"DELETE /sysExportTemplate/deleteSysExportTemplate": {group: "导出模板", description: "删除导出模板"},
|
||||
"DELETE /sysExportTemplate/deleteSysExportTemplateByIds": {group: "导出模板", description: "批量删除导出模板"},
|
||||
"DELETE /sysLoginLog/deleteLoginLog": {group: "登录日志", description: "删除登录日志"},
|
||||
"DELETE /sysLoginLog/deleteLoginLogByIds": {group: "登录日志", description: "批量删除登录日志"},
|
||||
"DELETE /sysOperationRecord/deleteSysOperationRecord": {group: "操作记录", description: "删除操作记录"},
|
||||
"DELETE /sysOperationRecord/deleteSysOperationRecordByIds": {group: "操作记录", description: "批量删除操作历史"},
|
||||
"DELETE /sysParams/deleteSysParams": {group: "参数管理", description: "删除参数"},
|
||||
"DELETE /sysParams/deleteSysParamsByIds": {group: "参数管理", description: "批量删除参数"},
|
||||
"DELETE /sysVersion/deleteSysVersion": {group: "版本控制", description: "删除版本"},
|
||||
"DELETE /sysVersion/deleteSysVersionByIds": {group: "版本控制", description: "批量删除版本"},
|
||||
"DELETE /timedTask/deleteTimedTask": {group: "定时任务", description: "删除定时任务"},
|
||||
"DELETE /user/deleteUser": {group: "系统用户", description: "删除用户"},
|
||||
"GET /api/getApiGroups": {group: "api", description: "获取路由组"},
|
||||
"GET /api/getApiRoles": {group: "api", description: "获取指定API关联角色列表"},
|
||||
"GET /api/syncApi": {group: "api", description: "获取待同步API"},
|
||||
"GET /attachmentCategory/getCategoryList": {group: "媒体库分类", description: "分类列表"},
|
||||
"GET /authority/getDataScopeDepts": {group: "角色", description: "获取角色自定义部门集"},
|
||||
"GET /authority/getUsersByAuthority": {group: "角色", description: "获取角色关联用户ID列表"},
|
||||
"GET /customer/customer": {group: "客户", description: "获取单一客户"},
|
||||
"GET /customer/customerList": {group: "客户", description: "获取客户列表"},
|
||||
"GET /department/findDepartment": {group: "部门", description: "根据ID获取部门"},
|
||||
"GET /department/getDepartmentUsers": {group: "部门", description: "获取部门成员ID列表"},
|
||||
"GET /info/findInfo": {group: "公告", description: "根据ID获取公告"},
|
||||
"GET /info/getInfoList": {group: "公告", description: "获取公告列表"},
|
||||
"GET /logViewer/content": {group: "文件日志", description: "分块读取日志文件内容"},
|
||||
"GET /logViewer/dates": {group: "文件日志", description: "获取存在日志的日期"},
|
||||
"GET /logViewer/files": {group: "文件日志", description: "获取日期下的日志文件"},
|
||||
"GET /menu/getMenuRoles": {group: "菜单", description: "获取菜单关联角色列表"},
|
||||
"GET /position/findPosition": {group: "岗位", description: "根据ID获取岗位"},
|
||||
"GET /position/getPositionUsers": {group: "岗位", description: "获取岗位成员ID列表"},
|
||||
"GET /securityConfig/getSecurityConfig": {group: "安全配置", description: "获取安全配置"},
|
||||
"GET /simpleUploader/checkFileMd5": {group: "断点续传(插件版)", description: "文件完整度验证"},
|
||||
"GET /simpleUploader/mergeFileMd5": {group: "断点续传(插件版)", description: "上传完成合并文件"},
|
||||
"GET /sysDictionary/exportSysDictionary": {group: "系统字典", description: "导出字典JSON"},
|
||||
"GET /sysDictionary/findSysDictionary": {group: "系统字典", description: "根据ID获取字典(建议选择)"},
|
||||
"GET /sysDictionary/getSysDictionaryList": {group: "系统字典", description: "获取字典列表"},
|
||||
"GET /sysDictionary/getSysDictionaryListWithDetails": {group: "系统字典", description: "获取字典列表(含明细)"},
|
||||
"GET /sysDictionaryDetail/findSysDictionaryDetail": {group: "系统字典详情", description: "根据ID获取字典内容"},
|
||||
"GET /sysDictionaryDetail/getDictionaryDetailsByParent": {group: "系统字典详情", description: "根据父级ID获取字典详情"},
|
||||
"GET /sysDictionaryDetail/getDictionaryPath": {group: "系统字典详情", description: "获取字典详情的完整路径"},
|
||||
"GET /sysDictionaryDetail/getDictionaryTreeList": {group: "系统字典详情", description: "获取字典数列表"},
|
||||
"GET /sysDictionaryDetail/getDictionaryTreeListByType": {group: "系统字典详情", description: "根据分类获取字典数列表"},
|
||||
"GET /sysDictionaryDetail/getSysDictionaryDetailList": {group: "系统字典详情", description: "获取字典内容列表"},
|
||||
"GET /sysError/findSysError": {group: "错误日志", description: "根据ID获取错误日志"},
|
||||
"GET /sysError/getSysErrorList": {group: "错误日志", description: "获取错误日志列表"},
|
||||
"GET /sysError/getSysErrorSolution": {group: "错误日志", description: "触发错误处理(异步)"},
|
||||
"GET /sysExportTemplate/exportExcel": {group: "导出模板", description: "导出Excel"},
|
||||
"GET /sysExportTemplate/exportTemplate": {group: "导出模板", description: "下载模板"},
|
||||
"GET /sysExportTemplate/findSysExportTemplate": {group: "导出模板", description: "根据ID获取导出模板"},
|
||||
"GET /sysExportTemplate/getSysExportTemplateList": {group: "导出模板", description: "获取导出模板列表"},
|
||||
"GET /sysExportTemplate/previewSQL": {group: "导出模板", description: "预览SQL"},
|
||||
"GET /sysLoginLog/findLoginLog": {group: "登录日志", description: "根据ID获取登录日志"},
|
||||
"GET /sysLoginLog/getLoginLogList": {group: "登录日志", description: "获取登录日志列表"},
|
||||
"GET /sysOperationRecord/findSysOperationRecord": {group: "操作记录", description: "根据ID获取操作记录"},
|
||||
"GET /sysOperationRecord/getSysOperationRecordList": {group: "操作记录", description: "获取操作记录列表"},
|
||||
"GET /sysParams/findSysParams": {group: "参数管理", description: "根据ID获取参数"},
|
||||
"GET /sysParams/getSysParam": {group: "参数管理", description: "获取参数列表"},
|
||||
"GET /sysParams/getSysParamsList": {group: "参数管理", description: "获取参数列表"},
|
||||
"GET /sysVersion/downloadVersionJson": {group: "版本控制", description: "下载版本json"},
|
||||
"GET /sysVersion/findSysVersion": {group: "版本控制", description: "获取单一版本"},
|
||||
"GET /sysVersion/getSysVersionList": {group: "版本控制", description: "获取版本列表"},
|
||||
"GET /timedTask/alertStream": {group: "定时任务", description: "订阅定时任务失败告警(SSE)"},
|
||||
"GET /timedTask/getRegisteredMethods": {group: "定时任务", description: "获取已注册方法列表"},
|
||||
"GET /timedTask/getTimedTaskList": {group: "定时任务", description: "获取定时任务列表"},
|
||||
"GET /timedTask/getTimedTaskLogList": {group: "定时任务", description: "获取定时任务执行日志"},
|
||||
"GET /user/getUserInfo": {group: "系统用户", description: "获取自身信息(必选)"},
|
||||
"POST /api/createApi": {group: "api", description: "创建api"},
|
||||
"POST /api/deleteApi": {group: "api", description: "删除Api"},
|
||||
"POST /api/enterSyncApi": {group: "api", description: "确认同步API"},
|
||||
"POST /api/getAllApis": {group: "api", description: "获取所有api"},
|
||||
"POST /api/getApiById": {group: "api", description: "获取api详细信息"},
|
||||
"POST /api/getApiList": {group: "api", description: "获取api列表"},
|
||||
"POST /api/ignoreApi": {group: "api", description: "忽略API"},
|
||||
"POST /api/setApiRoles": {group: "api", description: "全量覆盖API关联角色列表"},
|
||||
"POST /api/updateApi": {group: "api", description: "更新Api"},
|
||||
"POST /attachmentCategory/addCategory": {group: "媒体库分类", description: "添加/编辑分类"},
|
||||
"POST /attachmentCategory/deleteCategory": {group: "媒体库分类", description: "删除分类"},
|
||||
"POST /authority/copyAuthority": {group: "角色", description: "拷贝角色"},
|
||||
"POST /authority/createAuthority": {group: "角色", description: "创建角色"},
|
||||
"POST /authority/deleteAuthority": {group: "角色", description: "删除角色"},
|
||||
"POST /authority/getAuthorityList": {group: "角色", description: "获取角色列表"},
|
||||
"POST /authority/setDataScope": {group: "角色", description: "设置角色数据权限"},
|
||||
"POST /authority/setRoleUsers": {group: "角色", description: "全量覆盖角色关联用户"},
|
||||
"POST /authorityBtn/canRemoveAuthorityBtn": {group: "按钮权限", description: "删除按钮"},
|
||||
"POST /authorityBtn/getAuthorityBtn": {group: "按钮权限", description: "获取已有按钮权限"},
|
||||
"POST /authorityBtn/setAuthorityBtn": {group: "按钮权限", description: "设置按钮权限"},
|
||||
"POST /autoCode/initAPI": {group: "代码生成器", description: "生成插件 API 初始化文件"},
|
||||
"POST /autoCode/initDictionary": {group: "代码生成器", description: "生成插件字典初始化文件"},
|
||||
"POST /autoCode/initMenu": {group: "代码生成器", description: "生成插件菜单初始化文件"},
|
||||
"POST /casbin/getPolicyPathByAuthorityId": {group: "casbin", description: "获取权限列表"},
|
||||
"POST /casbin/updateCasbin": {group: "casbin", description: "更改角色api权限"},
|
||||
"POST /customer/customer": {group: "客户", description: "创建客户"},
|
||||
"POST /dataAccessLog/getDataAccessLogList": {group: "数据权限审计", description: "获取数据权限审计日志"},
|
||||
"POST /department/createDepartment": {group: "部门", description: "创建部门"},
|
||||
"POST /department/getDepartmentList": {group: "部门", description: "获取部门树"},
|
||||
"POST /department/setDepartmentUsers": {group: "部门", description: "设置部门成员(反向分配)"},
|
||||
"POST /email/emailTest": {group: "email", description: "发送测试邮件"},
|
||||
"POST /email/sendEmail": {group: "email", description: "发送邮件"},
|
||||
"POST /fileUploadAndDownload/deleteFile": {group: "文件上传与下载", description: "删除文件"},
|
||||
"POST /fileUploadAndDownload/editFileName": {group: "文件上传与下载", description: "文件名或者备注编辑"},
|
||||
"POST /fileUploadAndDownload/getFileList": {group: "文件上传与下载", description: "获取上传文件列表"},
|
||||
"POST /fileUploadAndDownload/importURL": {group: "文件上传与下载", description: "导入URL"},
|
||||
"POST /fileUploadAndDownload/upload": {group: "文件上传与下载", description: "文件上传(建议选择)"},
|
||||
"POST /info/createInfo": {group: "公告", description: "新建公告"},
|
||||
"POST /jwt/jsonInBlacklist": {group: "jwt", description: "jwt加入黑名单(退出,必选)"},
|
||||
"POST /mediaUpload/chunk": {group: "媒体上传", description: "上传分片"},
|
||||
"POST /mediaUpload/complete": {group: "媒体上传", description: "完成大文件上传"},
|
||||
"POST /mediaUpload/init": {group: "媒体上传", description: "初始化大文件上传"},
|
||||
"POST /menu/addBaseMenu": {group: "菜单", description: "新增菜单"},
|
||||
"POST /menu/addMenuAuthority": {group: "菜单", description: "增加menu和角色关联关系"},
|
||||
"POST /menu/deleteBaseMenu": {group: "菜单", description: "删除菜单"},
|
||||
"POST /menu/getBaseMenuById": {group: "菜单", description: "根据id获取菜单"},
|
||||
"POST /menu/getBaseMenuTree": {group: "菜单", description: "获取用户动态路由"},
|
||||
"POST /menu/getMenu": {group: "菜单", description: "获取菜单树(必选)"},
|
||||
"POST /menu/getMenuAuthority": {group: "菜单", description: "获取指定角色menu"},
|
||||
"POST /menu/getMenuList": {group: "菜单", description: "分页获取基础menu列表"},
|
||||
"POST /menu/setMenuRoles": {group: "菜单", description: "全量覆盖菜单关联角色列表"},
|
||||
"POST /menu/updateBaseMenu": {group: "菜单", description: "更新菜单"},
|
||||
"POST /position/createPosition": {group: "岗位", description: "创建岗位"},
|
||||
"POST /position/getPositionList": {group: "岗位", description: "获取岗位列表"},
|
||||
"POST /position/setPositionUsers": {group: "岗位", description: "设置岗位成员(反向分配)"},
|
||||
"POST /securityConfig/setSecurityConfig": {group: "安全配置", description: "设置安全配置"},
|
||||
"POST /simpleUploader/upload": {group: "断点续传(插件版)", description: "插件版分片上传"},
|
||||
"POST /sysApiToken/createApiToken": {group: "API Token", description: "签发API Token"},
|
||||
"POST /sysApiToken/deleteApiToken": {group: "API Token", description: "作废API Token"},
|
||||
"POST /sysApiToken/getApiTokenList": {group: "API Token", description: "获取API Token列表"},
|
||||
"POST /sysDictionary/createSysDictionary": {group: "系统字典", description: "新增字典"},
|
||||
"POST /sysDictionary/importSysDictionary": {group: "系统字典", description: "导入字典JSON"},
|
||||
"POST /sysDictionaryDetail/createSysDictionaryDetail": {group: "系统字典详情", description: "新增字典内容"},
|
||||
"POST /sysError/createSysError": {group: "错误日志", description: "新建错误日志"},
|
||||
"POST /sysExportTemplate/createSysExportTemplate": {group: "导出模板", description: "新增导出模板"},
|
||||
"POST /sysExportTemplate/importExcel": {group: "导出模板", description: "导入Excel"},
|
||||
"POST /sysOperationRecord/createSysOperationRecord": {group: "操作记录", description: "新增操作记录"},
|
||||
"POST /sysParams/createSysParams": {group: "参数管理", description: "新建参数"},
|
||||
"POST /system/getServerInfo": {group: "系统服务", description: "获取服务器信息"},
|
||||
"POST /system/getSystemConfig": {group: "系统服务", description: "获取配置文件内容"},
|
||||
"POST /system/setSystemConfig": {group: "系统服务", description: "设置配置文件内容"},
|
||||
"POST /sysVersion/exportVersion": {group: "版本控制", description: "创建版本"},
|
||||
"POST /sysVersion/importVersion": {group: "版本控制", description: "同步版本"},
|
||||
"POST /timedTask/createTimedTask": {group: "定时任务", description: "创建定时任务"},
|
||||
"POST /timedTask/toggleTimedTask": {group: "定时任务", description: "启用/停用定时任务"},
|
||||
"POST /timedTask/triggerTimedTask": {group: "定时任务", description: "手动触发定时任务"},
|
||||
"POST /user/admin_register": {group: "系统用户", description: "用户注册"},
|
||||
"POST /user/changePassword": {group: "系统用户", description: "修改密码(建议选择)"},
|
||||
"POST /user/getUserList": {group: "系统用户", description: "获取用户列表"},
|
||||
"POST /user/resetPassword": {group: "系统用户", description: "重置用户密码"},
|
||||
"POST /user/setUserAuthorities": {group: "系统用户", description: "设置权限组"},
|
||||
"POST /user/setUserAuthority": {group: "系统用户", description: "修改用户角色(必选)"},
|
||||
"POST /user/setUserDepartments": {group: "系统用户", description: "设置用户归属部门"},
|
||||
"POST /user/setUserPositions": {group: "系统用户", description: "设置用户岗位"},
|
||||
"PUT /authority/updateAuthority": {group: "角色", description: "更新角色信息"},
|
||||
"PUT /customer/customer": {group: "客户", description: "更新客户"},
|
||||
"PUT /department/updateDepartment": {group: "部门", description: "更新部门"},
|
||||
"PUT /info/updateInfo": {group: "公告", description: "更新公告"},
|
||||
"PUT /position/updatePosition": {group: "岗位", description: "更新岗位"},
|
||||
"PUT /sysDictionary/updateSysDictionary": {group: "系统字典", description: "更新字典"},
|
||||
"PUT /sysDictionaryDetail/updateSysDictionaryDetail": {group: "系统字典详情", description: "更新字典内容"},
|
||||
"PUT /sysError/updateSysError": {group: "错误日志", description: "更新错误日志"},
|
||||
"PUT /sysExportTemplate/updateSysExportTemplate": {group: "导出模板", description: "更新导出模板"},
|
||||
"PUT /sysParams/updateSysParams": {group: "参数管理", description: "更新参数"},
|
||||
"PUT /timedTask/updateTimedTask": {group: "定时任务", description: "更新定时任务"},
|
||||
"PUT /user/setSelfInfo": {group: "系统用户", description: "设置自身信息(必选)"},
|
||||
"PUT /user/setSelfSetting": {group: "系统用户", description: "用户界面配置"},
|
||||
"PUT /user/setUserInfo": {group: "系统用户", description: "设置用户信息"},
|
||||
}
|
||||
|
||||
func routeMetadata(method, path string) (string, string) {
|
||||
if value, ok := apiMetadata[strings.ToUpper(method)+" "+path]; ok {
|
||||
return value.group, value.description
|
||||
}
|
||||
return routeGroup(path), ""
|
||||
}
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"kra/pkg/adminauth"
|
||||
)
|
||||
|
||||
type UserDisabledError struct{ UserID uint }
|
||||
|
||||
func (e *UserDisabledError) Error() string { return biz.ErrUserDisabled.Error() }
|
||||
func (e *UserDisabledError) Unwrap() error { return biz.ErrUserDisabled }
|
||||
|
||||
type LoginResult struct {
|
||||
User map[string]any `json:"user"`
|
||||
Token string `json:"token"`
|
||||
@@ -34,7 +39,7 @@ func (s *SystemService) Login(ctx context.Context, username, password string) (*
|
||||
return nil, err
|
||||
}
|
||||
if u.Enable != 1 {
|
||||
return nil, biz.ErrUserDisabled
|
||||
return nil, &UserDisabledError{UserID: u.ID}
|
||||
}
|
||||
if security, securityErr := s.settings.CurrentSecurity(ctx); securityErr == nil && security.PwdExpireEnable && u.PasswordUpdatedAt != nil && time.Since(*u.PasswordUpdatedAt) > time.Duration(security.PwdExpireDays)*24*time.Hour {
|
||||
u.MustChangePassword = true
|
||||
|
||||
@@ -29,22 +29,37 @@ type SetSystemConfigRequest struct {
|
||||
Config struct {
|
||||
Data *struct {
|
||||
Database *struct {
|
||||
Driver string `json:"driver"`
|
||||
Source string `json:"source"`
|
||||
Host string `json:"host"`
|
||||
Port string `json:"port"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Name string `json:"name"`
|
||||
Config string `json:"config"`
|
||||
Path string `json:"path"`
|
||||
Driver string `json:"driver"`
|
||||
Source string `json:"source"`
|
||||
Host string `json:"host"`
|
||||
Port string `json:"port"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Name string `json:"name"`
|
||||
Config string `json:"config"`
|
||||
Path string `json:"path"`
|
||||
Prefix string `json:"prefix"`
|
||||
Engine string `json:"engine"`
|
||||
LogMode string `json:"log_mode"`
|
||||
MaxIdleConns int32 `json:"max_idle_conns"`
|
||||
MaxOpenConns int32 `json:"max_open_conns"`
|
||||
ConnMaxLifetime int32 `json:"conn_max_lifetime"`
|
||||
Singular bool `json:"singular"`
|
||||
} `json:"database"`
|
||||
Redis *struct {
|
||||
Network string `json:"network"`
|
||||
Addr string `json:"addr"`
|
||||
ReadTimeout string `json:"read_timeout"`
|
||||
WriteTimeout string `json:"write_timeout"`
|
||||
Network string `json:"network"`
|
||||
Addr string `json:"addr"`
|
||||
ReadTimeout string `json:"read_timeout"`
|
||||
WriteTimeout string `json:"write_timeout"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"password"`
|
||||
DB int32 `json:"db"`
|
||||
UseCluster bool `json:"use_cluster"`
|
||||
ClusterAddrs []string `json:"cluster_addrs"`
|
||||
} `json:"redis"`
|
||||
DatabaseList []*conf.Data_Database `json:"database_list"`
|
||||
RedisList []*conf.Data_Redis `json:"redis_list"`
|
||||
Mongo *conf.Data_Mongo `json:"mongo"`
|
||||
} `json:"data"`
|
||||
Admin struct {
|
||||
RouterPrefix string `json:"routerPrefix"`
|
||||
@@ -53,6 +68,7 @@ type SetSystemConfigRequest struct {
|
||||
UseMultipoint bool `json:"useMultipoint"`
|
||||
UseStrictAuth bool `json:"useStrictAuth"`
|
||||
DisableAutoMigrate bool `json:"disableAutoMigrate"`
|
||||
UseMongo bool `json:"useMongo"`
|
||||
} `json:"system"`
|
||||
JWT struct {
|
||||
SigningKey string `json:"signingKey"`
|
||||
@@ -74,6 +90,9 @@ type SetSystemConfigRequest struct {
|
||||
SessionTTL int32 `json:"sessionTtl"`
|
||||
} `json:"media"`
|
||||
Storage *conf.AdminBackend_Storage `json:"storage"`
|
||||
Zap *conf.AdminBackend_Zap `json:"zap"`
|
||||
Cors *conf.AdminBackend_CORS `json:"cors"`
|
||||
App *conf.AdminBackend_App `json:"app"`
|
||||
} `json:"admin"`
|
||||
Email *struct {
|
||||
To string `json:"to"`
|
||||
|
||||
@@ -48,7 +48,7 @@ func (s *SystemService) SystemConfig() map[string]any {
|
||||
}
|
||||
admin["routerPrefix"] = config.RouterPrefix
|
||||
if config.System != nil {
|
||||
admin["system"] = map[string]any{"useRedis": config.System.UseRedis, "useMultipoint": config.System.UseMultipoint, "useStrictAuth": config.System.UseStrictAuth, "disableAutoMigrate": config.System.DisableAutoMigrate}
|
||||
admin["system"] = map[string]any{"useRedis": config.System.UseRedis, "useMultipoint": config.System.UseMultipoint, "useStrictAuth": config.System.UseStrictAuth, "disableAutoMigrate": config.System.DisableAutoMigrate, "useMongo": config.System.UseMongo}
|
||||
}
|
||||
if config.Jwt != nil {
|
||||
admin["jwt"] = map[string]any{"signingKey": "******", "expiresTime": config.Jwt.ExpiresTime.AsDuration().String(), "bufferTime": config.Jwt.BufferTime.AsDuration().String(), "issuer": config.Jwt.Issuer}
|
||||
@@ -70,16 +70,36 @@ func (s *SystemService) SystemConfig() map[string]any {
|
||||
maskStorageSecrets(storage)
|
||||
admin["storage"] = storage
|
||||
}
|
||||
if config.Zap != nil {
|
||||
admin["zap"] = config.Zap
|
||||
}
|
||||
if config.Cors != nil {
|
||||
admin["cors"] = config.Cors
|
||||
}
|
||||
if config.App != nil {
|
||||
admin["app"] = config.App
|
||||
}
|
||||
data := s.runtime.Data()
|
||||
if data != nil {
|
||||
if data.Database != nil {
|
||||
data.Database.Password = "******"
|
||||
}
|
||||
if data.Redis != nil {
|
||||
data.Redis.Password = "******"
|
||||
}
|
||||
if data.Mongo != nil {
|
||||
data.Mongo.Password = "******"
|
||||
}
|
||||
for _, database := range data.DatabaseList {
|
||||
if database != nil {
|
||||
database.Password = "******"
|
||||
}
|
||||
}
|
||||
for _, redis := range data.RedisList {
|
||||
if redis != nil {
|
||||
redis.Password = "******"
|
||||
}
|
||||
}
|
||||
}
|
||||
dataMap := map[string]any{}
|
||||
if raw, err := (protojson.MarshalOptions{UseProtoNames: true}).Marshal(data); err == nil {
|
||||
@@ -103,6 +123,16 @@ func (s *SystemService) SaveSystemConfig(ctx context.Context, req *dto.SetSystem
|
||||
next.System.UseMultipoint = req.Config.Admin.System.UseMultipoint
|
||||
next.System.UseStrictAuth = req.Config.Admin.System.UseStrictAuth
|
||||
next.System.DisableAutoMigrate = req.Config.Admin.System.DisableAutoMigrate
|
||||
next.System.UseMongo = req.Config.Admin.System.UseMongo
|
||||
if req.Config.Admin.Zap != nil {
|
||||
next.Zap = req.Config.Admin.Zap
|
||||
}
|
||||
if req.Config.Admin.Cors != nil {
|
||||
next.Cors = req.Config.Admin.Cors
|
||||
}
|
||||
if req.Config.Admin.App != nil {
|
||||
next.App = req.Config.Admin.App
|
||||
}
|
||||
if next.Jwt != nil {
|
||||
if req.Config.Admin.JWT.SigningKey != "" && req.Config.Admin.JWT.SigningKey != "******" {
|
||||
next.Jwt.SigningKey = req.Config.Admin.JWT.SigningKey
|
||||
@@ -163,10 +193,14 @@ func (s *SystemService) SaveSystemConfig(ctx context.Context, req *dto.SetSystem
|
||||
if data.Database != nil && (password == "" || password == "******") {
|
||||
password = data.Database.Password
|
||||
}
|
||||
data.Database = &conf.Data_Database{Driver: value.Driver, Source: value.Source, Host: value.Host, Port: value.Port, User: value.User, Password: password, Name: value.Name, Config: value.Config, Path: value.Path}
|
||||
data.Database = &conf.Data_Database{Driver: value.Driver, Source: value.Source, Host: value.Host, Port: value.Port, User: value.User, Password: password, Name: value.Name, Config: value.Config, Path: value.Path, Prefix: value.Prefix, Engine: value.Engine, LogMode: value.LogMode, MaxIdleConns: value.MaxIdleConns, MaxOpenConns: value.MaxOpenConns, ConnMaxLifetime: value.ConnMaxLifetime, Singular: value.Singular}
|
||||
}
|
||||
if value := req.Config.Data.Redis; value != nil {
|
||||
redis := &conf.Data_Redis{Network: value.Network, Addr: value.Addr}
|
||||
password := value.Password
|
||||
if data.Redis != nil && (password == "" || password == "******") {
|
||||
password = data.Redis.Password
|
||||
}
|
||||
redis := &conf.Data_Redis{Network: value.Network, Addr: value.Addr, Name: value.Name, Password: password, Db: value.DB, UseCluster: value.UseCluster, ClusterAddrs: value.ClusterAddrs}
|
||||
if duration, parseErr := time.ParseDuration(value.ReadTimeout); parseErr == nil && duration >= 0 {
|
||||
redis.ReadTimeout = durationpb.New(duration)
|
||||
}
|
||||
@@ -175,6 +209,28 @@ func (s *SystemService) SaveSystemConfig(ctx context.Context, req *dto.SetSystem
|
||||
}
|
||||
data.Redis = redis
|
||||
}
|
||||
if req.Config.Data.DatabaseList != nil {
|
||||
for i, item := range req.Config.Data.DatabaseList {
|
||||
if item != nil && (item.Password == "" || item.Password == "******") && i < len(data.DatabaseList) && data.DatabaseList[i] != nil {
|
||||
item.Password = data.DatabaseList[i].Password
|
||||
}
|
||||
}
|
||||
data.DatabaseList = req.Config.Data.DatabaseList
|
||||
}
|
||||
if req.Config.Data.RedisList != nil {
|
||||
for i, item := range req.Config.Data.RedisList {
|
||||
if item != nil && (item.Password == "" || item.Password == "******") && i < len(data.RedisList) && data.RedisList[i] != nil {
|
||||
item.Password = data.RedisList[i].Password
|
||||
}
|
||||
}
|
||||
data.RedisList = req.Config.Data.RedisList
|
||||
}
|
||||
if req.Config.Data.Mongo != nil {
|
||||
if data.Mongo != nil && (req.Config.Data.Mongo.Password == "" || req.Config.Data.Mongo.Password == "******") {
|
||||
req.Config.Data.Mongo.Password = data.Mongo.Password
|
||||
}
|
||||
data.Mongo = req.Config.Data.Mongo
|
||||
}
|
||||
}
|
||||
dataRaw, err := protojson.MarshalOptions{UseProtoNames: true}.Marshal(data)
|
||||
if err != nil {
|
||||
|
||||
@@ -14,10 +14,10 @@ type DatabaseInit struct {
|
||||
Port string `json:"port"`
|
||||
UserName string `json:"userName"`
|
||||
Password string `json:"password"`
|
||||
DBName string `json:"dbName"`
|
||||
DBName string `json:"dbName" binding:"required"`
|
||||
DBPath string `json:"dbPath"`
|
||||
Template string `json:"template"`
|
||||
AdminPassword string `json:"adminPassword"`
|
||||
AdminPassword string `json:"adminPassword" binding:"required"`
|
||||
}
|
||||
|
||||
func (s *SystemService) Initialize(ctx context.Context, input *DatabaseInit, apis []*biz.API) error {
|
||||
@@ -34,7 +34,15 @@ func (s *SystemService) Initialize(ctx context.Context, input *DatabaseInit, api
|
||||
func (s *SystemService) InitializeRoutes(ctx context.Context, input *DatabaseInit, routes []dto.Route) error {
|
||||
apis := make([]*biz.API, 0, len(routes))
|
||||
for _, route := range routes {
|
||||
apis = append(apis, &biz.API{Path: route.Path, Method: route.Method, APIGroup: routeGroup(route.Path)})
|
||||
path := route.Path
|
||||
if config := s.runtime.Admin(); config != nil && config.RouterPrefix != "" {
|
||||
path = strings.TrimPrefix(path, strings.TrimSuffix(config.RouterPrefix, "/"))
|
||||
if path == "" {
|
||||
path = "/"
|
||||
}
|
||||
}
|
||||
group, description := routeMetadata(route.Method, path)
|
||||
apis = append(apis, &biz.API{Path: path, Method: route.Method, APIGroup: group, Description: description})
|
||||
}
|
||||
return s.Initialize(ctx, input, apis)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user