quick ugly fix

This commit is contained in:
Mikaël Cluseau 2019-01-21 16:53:45 +13:00
parent bd5baf5a23
commit c8551eac5b
3 changed files with 21 additions and 6 deletions

View File

@ -14,15 +14,13 @@ import (
) )
var ( var (
dir = flag.String("in", ".", "Source directory")
src *clustersconfig.Config src *clustersconfig.Config
dst *localconfig.Config dst *localconfig.Config
) )
func main() { func loadSrc() {
dir := flag.String("in", ".", "Source directory")
outPath := flag.String("out", "config.yaml", "Output file")
flag.Parse()
var err error var err error
src, err = clustersconfig.FromDir(*dir) src, err = clustersconfig.FromDir(*dir)
@ -30,6 +28,14 @@ func main() {
log.Fatal("failed to load config from dir: ", err) log.Fatal("failed to load config from dir: ", err)
} }
}
func main() {
outPath := flag.String("out", "config.yaml", "Output file")
flag.Parse()
loadSrc()
dst = &localconfig.Config{ dst = &localconfig.Config{
SSLConfig: src.SSLConfig, SSLConfig: src.SSLConfig,
} }
@ -44,7 +50,11 @@ func main() {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
for _, host := range src.Hosts { for _, host := range src.Hosts {
loadSrc() // FIXME ugly fix of some template caching or something
log.Print("rendering host ", host.Name)
ctx, err := newRenderContext(host, src) ctx, err := newRenderContext(host, src)
log.Printf(" ctx: %p", ctx)
if err != nil { if err != nil {
log.Fatal("failed to create render context for host ", host.Name, ": ", err) log.Fatal("failed to create render context for host ", host.Name, ": ", err)

View File

@ -23,6 +23,7 @@ type renderContext struct {
func newRenderContext(host *clustersconfig.Host, cfg *clustersconfig.Config) (ctx *renderContext, err error) { func newRenderContext(host *clustersconfig.Host, cfg *clustersconfig.Config) (ctx *renderContext, err error) {
cluster := cfg.Cluster(host.Cluster) cluster := cfg.Cluster(host.Cluster)
log.Printf("===> newRenderContext: cluster: %v", cluster.Name)
if cluster == nil { if cluster == nil {
err = fmt.Errorf("no cluster named %q", host.Cluster) err = fmt.Errorf("no cluster named %q", host.Cluster)
return return
@ -68,6 +69,7 @@ func (ctx *renderContext) Config() string {
templateFuncs := ctx.templateFuncs(ctxMap) templateFuncs := ctx.templateFuncs(ctxMap)
render := func(what string, t *clustersconfig.Template) (s string, err error) { render := func(what string, t *clustersconfig.Template) (s string, err error) {
log.Printf("render %q %p", what, t)
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
err = t.Execute(buf, ctxMap, templateFuncs) err = t.Execute(buf, ctxMap, templateFuncs)
if err != nil { if err != nil {
@ -118,6 +120,8 @@ func (ctx *renderContext) templateFuncs(ctxMap map[string]interface{}) map[strin
cluster := ctx.Cluster.Name cluster := ctx.Cluster.Name
getKeyCert := func(name, funcName string) (s string, err error) { getKeyCert := func(name, funcName string) (s string, err error) {
log.Print("=====> getKeyCert ", funcName, ": cluster: ", cluster)
req := ctx.clusterConfig.CSR(name) req := ctx.clusterConfig.CSR(name)
if req == nil { if req == nil {
err = fmt.Errorf("no certificate request named %q", name) err = fmt.Errorf("no certificate request named %q", name)
@ -169,6 +173,7 @@ func (ctx *renderContext) templateFuncs(ctxMap map[string]interface{}) map[strin
}, },
"tls_dir": func(name string) (s string, err error) { "tls_dir": func(name string) (s string, err error) {
log.Printf("CTX: %p", ctx)
return getKeyCert(name, "tls_dir") return getKeyCert(name, "tls_dir")
}, },

View File

@ -3,5 +3,5 @@
prep: go install ./cmd/... prep: go install ./cmd/...
#prep: go install ./cmd/dkl-local-server #prep: go install ./cmd/dkl-local-server
#prep: docker build -t dls . #prep: docker build -t dls .
daemon +sigterm: /var/lib/direktil/test-run #daemon +sigterm: /var/lib/direktil/test-run
} }