Merge branch 'master' into kd-live

This commit is contained in:
2023-07-03 14:32:09 +09:00

View File

@ -34,6 +34,16 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) {
enc.Encode(allHosts) 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) { func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
files, err := os.ReadDir(h.deployPath) files, err := os.ReadDir(h.deployPath)
if err != nil { if err != nil {
@ -44,18 +54,15 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request
getVersions := func(name string) []string { getVersions := func(name string) []string {
vers, _ := os.ReadDir(path.Join(h.deployPath, name)) 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{ out := []string{
string(mytags), mytags,
} }
for _, fd := range vers { for _, fd := range vers {
if fd.IsDir() { if fd.IsDir() {
ver := fd.Name() ver := fd.Name()
files, _ := os.ReadDir(path.Join(h.deployPath, name, ver)) files, _ := os.ReadDir(path.Join(h.deployPath, name, ver))
vertags, _ := os.ReadFile(path.Join(h.deployPath, name, ver, "@tags")) vertags := readTagsFromFile(h.deployPath, name, ver, "@tags")
ver = ver + string(mytags) + string(vertags)
if len(files) > 0 { if len(files) > 0 {
for _, file := range files { for _, file := range files {
if strings.HasPrefix(file.Name(), "@") { 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()) 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 break
} }
} }
@ -115,10 +122,10 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
if version == "config" { if version == "config" {
filename = path.Join(h.deployPath, name, version, "config"+ext) filename = path.Join(h.deployPath, name, version, "config"+ext)
tags, _ := os.ReadFile(path.Join(h.deployPath, name, version, "@tags")) tags := readTagsFromFile(h.deployPath, name, version, "@tags")
if !strings.Contains(string(tags), "#hidden") { if !strings.Contains(tags, "#hidden") {
tags = []byte(string(tags) + "#hidden") tags = tags + "#hidden"
os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), tags, 0644) os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), []byte(tags), 0644)
} }
} else { } else {
filename = path.Join(h.deployPath, name, version, name+ext) filename = path.Join(h.deployPath, name, version, name+ext)