feat: added kwargs and flags to pass to plugins

This commit is contained in:
David Allen 2025-09-01 18:59:12 -06:00
parent dc6a141ca1
commit 42c8fd7c1a
Signed by: towk
GPG key ID: 0430CDBE22619155
6 changed files with 95 additions and 7 deletions

View file

@ -11,18 +11,23 @@ import (
"strings"
"git.towk2.me/towk/makeshift/internal/archive"
"git.towk2.me/towk/makeshift/internal/kwargs"
makeshift "git.towk2.me/towk/makeshift/pkg"
"git.towk2.me/towk/makeshift/pkg/storage"
"github.com/go-chi/chi/v5"
"github.com/rs/zerolog/log"
)
func (s *Service) Download() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
path = s.PathForData() + strings.TrimPrefix(r.URL.Path, "/download")
pluginNames = strings.Split(r.URL.Query().Get("plugins"), ",")
profileIDs = strings.Split(r.URL.Query().Get("profiles"), ",")
path = s.PathForData() + strings.TrimPrefix(r.URL.Path, "/download")
pluginKWArgs = chi.URLParam(r, "kwargs")
pluginArgs = strings.Split(r.URL.Query().Get("args"), ",")
pluginNames = strings.Split(r.URL.Query().Get("plugins"), ",")
profileIDs = strings.Split(r.URL.Query().Get("profiles"), ",")
kw *kwargs.KWArgs
fileInfo os.FileInfo
out *os.File
store *storage.MemoryStorage = new(storage.MemoryStorage)
@ -32,8 +37,12 @@ func (s *Service) Download() http.HandlerFunc {
err error
)
// parse the KWArgs from request
kw.Set(pluginKWArgs)
// initialize storage
store.Init()
store.SetKWArgs(kw)
log.Debug().
Str("path", path).
@ -78,7 +87,7 @@ func (s *Service) Download() http.HandlerFunc {
log.Debug().Strs("files", filenamesToArchive).Send()
// prepare plugins
hooks, errs = s.loadPlugins(pluginNames, store, nil, errs)
hooks, errs = s.loadPlugins(pluginNames, store, pluginArgs, errs)
if len(errs) > 0 {
log.Error().Errs("errs", errs).Msg("errors occurred loading plugins")
errs = []error{}