Compare commits

2 Commits

Author SHA1 Message Date
26d3d0faeb dir2config: support json output 2025-12-03 09:45:12 +01:00
834510760f add ${host_name} to CSRs 2025-10-11 09:21:33 +02:00
2 changed files with 17 additions and 4 deletions

View File

@ -1,10 +1,12 @@
package main
import (
"encoding/json"
"flag"
"io/fs"
"log"
"os"
"path"
"path/filepath"
"github.com/go-git/go-git/v5"
@ -127,12 +129,22 @@ func main() {
defer out.Close()
switch ext := path.Ext(*outPath); ext {
case ".yaml":
out.Write([]byte("# dkl-dir2config " + Version + "\n"))
if err = yaml.NewEncoder(out).Encode(dst); err != nil {
log.Fatal("failed to render output: ", err)
}
case ".json":
if err = json.NewEncoder(out).Encode(dst); err != nil {
log.Fatal("failed to render output: ", err)
}
default:
log.Fatal("unknown output file extension: ", ext)
}
}
func cfgPath(subPath string) string { return filepath.Join(*dir, subPath) }

View File

@ -202,6 +202,7 @@ func (ctx *renderContext) TemplateFuncs() map[string]any {
}
reqJson = strings.ReplaceAll(reqJson, "${host_ip}", ctx.Host.IPs[0])
reqJson = strings.ReplaceAll(reqJson, "${host_name}", ctx.Host.Name)
kc, err := getKeyCert(cluster, caName, name, profile, label, reqJson)
if err != nil {