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

pull/3234/head
zhengkunwang 12 months ago committed by GitHub
parent 504d5f8596
commit fb709e7eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,12 +13,18 @@ type AppDatabase struct {
type AuthParam struct { type AuthParam struct {
RootPassword string `json:"PANEL_DB_ROOT_PASSWORD"` RootPassword string `json:"PANEL_DB_ROOT_PASSWORD"`
RootUser string `json:"PANEL_DB_ROOT_USER"`
} }
type RedisAuthParam struct { type RedisAuthParam struct {
RootPassword string `json:"PANEL_REDIS_ROOT_PASSWORD"` 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 { type ContainerExec struct {
ContainerName string `json:"containerName"` ContainerName string `json:"containerName"`
DbParam AppDatabase `json:"dbParam"` DbParam AppDatabase `json:"dbParam"`

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

Loading…
Cancel
Save