From 7f1193cddaebfdbcde0dcddc43a73e4b05717f69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?=
Date: Sun, 27 Jul 2025 12:08:45 +0200
Subject: [PATCH] dlset: allow globs in name, short kind
---
cmd/dkl-local-server/ws-download-set.go | 65 +++++++++++++++++++------
cmd/dkl-local-server/ws-downloads.go | 12 ++---
2 files changed, 55 insertions(+), 22 deletions(-)
diff --git a/cmd/dkl-local-server/ws-download-set.go b/cmd/dkl-local-server/ws-download-set.go
index 3cd60c6..6a2d02b 100644
--- a/cmd/dkl-local-server/ws-download-set.go
+++ b/cmd/dkl-local-server/ws-download-set.go
@@ -6,6 +6,7 @@ import (
"encoding/base32"
"fmt"
"io"
+ "path/filepath"
"slices"
"strconv"
"strings"
@@ -76,7 +77,15 @@ type DownloadSetItem struct {
}
func (i DownloadSetItem) EncodeTo(buf *strings.Builder) {
- buf.WriteString(i.Kind)
+ kind := i.Kind
+ switch kind {
+ case "host":
+ kind = "h"
+ case "cluster":
+ kind = "c"
+ }
+
+ buf.WriteString(kind)
buf.WriteByte(':')
buf.WriteString(i.Name)
@@ -89,6 +98,14 @@ func (i DownloadSetItem) EncodeTo(buf *strings.Builder) {
func (i *DownloadSetItem) Decode(encoded string) {
rem := encoded
i.Kind, rem, _ = strings.Cut(rem, ":")
+
+ switch i.Kind {
+ case "h":
+ i.Kind = "host"
+ case "c":
+ i.Kind = "cluster"
+ }
+
i.Name, rem, _ = strings.Cut(rem, ":")
if rem == "" {
@@ -230,10 +247,8 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) {
` + err.Error() + `
-
+
+
` + err.Error() + `
`))
@@ -245,21 +260,43 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) {
Download set
-
+
+
Download set
`)
+ cfg, err2 := readConfig()
+ if err2 != nil {
+ wsError(resp, err2)
+ return
+ }
+
for _, item := range set.Items {
- fmt.Fprintf(buf, "%s %s
", strings.Title(item.Kind), item.Name)
- fmt.Fprintf(buf, "\n")
- for _, asset := range item.Assets {
- fmt.Fprintf(buf, " %s\n", item.Kind, item.Name, asset, setStr, asset)
+ names := make([]string, 0)
+ switch item.Kind {
+ case "cluster":
+ for _, c := range cfg.Clusters {
+ if ok, _ := filepath.Match(item.Name, c.Name); ok {
+ names = append(names, c.Name)
+ }
+ }
+ case "host":
+ for _, h := range cfg.Hosts {
+ if ok, _ := filepath.Match(item.Name, h.Name); ok {
+ names = append(names, h.Name)
+ }
+ }
+ }
+
+ for _, name := range names {
+ fmt.Fprintf(buf, "
%s %s
", strings.Title(item.Kind), name)
+ fmt.Fprintf(buf, "\n")
+ for _, asset := range item.Assets {
+ fmt.Fprintf(buf, " %s\n", item.Kind, name, asset, setStr, asset)
+ }
+ fmt.Fprintf(buf, `
`)
}
- fmt.Fprintf(buf, `
`)
}
buf.WriteString("")
diff --git a/cmd/dkl-local-server/ws-downloads.go b/cmd/dkl-local-server/ws-downloads.go
index 67868e7..8cf26f7 100644
--- a/cmd/dkl-local-server/ws-downloads.go
+++ b/cmd/dkl-local-server/ws-downloads.go
@@ -184,10 +184,8 @@ func wsDownloadPage(req *restful.Request, resp *restful.Response) {
Token not found
-
+
+
Token not found
`))
@@ -199,10 +197,8 @@ func wsDownloadPage(req *restful.Request, resp *restful.Response) {
Token assets: %s %s
-
+
+
Token assets: %s %s