mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +08:00
feat: 应用关联 redis 时自动填充密码 (#1826)
This commit is contained in:
parent
7c6f8ff7c4
commit
70319aca45
@ -15,6 +15,10 @@ type AuthParam struct {
|
|||||||
RootPassword string `json:"PANEL_DB_ROOT_PASSWORD"`
|
RootPassword string `json:"PANEL_DB_ROOT_PASSWORD"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RedisAuthParam struct {
|
||||||
|
RootPassword string `json:"PANEL_REDIS_ROOT_PASSWORD"`
|
||||||
|
}
|
||||||
|
|
||||||
type ContainerExec struct {
|
type ContainerExec struct {
|
||||||
ContainerName string `json:"containerName"`
|
ContainerName string `json:"containerName"`
|
||||||
DbParam AppDatabase `json:"dbParam"`
|
DbParam AppDatabase `json:"dbParam"`
|
||||||
|
@ -83,20 +83,33 @@ func checkPort(key string, params map[string]interface{}) (int, error) {
|
|||||||
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" {
|
if app.Type == "runtime" {
|
||||||
var authParam dto.AuthParam
|
switch app.Key {
|
||||||
paramByte, err := json.Marshal(params)
|
case "mysql", "mariadb", "postgresql":
|
||||||
if err != nil {
|
if password, ok := params["PANEL_DB_ROOT_PASSWORD"]; ok {
|
||||||
return err
|
if password != "" {
|
||||||
}
|
authParam := dto.AuthParam{
|
||||||
if err := json.Unmarshal(paramByte, &authParam); err != nil {
|
RootPassword: password.(string),
|
||||||
return err
|
}
|
||||||
}
|
authByte, err := json.Marshal(authParam)
|
||||||
if authParam.RootPassword != "" {
|
if err != nil {
|
||||||
authByte, err := json.Marshal(authParam)
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
appInstall.Param = string(authByte)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "redis":
|
||||||
|
if password, ok := params["PANEL_REDIS_ROOT_PASSWORD"]; ok {
|
||||||
|
if password != "" {
|
||||||
|
authParam := dto.RedisAuthParam{
|
||||||
|
RootPassword: password.(string),
|
||||||
|
}
|
||||||
|
authByte, err := json.Marshal(authParam)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
appInstall.Param = string(authByte)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
appInstall.Param = string(authByte)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if app.Type == "website" || app.Type == "tool" {
|
if app.Type == "website" || app.Type == "tool" {
|
||||||
@ -104,7 +117,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(paramByte, &dbConfig); err != nil {
|
if err = json.Unmarshal(paramByte, &dbConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ func Init() {
|
|||||||
migrations.UpdateAppDetail,
|
migrations.UpdateAppDetail,
|
||||||
migrations.EncryptHostPassword,
|
migrations.EncryptHostPassword,
|
||||||
migrations.AddRemoteDB,
|
migrations.AddRemoteDB,
|
||||||
|
migrations.UpdateRedisParam,
|
||||||
})
|
})
|
||||||
if err := m.Migrate(); err != nil {
|
if err := m.Migrate(); err != nil {
|
||||||
global.LOG.Error(err)
|
global.LOG.Error(err)
|
||||||
|
@ -523,3 +523,27 @@ var AddRemoteDB = &gormigrate.Migration{
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var UpdateRedisParam = &gormigrate.Migration{
|
||||||
|
ID: "20230804-update-redis-param",
|
||||||
|
Migrate: func(tx *gorm.DB) error {
|
||||||
|
var (
|
||||||
|
app model.App
|
||||||
|
appInstall model.AppInstall
|
||||||
|
)
|
||||||
|
if err := global.DB.Where("key = ?", "redis").First(&app).Error; err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := global.DB.Where("app_id = ?", app.ID).First(&appInstall).Error; err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
appInstall.Param = strings.ReplaceAll(appInstall.Param, "PANEL_DB_ROOT_PASSWORD", "PANEL_REDIS_ROOT_PASSWORD")
|
||||||
|
appInstall.DockerCompose = strings.ReplaceAll(appInstall.DockerCompose, "PANEL_DB_ROOT_PASSWORD", "PANEL_REDIS_ROOT_PASSWORD")
|
||||||
|
appInstall.Env = strings.ReplaceAll(appInstall.Env, "PANEL_DB_ROOT_PASSWORD", "PANEL_REDIS_ROOT_PASSWORD")
|
||||||
|
if err := tx.Model(&model.AppInstall{}).Where("id = ?", appInstall.ID).Updates(appInstall).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user