use secure cockroach connection

This commit is contained in:
Seán C McCord 2018-07-18 01:24:06 -04:00
parent 0583c66d96
commit 4004c1a00d

View file

@ -20,13 +20,18 @@ func Connect() error {
} }
var username = "nobody" var username = "nobody"
var password string
u, err := user.Current() u, err := user.Current()
if err == nil { if err == nil {
username = u.Username username = u.Username
} }
if os.Getenv("COCKROACH_USER") != "" {
username = os.Getenv("COCKROACH_USER")
password = os.Getenv("COCKROACH_PASS")
}
dsn := fmt.Sprintf("postgresql://%s@localhost:26257/cycore?sslmode=disable", username) dsn := fmt.Sprintf("postgresql://%s:%s@localhost:26257/cycore?sslmode=require", username, password)
if os.Getenv("DSN") != "" { if os.Getenv("DSN") != "" {
dsn = os.Getenv("DSN") dsn = os.Getenv("DSN")
} }