diff --git a/configmanage/server/service/sshd.go b/configmanage/server/service/sshd.go new file mode 100644 index 0000000000000000000000000000000000000000..117863b2b6385170d9d61b62862c08bcb00f5075 --- /dev/null +++ b/configmanage/server/service/sshd.go @@ -0,0 +1,54 @@ +package service + +import ( + "encoding/json" + "errors" + "fmt" + "time" + + "openeuler.org/PilotGo/configmanage-plugin/internal" +) + +/* +sshd: 配置文件,sshd_config文件只有一个 + +一般方法: 1、在/etc/ssh/sshd_config中修改内容 + + 2、执行命令systemctl restart sshd重启sshd服务 + +考虑的问题: +*/ +type SSHDFile = internal.SSHDFile +type SSHDConfig 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 (sdc *SSHDConfig) toSSHDFile() SSHDFile { + return SSHDFile{ + UUID: sdc.UUID, + ConfigInfoUUID: sdc.ConfigInfoUUID, + Path: sdc.Path, + Name: sdc.Name, + Content: sdc.Content, + Version: fmt.Sprintf("v%s", time.Now().Format("2006-01-02-15-04-05")), + IsActive: sdc.IsActive, + } +} + +func (sdc *SSHDConfig) Record() error { + //检查info的uuid是否存在 + ci, err := GetInfoByUUID(sdc.ConfigInfoUUID) + if err != nil || ci.UUID == "" { + return errors.New("configinfo uuid not exist") + } + + sdf := sdc.toSSHDFile() + return sdf.Add() +} diff --git a/configmanage/server/service/sshd_test.go b/configmanage/server/service/sshd_test.go new file mode 100644 index 0000000000000000000000000000000000000000..6d43c3366ca3e6c323c783077e9aa02280048c57 --- /dev/null +++ b/configmanage/server/service/sshd_test.go @@ -0,0 +1 @@ +package service