refactor: update pyjinja2 implementation

This commit is contained in:
David Allen 2025-09-04 10:08:40 -06:00
parent 62b58f4cbb
commit 23d43061fb
Signed by: towk
GPG key ID: 793B2924A49B3A3F

View file

@ -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)