Commits

Fazlul Shahriar committed 2bffb23

detach GetUserPassword from RPC type

Makes common use case shorter.

  • Participants
  • Parent commits adf615b

Comments (0)

Files changed (2)

 // GetUserPassword returns the username and password for the key
 // formatted using format and a. GetKey is called to obtain missing
 // information (if any).
-func (rpc *RPC) GetUserPassword(getKey GetKeyFunc, format string, a ...interface{}) (string, string, error) {
+func GetUserPassword(getKey GetKeyFunc, format string, a ...interface{}) (string, string, error) {
+	rpc, err := NewRPC()
+	if err != nil {
+		return "", "", err
+	}
+	defer rpc.Close()
 	status, b, err := rpc.callNeedKey(getKey, "start", []byte(fmt.Sprintf(format, a...)))
 	if status != "ok" {
 		return "", "", fmt.Errorf("rpc start failed: %v", err)
 		t.Fatalf("AddKey failed: %v\n", err)
 	}
 
-	rpc, err := NewRPC()
-	if err != nil {
-		t.Fatalf("open factotum/rpc: %v\n", err)
-	}
-	defer rpc.Close()
-	user1, pass1, err := rpc.GetUserPassword(nil, params)
+	user1, pass1, err := GetUserPassword(nil, params)
 	if err != nil {
 		t.Errorf("GetUserPassword failed: %v\n", err)
 	}