From cb459d299fe6f58477f264ab420b72170622daf4 Mon Sep 17 00:00:00 2001 From: wubijie Date: Mon, 4 Nov 2024 15:39:21 +0800 Subject: [PATCH] Improve the handling of host configuration logic using the Config InfoHandler --- configmanage/server/controller/lists.go | 10 +++++++++- configmanage/server/internal/hostfile.go | 2 +- configmanage/server/service/host.go | 4 ++-- configmanage/server/service/host_test.go | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/configmanage/server/controller/lists.go b/configmanage/server/controller/lists.go index 46b1e8e9..def88655 100644 --- a/configmanage/server/controller/lists.go +++ b/configmanage/server/controller/lists.go @@ -76,7 +76,15 @@ func ConfigInfoHandler(c *gin.Context) { response.Success(c, repofiles, "load repo config success") case global.Host: - + // 获取有关配置的所有文件信息 + repofiles, err := service.GetHostFilesByConfigUUID(ci.UUID) + if err != nil { + logger.Error("failed to get hostconfig file:s %s", err.Error()) + response.Fail(c, "failed to get hostconfig files", err.Error()) + return + } + logger.Debug("load hostconfig success") + response.Success(c, repofiles, "load hostconfig success") case global.SSH: case global.SSHD: diff --git a/configmanage/server/internal/hostfile.go b/configmanage/server/internal/hostfile.go index b2763285..41adec52 100644 --- a/configmanage/server/internal/hostfile.go +++ b/configmanage/server/internal/hostfile.go @@ -53,7 +53,7 @@ func (hf *HostFile) UpdateByuuid() error { } // 根据配置uuid获取所有配置文件 -func GetHostFilesByCinfigUUID(uuid string) ([]HostFile, error) { +func GetHostFilesByConfigUUID(uuid string) ([]HostFile, error) { var files []HostFile err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=?", uuid).Find(&files).Error return files, err diff --git a/configmanage/server/service/host.go b/configmanage/server/service/host.go index 28ce3473..5b36d2f4 100644 --- a/configmanage/server/service/host.go +++ b/configmanage/server/service/host.go @@ -159,6 +159,6 @@ func (hc *HostConfig) Collect() error { } // 根据配置uuid获取所有配置文件 -func GetHostFilesByCinfigUUID(uuid string) ([]HostFile, error) { - return internal.GetHostFilesByCinfigUUID(uuid) +func GetHostFilesByConfigUUID(uuid string) ([]HostFile, error) { + return internal.GetHostFilesByConfigUUID(uuid) } diff --git a/configmanage/server/service/host_test.go b/configmanage/server/service/host_test.go index 6618ffd8..bbb2711a 100644 --- a/configmanage/server/service/host_test.go +++ b/configmanage/server/service/host_test.go @@ -52,12 +52,12 @@ func TestGetHostFileByUUID(t *testing.T) { fmt.Printf("hc: %v\n", hf) } -func TestGetHostFilesByCinfigUUID(t *testing.T) { +func TestGetHostFilesByConfigUUID(t *testing.T) { // 设置测试数据 testUUID := "158e0acf-159b-4876-83b1-fa5f3d6460b1" // 调用被测试的函数 - files, err := GetHostFilesByCinfigUUID(testUUID) + files, err := GetHostFilesByConfigUUID(testUUID) if err != nil { fmt.Printf("load hostfiles error: %s\n", err) os.Exit(-1) -- Gitee