From 56e4e4218ad5e836f2f39344e60e820c73c5e47f Mon Sep 17 00:00:00 2001 From: Shteryana Shopova Date: Sat, 20 Jul 2019 22:04:12 +0300 Subject: [PATCH] Custom output directory --- access/fetch-keys/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/access/fetch-keys/main.go b/access/fetch-keys/main.go index eaff0f3..847d7c1 100644 --- a/access/fetch-keys/main.go +++ b/access/fetch-keys/main.go @@ -27,6 +27,7 @@ func main() { ghOrganization := parser.String("o", "org", &argparse.Options{Required: false, Help: "Github Organization name", Default: "OpenFest"}) authToken := parser.String("a", "authtoken", &argparse.Options{Required: false, Help: "Github Auth token", Default: AuthToken}) quiet := parser.Flag("q", "quiet", &argparse.Options{Required: false, Help: "Skip output to stdout", Default: false}) + keysDir := parser.String("d", "directory", &argparse.Options{Required: false, Help: "Path where to store the key files", Default: "./"}) // Parse input err := parser.Parse(os.Args) @@ -35,6 +36,17 @@ func main() { os.Exit(1) } + fi, err := os.Lstat(*keysDir) + if err != nil { + fmt.Println(*keysDir, ": target directory error :", err) + os.Exit(1) + } else { + if fi.Mode().IsDir() == false { + fmt.Println(*keysDir, ": target directory error : not a directory - ", fi.Mode()) + os.Exit(1) + } + } + ctx := context.Background() ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: *authToken}, @@ -141,7 +153,8 @@ func main() { nextPage = rsp.NextPage } - err := ioutil.WriteFile(*user+".key", sshKeys.Bytes(), 0444) + fmt.Println("Writing to", *keysDir + *user+".key") + err := ioutil.WriteFile(*keysDir + "/" + *user+".key", sshKeys.Bytes(), 0444) if err != nil { fmt.Errorf(*user+".key error %v", err) }