Created
January 15, 2018 17:00
-
-
Save tylerFowler/3bccf7181aa17be6748e66c9747cefd2 to your computer and use it in GitHub Desktop.
consul-template-certdump
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 ( | |
| "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