download set with c= to match every host of a cluster
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
||||
restful "github.com/emicklei/go-restful"
|
||||
"github.com/pierrec/lz4"
|
||||
"m.cluseau.fr/go/httperr"
|
||||
|
||||
"novit.tech/direktil/pkg/localconfig"
|
||||
)
|
||||
|
||||
func globMatch(pattern, value string) bool {
|
||||
@@ -27,10 +29,22 @@ type DownloadSet struct {
|
||||
Items []DownloadSetItem
|
||||
}
|
||||
|
||||
func (s DownloadSet) Contains(kind, name, asset string) bool {
|
||||
func (s DownloadSet) Contains(cfg *localconfig.Config, kind, name, asset string) bool {
|
||||
for _, item := range s.Items {
|
||||
if item.Kind == kind && globMatch(item.Name, name) &&
|
||||
slices.Contains(item.Assets, asset) {
|
||||
if item.Kind != kind || !slices.Contains(item.Assets, asset) {
|
||||
continue
|
||||
}
|
||||
|
||||
// c=<cluster> matches any host of the given cluster
|
||||
if kind == "host" && strings.HasPrefix(item.Name, "c=") {
|
||||
host := hostOrTemplate(cfg, name)
|
||||
if host != nil && host.ClusterName == item.Name[2:] {
|
||||
return true
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if globMatch(item.Name, name) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -233,7 +247,13 @@ func wsDownloadSetAsset(req *restful.Request, resp *restful.Response) {
|
||||
name := req.PathParameter("name")
|
||||
asset := req.PathParameter("asset")
|
||||
|
||||
if !set.Contains(kind, name, asset) {
|
||||
cfg, err2 := readConfig()
|
||||
if err2 != nil {
|
||||
wsError(resp, err2)
|
||||
return
|
||||
}
|
||||
|
||||
if !set.Contains(cfg, kind, name, asset) {
|
||||
wsNotFound(resp)
|
||||
return
|
||||
}
|
||||
@@ -273,9 +293,18 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
case "host":
|
||||
section = "Host"
|
||||
for _, h := range cfg.Hosts {
|
||||
if globMatch(item.Name, h.Name) {
|
||||
names = append(names, h.Name)
|
||||
if strings.HasPrefix(item.Name, "c=") {
|
||||
clusterName := item.Name[2:]
|
||||
for _, h := range cfg.Hosts {
|
||||
if h.ClusterName == clusterName {
|
||||
names = append(names, h.Name)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, h := range cfg.Hosts {
|
||||
if globMatch(item.Name, h.Name) {
|
||||
names = append(names, h.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user