refactor: small changes and tweaks
This commit is contained in:
parent
568d3e21a6
commit
d408893389
2 changed files with 14 additions and 5 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue