func main() { if pw, err := keyring.Get("keyring_example", "jack"); err == nil { fmt.Println("current stored password:"******"no password stored yet") } else { fmt.Println("got unexpected error:", err) os.Exit(1) } pw, err := gopass.GetPass("enter new password: "******"setting keyring_example/jack to..", pw) err = keyring.Set("keyring_example", "jack", pw) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println("fetching keyring_example/jack..") if pw, err := keyring.Get("keyring_example", "jack"); err == nil { fmt.Println("got", pw) } else { fmt.Println("error:", err) } }
// GetPassphrase attemps to retrieve the user's gpg master // key passphrase using multiple methods. First it will attempt // to retrieve it from the environment, then it will try to fetch // it from the system keyring manager, ultimately it will try // to get it from a running gpg-agent daemon. func GetPassphrase() (passphrase string) { var err error // try to retrieve passphrase from env passphrase = os.Getenv(ENV_PASSPHRASE_KEY) if len(passphrase) > 0 { return passphrase } // if passphrase wasn't found in env, try to fetch it from // system keyring manager. passphrase, err = keyring.Get(os.Getenv(ENV_KEYRING_SERVICE_KEY), os.Getenv(ENV_KEYRING_USER_KEY)) if len(passphrase) > 0 { return passphrase } // if passphrase was enither found in the environment nor // system keyring manager try to fetch it from gpg-agent if os.Getenv("gpg_agent_info") != "" { passphrase, err = getGpgPassphrase(os.Getenv(ENV_MASTER_GPG_ID_KEY)) } if err != nil { ErrorLogger.Fatal("no passphrase provided. unable to open data store") } return passphrase }
// GetPassphrase attemps to retrieve the user's gpg master // key passphrase using multiple methods. First it will attempt // to retrieve it from the environment, then it will try to fetch // it from the system keyring manager, ultimately it will try // to get it from a running gpg-agent daemon. func GetPassphrase() string { var passphrase string var err error // Try to retrieve passphrase from env passphrase = os.Getenv(ENV_PASSPHRASE_KEY) if len(passphrase) > 0 { return passphrase } // If passphrase wasn't found in env, try to fetch it from // system keyring manager. passphrase, _ = keyring.Get(gKeyringService, gKeyringUser) if len(passphrase) > 0 { return passphrase } // If passphrase was enither found in the environment nor // system keyring manager try to fetch it from gpg-agent if os.Getenv("GPG_AGENT_INFO") != "" { passphrase, err = GetGpgPassphrase(gMasterGpgId) if err != nil { log.Fatal(err) } } return passphrase }
func ExampleGet() { keyring.Set("keyring-test", "jack", "test password") pw, _ := keyring.Get("keyring-test", "jack") fmt.Println("pw:", pw) // don't ignore errors like this in your code // Output: // pw: test password }
func get_value(service, path string) string { if value, err := keyring.Get(service, path); err == nil { return value } else { fmt.Println("error:", err) os.Exit(1) } return "" }
func Password(data Info) (pass string) { if data.Auth == "open" && data.LinkAuth == "none" { } else { password, err := keyring.Get("AirPort", data.Ssid) if err == nil { pass = password } else { log.Fatal(err) } } return }
func main() { args := os.Args[1:] if len(args) < 1 { fmt.Fprintf(os.Stderr, "No variable was provided.") os.Exit(1) } variable := os.Args[1] if pw, err := keyring.Get("summon", variable); err == nil { os.Stdout.WriteString(pw) } else if err == keyring.ErrNotFound { fmt.Fprintf(os.Stderr, "%s could not be retrieved", variable) } else { fmt.Fprintf(os.Stderr, "error:", err) os.Exit(1) } }