diff --git a/cmd/dkl-local-server/ws-download-set.go b/cmd/dkl-local-server/ws-download-set.go index bfc2ee1..53ebada 100644 --- a/cmd/dkl-local-server/ws-download-set.go +++ b/cmd/dkl-local-server/ws-download-set.go @@ -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= 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) + } } } } diff --git a/html/ui/Cluster-8864c22a73e68a3e.js b/html/ui/Cluster-361bc6b76a062d88.js similarity index 90% rename from html/ui/Cluster-8864c22a73e68a3e.js rename to html/ui/Cluster-361bc6b76a062d88.js index 943cfe9..6d7cdf2 100644 --- a/html/ui/Cluster-8864c22a73e68a3e.js +++ b/html/ui/Cluster-361bc6b76a062d88.js @@ -4,16 +4,16 @@ const Cluster = { template: ` -

Tokens

+ + +

Secrets

+

Tokens

- -

Passwords

+

Passwords

- - ` } diff --git a/html/ui/ClusterAccess-fede0ff535b7cf.js b/html/ui/ClusterAccess-e67af72c976d642c.js similarity index 97% rename from html/ui/ClusterAccess-fede0ff535b7cf.js rename to html/ui/ClusterAccess-e67af72c976d642c.js index 0544790..926c3fe 100644 --- a/html/ui/ClusterAccess-fede0ff535b7cf.js +++ b/html/ui/ClusterAccess-e67af72c976d642c.js @@ -79,12 +79,11 @@ const ClusterAccess = { generateDownloadSet() { event.preventDefault() - const hosts = this.hostCount ? (this.state.Hosts||[]).filter(h => h.Cluster == this.cluster.Name) : [] - const items = hosts.map(h => ({ + const items = [{ Kind: "host", - Name: h.Name, + Name: "c=" + this.cluster.Name, Assets: this.selectedAssetList, - })) + }] fetch('/sign-download-set', { method: 'POST', diff --git a/html/ui/index.html b/html/ui/index.html index a4c2994..493e515 100644 --- a/html/ui/index.html +++ b/html/ui/index.html @@ -13,9 +13,9 @@ - + - + diff --git a/ui/js/Cluster.js b/ui/js/Cluster.js index 943cfe9..6d7cdf2 100644 --- a/ui/js/Cluster.js +++ b/ui/js/Cluster.js @@ -4,16 +4,16 @@ const Cluster = { template: ` -

Tokens

+ + +

Secrets

+

Tokens

- -

Passwords

+

Passwords

- - ` } diff --git a/ui/js/ClusterAccess.js b/ui/js/ClusterAccess.js index 0544790..926c3fe 100644 --- a/ui/js/ClusterAccess.js +++ b/ui/js/ClusterAccess.js @@ -79,12 +79,11 @@ const ClusterAccess = { generateDownloadSet() { event.preventDefault() - const hosts = this.hostCount ? (this.state.Hosts||[]).filter(h => h.Cluster == this.cluster.Name) : [] - const items = hosts.map(h => ({ + const items = [{ Kind: "host", - Name: h.Name, + Name: "c=" + this.cluster.Name, Assets: this.selectedAssetList, - })) + }] fetch('/sign-download-set', { method: 'POST',