Skip to content

Commit 5398819

Browse files
committed
feat: Complete the node initialization logic
1 parent 5dbd16a commit 5398819

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

agent/app/model/setting.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ type Setting struct {
88
}
99

1010
type NodeInfo struct {
11-
Scope string `json:"scope"`
12-
BaseDir string `json:"baseDir"`
13-
Version string `json:"version"`
14-
EncryptKey string `json:"encryptKey"`
15-
ServerCrt string `json:"serverCrt"`
16-
ServerKey string `json:"serverKey"`
11+
Scope string `json:"scope"`
12+
BaseDir string `json:"baseDir"`
13+
Version string `json:"version"`
14+
ServerCrt string `json:"serverCrt"`
15+
ServerKey string `json:"serverKey"`
1716
}

agent/app/repo/app_launcher.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type ILauncherRepo interface {
1313
Create(launcher *model.AppLauncher) error
1414
Save(launcher *model.AppLauncher) error
1515
Delete(opts ...DBOption) error
16+
17+
SyncAll(data []model.AppLauncher) error
1618
}
1719

1820
func NewILauncherRepo() ILauncherRepo {
@@ -53,3 +55,17 @@ func (u *LauncherRepo) Delete(opts ...DBOption) error {
5355
}
5456
return db.Delete(&model.AppLauncher{}).Error
5557
}
58+
59+
func (u *LauncherRepo) SyncAll(data []model.AppLauncher) error {
60+
tx := global.DB.Begin()
61+
if err := tx.Where("1 = 1").Delete(&model.AppLauncher{}).Error; err != nil {
62+
tx.Rollback()
63+
return err
64+
}
65+
if err := tx.Model(model.AppLauncher{}).Save(&data).Error; err != nil {
66+
tx.Rollback()
67+
return err
68+
}
69+
tx.Commit()
70+
return nil
71+
}

agent/app/repo/backup.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type IBackupRepo interface {
2626
WithByFileName(fileName string) DBOption
2727
WithByCronID(cronjobID uint) DBOption
2828
WithFileNameStartWith(filePrefix string) DBOption
29+
30+
SyncAll(data []model.BackupAccount) error
2931
}
3032

3133
func NewIBackupRepo() IBackupRepo {
@@ -153,3 +155,17 @@ func (u *BackupRepo) GetRecord(opts ...DBOption) (*model.BackupRecord, error) {
153155
err := db.Find(record).Error
154156
return record, err
155157
}
158+
159+
func (u *BackupRepo) SyncAll(data []model.BackupAccount) error {
160+
tx := global.DB.Begin()
161+
if err := tx.Where("1 = 1").Delete(&model.BackupAccount{}).Error; err != nil {
162+
tx.Rollback()
163+
return err
164+
}
165+
if err := tx.Model(model.BackupAccount{}).Save(&data).Error; err != nil {
166+
tx.Rollback()
167+
return err
168+
}
169+
tx.Commit()
170+
return nil
171+
}

agent/app/service/setting.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func (u *SettingService) ReloadConn() error {
106106

107107
global.CONF.System.BaseDir = nodeInfo.BaseDir
108108
global.CONF.System.Version = nodeInfo.Version
109-
global.CONF.System.EncryptKey = nodeInfo.EncryptKey
110109
global.IsMaster = nodeInfo.Scope == "master"
111110
return nil
112111
}

agent/init/hook/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func initGlobalData() {
2626
if err := settingRepo.Update("SystemStatus", "Free"); err != nil {
2727
global.LOG.Fatalf("init service before start failed, err: %v", err)
2828
}
29-
29+
global.CONF.System.EncryptKey, _ = settingRepo.GetValueByKey("EncryptKey")
3030
_ = service.NewISettingService().ReloadConn()
3131
if global.IsMaster {
3232
global.CoreDB = common.LoadDBConnByPath(path.Join(global.CONF.System.DbPath, "core.db"), "core")

agent/init/migration/migrations/init.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ var InitSetting = &gormigrate.Migration{
8181
if err := tx.Create(&model.Setting{Key: "BaseDir", Value: nodeInfo.BaseDir}).Error; err != nil {
8282
return err
8383
}
84-
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: nodeInfo.EncryptKey}).Error; err != nil {
85-
return err
86-
}
8784
itemKey, _ := encrypt.StringEncrypt(nodeInfo.ServerKey)
8885
if err := tx.Create(&model.Setting{Key: "ServerKey", Value: itemKey}).Error; err != nil {
8986
return err
@@ -99,6 +96,9 @@ var InitSetting = &gormigrate.Migration{
9996
return err
10097
}
10198

99+
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: common.RandStr(16)}).Error; err != nil {
100+
return err
101+
}
102102
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
103103
return err
104104
}

agent/utils/xpack/xpack.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/1Panel-dev/1Panel/agent/buserr"
1515
"github.com/1Panel-dev/1Panel/agent/constant"
1616
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
17-
"github.com/1Panel-dev/1Panel/agent/utils/common"
1817
)
1918

2019
func RemoveTamper(website string) {}
@@ -48,7 +47,6 @@ func LoadNodeInfo() (bool, model.NodeInfo, error) {
4847
var info model.NodeInfo
4948
info.BaseDir = loadParams("BASE_DIR")
5049
info.Version = loadParams("ORIGINAL_VERSION")
51-
info.EncryptKey = common.RandStr(16)
5250
info.Scope = "master"
5351
return false, info, nil
5452
}

0 commit comments

Comments
 (0)