Browse Source

feat: 增加安装应用时 mongodb 和 minio 的用户名/密码自动填写 (#3231)

pull/3234/head
zhengkunwang 12 months ago committed by GitHub
parent
commit
fb709e7eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      backend/app/dto/app.go
  2. 39
      backend/app/service/app_utils.go

6
backend/app/dto/app.go

@ -13,12 +13,18 @@ type AppDatabase struct {
type AuthParam struct {
RootPassword string `json:"PANEL_DB_ROOT_PASSWORD"`
RootUser string `json:"PANEL_DB_ROOT_USER"`
}
type RedisAuthParam struct {
RootPassword string `json:"PANEL_REDIS_ROOT_PASSWORD"`
}
type MinioAuthParam struct {
RootPassword string `json:"PANEL_MINIO_ROOT_PASSWORD"`
RootUser string `json:"PANEL_MINIO_ROOT_USER"`
}
type ContainerExec struct {
ContainerName string `json:"containerName"`
DbParam AppDatabase `json:"dbParam"`

39
backend/app/service/app_utils.go

@ -118,9 +118,13 @@ var DatabaseKeys = map[string]uint{
"memcached": 11211,
}
var ToolKeys = map[string]uint{
"minio": 9001,
}
func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall, params map[string]interface{}) error {
var dbConfig dto.AppDatabase
if app.Type == "runtime" && DatabaseKeys[app.Key] > 0 {
if DatabaseKeys[app.Key] > 0 {
database := &model.Database{
AppInstallID: appInstall.ID,
Name: appInstall.Name,
@ -153,21 +157,23 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
case "mysql", "mariadb", "postgresql", "mongodb":
if password, ok := params["PANEL_DB_ROOT_PASSWORD"]; ok {
if password != "" {
database.Password = password.(string)
if app.Key == "mysql" || app.Key == "mariadb" {
database.Username = "root"
}
if rootUser, ok := params["PANEL_DB_ROOT_USER"]; ok {
database.Username = rootUser.(string)
}
authParam := dto.AuthParam{
RootPassword: password.(string),
RootUser: database.Username,
}
authByte, err := json.Marshal(authParam)
if err != nil {
return err
}
appInstall.Param = string(authByte)
database.Password = password.(string)
if app.Key == "mysql" || app.Key == "mariadb" {
database.Username = "root"
}
if rootUser, ok := params["PANEL_DB_ROOT_USER"]; ok {
database.Username = rootUser.(string)
}
}
}
case "redis":
@ -189,6 +195,23 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
return err
}
}
if ToolKeys[app.Key] > 0 {
if app.Key == "minio" {
authParam := dto.MinioAuthParam{}
if password, ok := params["PANEL_MINIO_ROOT_PASSWORD"]; ok {
authParam.RootPassword = password.(string)
}
if rootUser, ok := params["PANEL_MINIO_ROOT_USER"]; ok {
authParam.RootUser = rootUser.(string)
}
authByte, err := json.Marshal(authParam)
if err != nil {
return err
}
appInstall.Param = string(authByte)
}
}
if app.Type == "website" || app.Type == "tool" {
paramByte, err := json.Marshal(params)
if err != nil {

Loading…
Cancel
Save