refactor: updated plugin implementations

This commit is contained in:
David Allen 2025-09-20 15:35:39 -06:00
parent 505dbefb67
commit 72c52fbac6
Signed by: towk
GPG key ID: 0430CDBE22619155
4 changed files with 27 additions and 79 deletions

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"git.towk2.me/towk/makeshift/internal/kwargs"
makeshift "git.towk2.me/towk/makeshift/pkg"
"git.towk2.me/towk/makeshift/pkg/storage"
jinja2 "github.com/kluctl/kluctl/lib/go-jinja2"
@ -42,6 +43,7 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
mappings struct {
Data map[string]any `json:"data"`
}
userdata *kwargs.KWArgs
profiles any // makeshift.ProfileMap
input any // []byte
output string
@ -54,11 +56,19 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
Int("arg_count", len(args)).
Msg("(pyjinja2) Run()")
// get profile data used as variable `{{ makeshift.profiles }}`
profiles, err = store.Get("profiles")
if err != nil {
return fmt.Errorf("(pyjinja2) failed to get profiles: %v", err)
}
// get userdata used as variable `{{ makeshift.userdata }}`
userdata, err = store.GetKWArgs()
if err != nil {
return fmt.Errorf("(pyjinja2) failed to get key-word arguments: %v", err)
}
// get file contents used for templating
input, err = store.Get("file")
if err != nil {
return fmt.Errorf("(pyjinja2) failed to get input data: %v", err)
@ -75,7 +85,7 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
}
}
// get mappings from provided profiles
// get mappings from provided profiles `{{ makeshift.plugin.*}}`
var ps = make(map[string]any)
for profileID, profile := range profiles.(makeshift.ProfileMap) {
ps[profileID] = map[string]any{
@ -89,6 +99,7 @@ func (p *Jinja2) Run(store storage.KVStore, args []string) error {
mappings.Data = map[string]any{
"makeshift": map[string]any{
"profiles": ps,
"userdata": userdata,
"plugin": map[string]any{
"name": p.Name(),
"version": p.Version(),