diff --git a/server/http_api.go b/server/http_api.go index 6908172..142f4fb 100644 --- a/server/http_api.go +++ b/server/http_api.go @@ -34,6 +34,16 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) { enc.Encode(allHosts) } +func readTagsFromFile(paths ...string) string { + raw, _ := os.ReadFile(path.Join(paths...)) + if len(raw) > 0 { + tag := string(raw) + return strings.Trim(tag, "\n") + } + + return "" +} + func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) { files, err := os.ReadDir(h.deployPath) if err != nil { @@ -44,18 +54,15 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request getVersions := func(name string) []string { vers, _ := os.ReadDir(path.Join(h.deployPath, name)) - mytags, _ := os.ReadFile(path.Join(h.deployPath, name, "@tags")) - + mytags := readTagsFromFile(h.deployPath, name, "@tags") out := []string{ - string(mytags), + mytags, } for _, fd := range vers { if fd.IsDir() { ver := fd.Name() files, _ := os.ReadDir(path.Join(h.deployPath, name, ver)) - vertags, _ := os.ReadFile(path.Join(h.deployPath, name, ver, "@tags")) - ver = ver + string(mytags) + string(vertags) - + vertags := readTagsFromFile(h.deployPath, name, ver, "@tags") if len(files) > 0 { for _, file := range files { if strings.HasPrefix(file.Name(), "@") { @@ -63,7 +70,7 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request } downloadpath := path.Join(sub_folder_name_deploys, name, ver, file.Name()) - ver = fmt.Sprintf("%s:%s", ver, downloadpath) + ver = fmt.Sprintf("%s:%s", ver+mytags+vertags, downloadpath) break } } @@ -115,10 +122,10 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque if version == "config" { filename = path.Join(h.deployPath, name, version, "config"+ext) - tags, _ := os.ReadFile(path.Join(h.deployPath, name, version, "@tags")) - if !strings.Contains(string(tags), "#hidden") { - tags = []byte(string(tags) + "#hidden") - os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), tags, 0644) + tags := readTagsFromFile(h.deployPath, name, version, "@tags") + if !strings.Contains(tags, "#hidden") { + tags = tags + "#hidden" + os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), []byte(tags), 0644) } } else { filename = path.Join(h.deployPath, name, version, name+ext)