diff --git a/configmanage/server/global/plugin_configmanage.go b/configmanage/server/global/plugin_configmanage.go index 4aa5899c8c5ec4196c7d34fc1264afb4b53a93e8..8e8d138661427e44e09ccda51a274d492df99815 100644 --- a/configmanage/server/global/plugin_configmanage.go +++ b/configmanage/server/global/plugin_configmanage.go @@ -26,4 +26,5 @@ const ( SSH = "ssh" SSHD = "sshd" Sysctl = "sysctl" + DNS = "dns" ) diff --git a/configmanage/server/internal/dnsfile.go b/configmanage/server/internal/dnsfile.go new file mode 100644 index 0000000000000000000000000000000000000000..e5b8a50a84b53a2ea25b9f0ef6f88b1688ee70bd --- /dev/null +++ b/configmanage/server/internal/dnsfile.go @@ -0,0 +1,51 @@ +package internal + +import ( + "encoding/json" + "time" + + "openeuler.org/PilotGo/configmanage-plugin/db" +) + +type DNSFile struct { + ID int `gorm:"unique;autoIncrement:true"` + UUID string `gorm:"primary_key;type:varchar(50)" json:"uuid"` + ConfigInfo ConfigInfo `gorm:"Foreignkey:ConfigInfoUUID"` + ConfigInfoUUID string + Path string `json:"path"` + Name string `json:"name"` + Content json.RawMessage `gorm:"type:json" json:"content"` + Version string `gorm:"type:varchar(50)" json:"version"` + IsActive bool `json:"isactive"` + IsFromHost bool `gorm:"default:false" json:"isfromhost"` + Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` + CreatedAt time.Time +} + +func (df *DNSFile) Add() error { + sql := ` + INSERT INTO dns_file (uuid,config_info_uuid,path,name,content,version,is_active,is_from_host,hostuuid) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) + ON DUPLICATE KEY UPDATE + uuid = VALUES(uuid), + config_info_uuid = VALUES(config_info_uuid), + path = VALUES(path), + name = VALUES(name), + content = VALUES(content), + version = VALUES(version), + is_active = VALUES(is_active), + is_from_host = VALUES(is_from_host), + hostuuid = VALUES(hostuuid); + ` + return db.MySQL().Exec(sql, + df.UUID, + df.ConfigInfoUUID, + df.Path, + df.Name, + df.Content, + df.Version, + df.IsActive, + df.IsFromHost, + df.Hostuuid, + ).Error +} diff --git a/configmanage/server/service/configinstance.go b/configmanage/server/service/configinstance.go index e33b610fd66d51dc2aa2234162e0fcd92be418cb..8a77e3d0c8600a81643819b0287fa1849810bd0f 100644 --- a/configmanage/server/service/configinstance.go +++ b/configmanage/server/service/configinstance.go @@ -48,6 +48,10 @@ func Init() error { if err != nil { return err } + err = db.MySQL().Set("gorm:table_options", "ENGINE=InnoDB CHARACTER SET utf8mb4").AutoMigrate(&internal.DNSFile{}) + if err != nil { + return err + } return nil }