From d03a7ab4eceffa599710034f7fcde656f9feb645 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 | 72 +++++++++++++++++++------ cmd/dkl-local-server/ws-downloads.go | 12 ++--- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/cmd/dkl-local-server/ws-download-set.go b/cmd/dkl-local-server/ws-download-set.go index 3cd60c6..71df998 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" @@ -16,6 +17,11 @@ import ( "m.cluseau.fr/go/httperr" ) +func globMatch(pattern, value string) bool { + ok, _ := filepath.Match(pattern, value) + return ok +} + type DownloadSet struct { Expiry time.Time Items []DownloadSetItem @@ -23,7 +29,7 @@ type DownloadSet struct { func (s DownloadSet) Contains(kind, name, asset string) bool { for _, item := range s.Items { - if item.Kind == kind && item.Name == name && + if item.Kind == kind && globMatch(item.Name, name) && slices.Contains(item.Assets, asset) { return true } @@ -76,7 +82,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 +103,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 +252,8 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) { ` + err.Error() + ` - + + + +