From d408893389098e23f9ec252ff24a07c53c8f595e Mon Sep 17 00:00:00 2001 From: David Allen Date: Fri, 5 Sep 2025 22:21:00 -0600 Subject: [PATCH] refactor: small changes and tweaks --- cmd/root.go | 9 +++++++++ pkg/service/routes.go | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index fb354f0..f5b1fc6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -118,3 +118,12 @@ func handleResponseError(res *http.Response, host, query string, err error) { os.Exit(1) } } + +// helper to write downloaded files +func writeFiles(path string, body []byte) { + var err = os.WriteFile(path, body, 0o755) + if err != nil { + log.Error().Err(err).Msg("failed to write file(s) from download") + os.Exit(1) + } +} diff --git a/pkg/service/routes.go b/pkg/service/routes.go index 1cbfc7f..e4fdb04 100644 --- a/pkg/service/routes.go +++ b/pkg/service/routes.go @@ -55,7 +55,7 @@ func (s *Service) Download() http.HandlerFunc { Msg("Service.Download()") // prepare profiles - errs = s.loadProfiles(profileIDs, store, errs) + errs = s.LoadProfiles(profileIDs, store, errs) if len(errs) > 0 { log.Error(). Errs("errs", errs). @@ -93,7 +93,7 @@ func (s *Service) Download() http.HandlerFunc { log.Debug().Strs("files", filenamesToArchive).Send() // prepare plugins - hooks, errs = s.loadPlugins(pluginNames, store, pluginArgs, errs) + hooks, errs = s.LoadPlugins(pluginNames, store, pluginArgs, errs) if len(errs) > 0 { log.Error(). Errs("errs", errs). @@ -143,7 +143,7 @@ func (s *Service) Download() http.HandlerFunc { // prepare plugins store.Set("file", contents) - 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). @@ -329,7 +329,7 @@ func (s *Service) GetStatus(w http.ResponseWriter, r *http.Request) { } } -func (s *Service) loadProfiles(profileIDs []string, store storage.KVStore, errs []error) []error { +func (s *Service) LoadProfiles(profileIDs []string, store storage.KVStore, errs []error) []error { // check for special case profile ID (e.g. '*' or 'all') useAll := slices.ContainsFunc(profileIDs, func(profileID string) bool { return profileID == "*" || profileID == "all" @@ -381,7 +381,7 @@ func (s *Service) loadProfiles(profileIDs []string, store storage.KVStore, errs return errs } -func (s *Service) loadPlugins(pluginNames []string, store storage.KVStore, args []string, errs []error) ([]makeshift.Hook, []error) { +func (s *Service) LoadPlugins(pluginNames []string, store storage.KVStore, args []string, errs []error) ([]makeshift.Hook, []error) { // create hooks to run from provided plugins specified var hooks []makeshift.Hook for i, pluginName := range pluginNames {