Merge key fetcher #6

Merged
zeridon merged 15 commits from master into master 2019-07-29 14:19:52 +03:00
1 changed files with 17 additions and 14 deletions
Showing only changes of commit 61b73ceece - Show all commits

View File

@ -29,6 +29,7 @@ func main() {
fetchPgp := parser.Flag("p", "pgp-keys", &argparse.Options{Required: false, Help: "Fetch configured PGP key ids", Default: false}) fetchPgp := parser.Flag("p", "pgp-keys", &argparse.Options{Required: false, Help: "Fetch configured PGP key ids", Default: false})
quiet := parser.Flag("q", "quiet", &argparse.Options{Required: false, Help: "Skip output to stdout", Default: false}) quiet := parser.Flag("q", "quiet", &argparse.Options{Required: false, Help: "Skip output to stdout", Default: false})
ghTeam := parser.String("t", "team", &argparse.Options{Required: false, Help: "Github Team name, 'all' for all members of the organization", Default: "NOC"}) ghTeam := parser.String("t", "team", &argparse.Options{Required: false, Help: "Github Team name, 'all' for all members of the organization", Default: "NOC"})
verbose := parser.Flag("v", "verbose", &argparse.Options{Required: false, Help: "Verbose output: print keys to stdout", Default: false})
// Parse input // Parse input
err := parser.Parse(os.Args) err := parser.Parse(os.Args)
@ -37,6 +38,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if *verbose == false {
fi, err := os.Lstat(*keysDir) fi, err := os.Lstat(*keysDir)
if err != nil { if err != nil {
fmt.Println(*keysDir, ": target directory error :", err) fmt.Println(*keysDir, ": target directory error :", err)
@ -47,6 +49,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
} }
}
ctx := context.Background() ctx := context.Background()
ts := oauth2.StaticTokenSource( ts := oauth2.StaticTokenSource(
@ -80,7 +83,7 @@ func main() {
} }
for _, key := range keys { for _, key := range keys {
if *quiet == false { if *verbose == true {
fmt.Println(*key.Key) fmt.Println(*key.Key)
} }
sshKeys.WriteString(*key.Key) sshKeys.WriteString(*key.Key)
@ -93,11 +96,11 @@ func main() {
nextPage = rsp.NextPage nextPage = rsp.NextPage
} }
if *quiet == false { if *quiet == false && *verbose == false {
fmt.Println("Writing to", *keysDir+"/"+*user+".key") fmt.Println("Writing to", *keysDir+"/"+*user+".key")
} }
err := ioutil.WriteFile(*keysDir+"/"+*user+".key", sshKeys.Bytes(), 0444) err := ioutil.WriteFile(*keysDir+"/"+*user+".key", sshKeys.Bytes(), 0444)
if err != nil { if err != nil && *verbose == false {
fmt.Println(*user+".key error ", err) fmt.Println(*user+".key error ", err)
} }
@ -118,7 +121,7 @@ func main() {
} }
for _, key := range keys { for _, key := range keys {
if *quiet == false { if *verbose == true {
fmt.Println(*key.KeyID) fmt.Println(*key.KeyID)
} }
pgpKeys.WriteString(*key.KeyID) pgpKeys.WriteString(*key.KeyID)
@ -130,11 +133,11 @@ func main() {
} }
nextPage = rsp.NextPage nextPage = rsp.NextPage
} }
if *quiet == false { if *quiet == false && *verbose == false {
fmt.Println("Writing to", *keysDir+"/"+*user+".gpg") fmt.Println("Writing to", *keysDir+"/"+*user+".gpg")
} }
err = ioutil.WriteFile(*keysDir+"/"+*user+".gpg", pgpKeys.Bytes(), 0444) err = ioutil.WriteFile(*keysDir+"/"+*user+".gpg", pgpKeys.Bytes(), 0444)
if err != nil { if err != nil && *verbose == false {
fmt.Println(*user+".gpg error ", err) fmt.Println(*user+".gpg error ", err)
} }
} }