support for file's content64 (compat mode)

This commit is contained in:
Mikaël Cluseau
2026-01-25 20:55:15 +01:00
parent 183099f7da
commit ca436ed246
3 changed files with 24 additions and 3 deletions

View File

@ -32,6 +32,8 @@ import (
var cmdlineParam = restful.QueryParameter("cmdline", "Linux kernel cmdline addition")
var b64 = base64.StdEncoding.WithPadding(base64.NoPadding)
type renderContext struct {
Host *localconfig.Host
SSLConfig *cfsslconfig.Config
@ -102,11 +104,29 @@ func (ctx *renderContext) Config() (ba []byte, cfg *config.Config, err error) {
return
}
// log.Print("rendered config:\n", string(ba))
cfg = &config.Config{}
if err = yaml.Unmarshal(ba, cfg); err != nil {
return
}
// compatibility post-processing: decode all base64 content
for i := range cfg.Files {
file := &cfg.Files[i]
if file.Content64 != "" {
decoded, decodeErr := b64.DecodeString(file.Content64)
if decodeErr != nil {
err = fmt.Errorf("failed to decode file %s: %w", file.Path, decodeErr)
return
}
file.Content = string(decoded)
file.Content64 = ""
}
}
return
}
@ -189,6 +209,7 @@ func (ctx *renderContext) TemplateFuncs() map[string]any {
enc := base64.StdEncoding.WithPadding(base64.NoPadding)
return enc.EncodeToString([]byte(input))
},
"host_ip": func() (s string) {
return ctx.Host.IPs[0]
},