diff --git a/configmanage/server/controller/configinstance.go b/configmanage/server/controller/configinstance.go index 510c749f1fecb9b427dc3697c791bf77aa2622d9..8fd362ba6c28ccbae3339997b16e1e2fb2cb35b5 100644 --- a/configmanage/server/controller/configinstance.go +++ b/configmanage/server/controller/configinstance.go @@ -207,6 +207,7 @@ func LoadConfigHandler(c *gin.Context) { } } +// TODO: 考虑问价下发和执行命令使用配置 func ApplyConfigHandler(c *gin.Context) { //TODO:修改请求的参数 query := &struct { diff --git a/configmanage/server/internal/ssh.go b/configmanage/server/internal/ssh.go new file mode 100644 index 0000000000000000000000000000000000000000..e65d2d9fb5a6b8be22397b29338eaabbaaf06c97 --- /dev/null +++ b/configmanage/server/internal/ssh.go @@ -0,0 +1,27 @@ +package internal + +import ( + "encoding/json" + "time" + + "openeuler.org/PilotGo/configmanage-plugin/db" +) + +type SSHFile 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 (sf *SSHFile) Add() error { + return db.MySQL().Save(&sf).Error +} diff --git a/configmanage/server/service/ssh.go b/configmanage/server/service/ssh.go new file mode 100644 index 0000000000000000000000000000000000000000..1377607e8d46acae44f5c27aec358cc4e50eea48 --- /dev/null +++ b/configmanage/server/service/ssh.go @@ -0,0 +1,54 @@ +package service + +import ( + "encoding/json" + "errors" + "fmt" + "time" + + "openeuler.org/PilotGo/configmanage-plugin/internal" +) + +/* +ssh: 配置文件 + +一般方法: 1、在/etc/ssh/ssh_config中修改内容 + + 2、执行命令systemctl restart ssh重启ssh服务 + +考虑的问题: +*/ +type SSHFile = internal.SSHFile +type SSHConfig struct { + UUID string `json:"uuid"` + ConfigInfoUUID string `json:"configinfouuid"` + Content json.RawMessage `json:"content"` + Version string `json:"version"` + Path string `json:"path"` + Name string `json:"name"` + //下发改变标志位 + IsActive bool `json:"isactive"` +} + +func (sc *SSHConfig) toSSHFile() SSHFile { + return SSHFile{ + UUID: sc.UUID, + ConfigInfoUUID: sc.ConfigInfoUUID, + Path: sc.Path, + Name: sc.Name, + Content: sc.Content, + Version: fmt.Sprintf("v%s", time.Now().Format("2006-01-02-15-04-05")), + IsActive: sc.IsActive, + } +} + +func (sc *SSHConfig) Record() error { + //检查info的uuid是否存在 + ci, err := GetInfoByUUID(sc.ConfigInfoUUID) + if err != nil || ci.UUID == "" { + return errors.New("configinfo uuid not exist") + } + + sf := sc.toSSHFile() + return sf.Add() +} diff --git a/configmanage/server/service/ssh_test.go b/configmanage/server/service/ssh_test.go new file mode 100644 index 0000000000000000000000000000000000000000..6d43c3366ca3e6c323c783077e9aa02280048c57 --- /dev/null +++ b/configmanage/server/service/ssh_test.go @@ -0,0 +1 @@ +package service