Created
May 28, 2018 08:34
-
-
Save raphink/2c1e4a3dea54fbb871d42b04641dd393 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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