Created
September 1, 2016 19:02
-
-
Save tam7t/1b45125ae4de13b3fc6fd0455954c08e to your computer and use it in GitHub Desktop.
certdump consul-template plugin for writing vault-generated certificates to separate files
This file contains 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 ( | |
"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