[management,misc] Fix configuration migration checks

The initial migration let an empty legacy Datadir override Management defaults and pulled Viper into WASM builds through the common util package.

Normalize the Management data directory, isolate template expansion from the loader dependency, and split source binding to satisfy the quality gate.
This commit is contained in:
jnfrati
2026-08-25 11:03:33 +02:00
parent 9bb006a3d7
commit 0646d8fc78
6 changed files with 132 additions and 67 deletions
+35
View File
@@ -0,0 +1,35 @@
// Package envtemplate expands Go templates with environment variables.
package envtemplate
import (
"bytes"
"fmt"
"os"
"strings"
"text/template"
)
// Expand substitutes Go-template references with environment values.
func Expand(data []byte) ([]byte, error) {
tmpl, err := template.New("config").Parse(string(data))
if err != nil {
return nil, fmt.Errorf("parse environment template: %w", err)
}
var output bytes.Buffer
if err := tmpl.Execute(&output, environment()); err != nil {
return nil, fmt.Errorf("execute environment template: %w", err)
}
return output.Bytes(), nil
}
func environment() map[string]string {
values := make(map[string]string)
for _, entry := range os.Environ() {
key, value, ok := strings.Cut(entry, "=")
if ok {
values[key] = value
}
}
return values
}