Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
danielingegneri committed Apr 1, 2021
1 parent d0a7363 commit 186f9f6
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"git.jcu.edu.au/cft/cfds/crypt"
"git.jcu.edu.au/cft/cfds/datasources"
"gopkg.in/yaml.v2"
Expand All @@ -15,6 +16,7 @@ import (
func main() {
seed := flag.String("seed", "", "Seed from seed.properties. 16 chars")
input := flag.String("input", "datasources.yml", "Input yaml data sources")
output := flag.String("output", "neo-datasource.xml", "Output XML file")
templateDir := "templates"
flag.Parse()
if *seed == "" || *input == "" {
Expand All @@ -24,15 +26,28 @@ func main() {
if err != nil {
panic(err)
}
defer inFile.Close()
d := yaml.NewDecoder(inFile)
doc := datasources.NewDoc()
err = d.Decode(doc)
_ = inFile.Close()

templates := map[string]*template.Template{}
if err != nil {
panic("Error reading datasource file " + err.Error())
}

start := "<wddxPacket version='1.0'><header/><data><array length='2'><struct type='coldfusion.server.ConfigMap'>"
end := "</struct><struct type='coldfusion.server.ConfigMap'><var name='maxcachecount'><number>100.0</number></var></struct></array></data></wddxPacket>"

outFile, err := os.Create(*output)
if err != nil {
panic(err)
}
defer outFile.Close()

templates := map[string]*template.Template{}

if _, err = outFile.WriteString(start); err != nil {
panic(err)
}
for ds, data := range doc.Datasources {
data.Name = ds
data.Password, err = crypt.Encrypt(data.Password, *seed)
Expand All @@ -52,11 +67,13 @@ func main() {
panic(err)
}
}
err = templates[key].Execute(os.Stdout, data)
err = templates[key].Execute(outFile, data)
if err != nil {
panic(err)
}
}

//tmpl := template.New("ds")
if _, err = outFile.WriteString(end); err != nil {
panic(err)
}
fmt.Printf("Wrote %d datasources\n", len(doc.Datasources))
}

0 comments on commit 186f9f6

Please sign in to comment.