Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
certdump consul-template plugin for writing vault-generated certificates to separate files
package main
import (
"io/ioutil"
"log"
"os"
"os/user"
"strconv"
)
func main() {
err := realMain()
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}
func realMain() error {
if len(os.Args) != 4 {
// Ensure the empty input case is handled correctly
return nil
}
// certdump <filepath> <owner> <data>
path := os.Args[1]
owner := os.Args[2]
data := os.Args[3]
err := ioutil.WriteFile(path, []byte(data), 0700)
if err != nil {
return err
}
u, err := user.Lookup(owner)
if err != nil {
return err
}
uid, err := strconv.Atoi(u.Uid)
if err != nil {
return err
}
gid := os.Getgid()
err = os.Chmod(path, 0660)
if err != nil {
return err
}
err = os.Chown(path, uid, gid)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.