Skip to content

Instantly share code, notes, and snippets.

@raphink
Created May 28, 2018 08:34
Show Gist options
  • Save raphink/2c1e4a3dea54fbb871d42b04641dd393 to your computer and use it in GitHub Desktop.
Save raphink/2c1e4a3dea54fbb871d42b04641dd393 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"github.com/raphink/narcissus"
"honnef.co/go/augeas"
)
type OVHConfig struct {
Name string `yaml:"omitempty"`
ApplicationKey string `yaml:"application_key" path:"application_key"`
ApplicationSecret string `yaml:"application_secret" path:"application_secret"`
ConsumerKey string `yaml:"consumer_key" path:"consumer_key"`
}
type OVHConfigs struct {
augeasPath string
Configs map[string]OVHConfig `path:"section" purge:"false"`
}
func main() {
aug, err := augeas.New("/home/raphink/go/src/github.com/raphink/narcissus/examples/", "", augeas.None)
if err != nil {
log.Fatalf("Failed to create Augeas handler, %v", err)
}
err = aug.Transform("IniFile.lns_loose", "/ovh.conf", false)
if err != nil {
log.Fatalf("Failed to set up transform: %v", err)
}
err = aug.Load()
if err != nil {
log.Fatalf("Failed load Augeas tree: %v", err)
}
n := narcissus.New(&aug)
configs := OVHConfigs{
augeasPath: "/files/ovh.conf",
Configs: map[string]OVHConfig{
"ovh-eu": {
ApplicationKey: "abdfd",
ApplicationSecret: "duiozrkjlmds",
ConsumerKey: "zre24",
},
},
}
err = n.Write(&configs)
if err != nil {
log.Fatalf("Failed to write Augeas tree: %v", err)
}
aug.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment