From 85394ab70538e94885b144d78711625f85d8e020 Mon Sep 17 00:00:00 2001 From: wubijie Date: Wed, 6 Nov 2024 10:33:11 +0800 Subject: [PATCH] add GetSSHDFileByUUID and UpdateByuuid error { --- configmanage/server/internal/sshd.go | 16 ++++++++++++++++ configmanage/server/service/ssh_test.go | 8 ++++---- configmanage/server/service/sshd_test.go | 15 +++++++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/configmanage/server/internal/sshd.go b/configmanage/server/internal/sshd.go index c586e4ed..a0a8fd26 100644 --- a/configmanage/server/internal/sshd.go +++ b/configmanage/server/internal/sshd.go @@ -34,3 +34,19 @@ func GetSSHDFileByInfoUUID(uuid string, isindex interface{}) (SSHDFile, error) { err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error return file, err } + +func GetSSHDFileByUUID(uuid string) (SSHDFile, error) { + var file SSHDFile + err := db.MySQL().Model(&SSHDFile{}).Where("uuid=?", uuid).Find(&file).Error + return file, err +} + +func (sdf *SSHDFile) UpdateByuuid() error { + // 将同类配置的所有标志修改为未使用 + err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=?", sdf.ConfigInfoUUID).Update("is_index", 0).Error + if err != nil { + return err + } + // 将成功下发的具体某一个配置状态修改为已使用 + return db.MySQL().Model(&SSHDFile{}).Where("uuid=?", sdf.UUID).Update("is_index", 1).Error +} diff --git a/configmanage/server/service/ssh_test.go b/configmanage/server/service/ssh_test.go index ebc265e6..b973c2ea 100644 --- a/configmanage/server/service/ssh_test.go +++ b/configmanage/server/service/ssh_test.go @@ -39,7 +39,7 @@ func TestSSHConfig_Load(t *testing.T) { fmt.Printf("record error: %s\n", err) os.Exit(-1) } - fmt.Printf("sc: %v\n", sc) + fmt.Printf("sshconfig: %v\n", sc) } func TestGetSSHFileByUUID(t *testing.T) { @@ -49,15 +49,15 @@ func TestGetSSHFileByUUID(t *testing.T) { fmt.Printf("get ssh file error: %s\n", err) os.Exit(-1) } - fmt.Printf("hc: %v\n", sf) + fmt.Printf("sshfile: %v\n", sf) } func TestGetSSHFilesByCinfigUUID(t *testing.T) { // 设置测试数据 - testUUID := "5973e993-6236-4b53-9eb6-0cc23c652460" + scUUID := "5973e993-6236-4b53-9eb6-0cc23c652460" // 调用被测试的函数 - files, err := GetSSHFilesByCinfigUUID(testUUID) + files, err := GetSSHFilesByCinfigUUID(scUUID) if err != nil { fmt.Printf("load sshfiles error: %s\n", err) os.Exit(-1) diff --git a/configmanage/server/service/sshd_test.go b/configmanage/server/service/sshd_test.go index dc02a66d..f54037e9 100644 --- a/configmanage/server/service/sshd_test.go +++ b/configmanage/server/service/sshd_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/google/uuid" + "openeuler.org/PilotGo/configmanage-plugin/internal" ) func TestSSHDConfig_Record(t *testing.T) { @@ -16,7 +17,7 @@ func TestSSHDConfig_Record(t *testing.T) { ConfigInfoUUID: "4d415c77-5a3d-45fb-a221-67dba74db56d", Content: json.RawMessage(`{"test": "test"}`), Path: "/ssh", - Name: "ssh.txt", + Name: "sshd.txt", IsActive: false, } @@ -38,5 +39,15 @@ func TestSSHDConfig_Load(t *testing.T) { fmt.Printf("record error: %s\n", err) os.Exit(-1) } - fmt.Printf("sdc: %v\n", sdc) + fmt.Printf("sshdconfig: %v\n", sdc) +} + +func TestGetSSHDFileByUUID(t *testing.T) { + uuid := "ab9b9ee6-8750-46ce-958c-4d3e26bbf877" + sdf, err := internal.GetSSHDFileByUUID(uuid) + if err != nil { + fmt.Printf("get sshd file error: %s\n", err) + os.Exit(-1) + } + fmt.Printf("sshdfile: %v\n", sdf) } -- Gitee