Compare commits
3 commits
2eee847205
...
23d43061fb
| Author | SHA1 | Date | |
|---|---|---|---|
| 23d43061fb | |||
| 62b58f4cbb | |||
| 215dbe8eff |
4 changed files with 38 additions and 9 deletions
|
|
@ -75,6 +75,7 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
// get mappings from provided profiles
|
||||
var ps = make(map[string]any)
|
||||
for profileID, profile := range profiles.(makeshift.ProfileMap) {
|
||||
ps[profileID] = map[string]any{
|
||||
|
|
@ -84,8 +85,9 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
j2, err := jinja2.NewJinja2("pyjinja", 1,
|
||||
jinja2.WithGlobal("makeshift", map[string]any{
|
||||
// get mappings supplied by this plugin
|
||||
mappings.Data = map[string]any{
|
||||
"makeshift": map[string]any{
|
||||
"profiles": ps,
|
||||
"plugin": map[string]any{
|
||||
"name": p.Name(),
|
||||
|
|
@ -93,7 +95,11 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
|
|||
"description": p.Description(),
|
||||
"metadata": p.Metadata(),
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
j2, err := jinja2.NewJinja2("makeshift", 1,
|
||||
jinja2.WithGlobals(mappings.Data),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("(pyjinja2) failed to create new Jinja 2 instance: %v", err)
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ const (
|
|||
Name: {{ makeshift.plugin.name }}
|
||||
Version: {{ makeshift.plugin.version }}
|
||||
Description: {{ makeshift.plugin.description }}
|
||||
Author: {{ makeshift.plugin.metadata.name }} ({{ makeshift.plugin.metadata.email }})
|
||||
|
||||
Author: {{ makeshift.plugin.metadata }}
|
||||
Profile Information:
|
||||
ID: {{ makeshift.profiles.default.id }}
|
||||
Description: {{ makeshift.profiles.default.description }}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"git.towk2.me/towk/makeshift/internal/kwargs"
|
||||
makeshift "git.towk2.me/towk/makeshift/pkg"
|
||||
"git.towk2.me/towk/makeshift/pkg/storage"
|
||||
"git.towk2.me/towk/makeshift/pkg/util"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
|
@ -56,7 +57,11 @@ func (s *Service) Download() http.HandlerFunc {
|
|||
// prepare profiles
|
||||
errs = s.loadProfiles(profileIDs, store, errs)
|
||||
if len(errs) > 0 {
|
||||
log.Error().Errs("errs", errs).Msg("errors occurred loading profiles")
|
||||
log.Error().
|
||||
Errs("errs", errs).
|
||||
Msg("errors occurred loading profiles")
|
||||
err = util.FormatErrors("failed to load plugins", "", errs)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
errs = []error{}
|
||||
}
|
||||
|
||||
|
|
@ -90,8 +95,13 @@ func (s *Service) Download() http.HandlerFunc {
|
|||
// prepare plugins
|
||||
hooks, errs = s.loadPlugins(pluginNames, store, pluginArgs, errs)
|
||||
if len(errs) > 0 {
|
||||
log.Error().Errs("errs", errs).Msg("errors occurred loading plugins")
|
||||
log.Error().
|
||||
Errs("errs", errs).
|
||||
Msg("errors occurred loading plugins")
|
||||
err = util.FormatErrors("failed to load plugins", "", errs)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
errs = []error{}
|
||||
return
|
||||
}
|
||||
|
||||
// create an archive of the directory, run hooks, and download
|
||||
|
|
@ -132,12 +142,16 @@ func (s *Service) Download() http.HandlerFunc {
|
|||
}
|
||||
|
||||
// prepare plugins
|
||||
|
||||
store.Set("file", contents)
|
||||
hooks, errs = s.loadPlugins(pluginNames, store, nil, errs)
|
||||
if len(errs) > 0 {
|
||||
log.Error().Errs("errs", errs).Msg("errors occurred loading plugins")
|
||||
log.Error().
|
||||
Errs("errs", errs).
|
||||
Msg("errors occurred loading plugins")
|
||||
err = util.FormatErrors("failed to load plugins", "", errs)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
errs = []error{}
|
||||
return
|
||||
}
|
||||
if len(hooks) > 0 {
|
||||
// run pre-hooks to modify the contents of the file before archiving
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"cmp"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -97,3 +98,12 @@ func CopyIf[T comparable](s []T, condition func(t T) bool) []T {
|
|||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func FormatErrors(message string, prefix string, errs []error) error {
|
||||
var errMessage = prefix + message + "\n"
|
||||
for _, err := range errs {
|
||||
errMessage = fmt.Sprintf("%s %v\n", prefix, err)
|
||||
}
|
||||
|
||||
return errors.New(errMessage)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue