2020-05-25 22:15:11 +02:00
|
|
|
// Copyright (c) 2017 The Namecoin developers
|
|
|
|
// Copyright (c) 2019 The btcsuite developers
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package rpcclient
|
|
|
|
|
|
|
|
import (
|
2019-10-11 00:59:50 +02:00
|
|
|
"bufio"
|
2020-05-25 22:15:11 +02:00
|
|
|
"fmt"
|
2019-10-11 00:59:50 +02:00
|
|
|
"os"
|
2020-05-25 22:15:11 +02:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func readCookieFile(path string) (username, password string, err error) {
|
2019-10-11 00:59:50 +02:00
|
|
|
f, err := os.Open(path)
|
2020-05-25 22:15:11 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2019-10-11 00:59:50 +02:00
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(f)
|
|
|
|
scanner.Scan()
|
|
|
|
err = scanner.Err()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s := scanner.Text()
|
2020-05-25 22:15:11 +02:00
|
|
|
|
|
|
|
parts := strings.SplitN(s, ":", 2)
|
|
|
|
if len(parts) != 2 {
|
|
|
|
err = fmt.Errorf("malformed cookie file")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
username, password = parts[0], parts[1]
|
|
|
|
return
|
|
|
|
}
|