Exemplo n.º 1
0
func lookup(name string) {
	user, err := api.LookupUser(name)
	if err != nil {
		fmt.Printf("Lookup failed: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Details for user %s:\n", user.Basics.Username)
	fmt.Printf("\tCreated: %s\n", unixToString(user.Basics.Created))
	fmt.Printf("\tLast modified: %s\n", unixToString(user.Basics.Modified))
	fmt.Printf("\tProfile:\n")
	fmt.Printf("\t\tLast updated: %s\n", unixToString(user.Profile.Modified))
	fmt.Printf("\t\tFull name: %s\n", user.Profile.FullName)
	fmt.Printf("\t\tLocation: %s\n", user.Profile.Location)
	fmt.Printf("\t\tBio:\n")
	fmt.Printf("\t\t\t%s\n", user.Profile.Bio) // TODO(kyle): wordwrap bio

	if pub, ok := user.PublicKeys["primary"]; ok {
		fmt.Printf("\tPublic key\n")
		fmt.Printf("\t\tKey ID: %s\n", pub.KeyID)
		fmt.Printf("\t\tCreated: %s\n", unixToString(pub.Created))
		fmt.Printf("\t\tLast modified: %s\n", unixToString(pub.Modified))
	} else {
		fmt.Printf("\tNo public key.\n")
	}

}
Exemplo n.º 2
0
func fetchKey(name, outFile string) {
	user, err := api.LookupUser(name)
	if err != nil {
		fmt.Printf("Fetch failed: %v\n", err)
		os.Exit(1)
	}

	pub, ok := user.PublicKeys["primary"]
	if !ok || pub.Bundle == "" {
		fmt.Printf("%s hasn't uploaded a public key yet.")
		os.Exit(1)
	}

	if outFile != "-" {
		err = ioutil.WriteFile(outFile, []byte(pub.Bundle+"\n"), 0644)
		if err != nil {
			fmt.Printf("Couldn't write %s's public key to disk: %v\n", user.Basics.Username, err)
		} else {
			fmt.Printf("Wrote %s's public key to %s.\n'", user.Basics.Username, outFile)
		}
	} else {
		fmt.Fprintf(os.Stdout, "%s\n", pub.Bundle)
	}
}