Skip to content

Commit

Permalink
enable users to connect without specifying password
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsteinsland committed Mar 17, 2022
1 parent 89a232b commit 268fb16
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/root/postgres/psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ var psqlCmd = &cobra.Command{
"--dbname", connectionInfo.dbName,
}

pgpass := []byte(fmt.Sprintf("localhost:5432:%s:%s:%s", connectionInfo.dbName, email, token))
if err := os.WriteFile("~/.pgpass", pgpass, 0600); err != nil {
log.Println("Failed to write contents to pgpass file")
} else {
log.Printf("You can authenticate using 'pgpass' method: log in using only <%s> as username\n", email)
}

cmd := exec.CommandContext(ctx, psqlPath, arguments...)
cmd.Env = append(cmd.Env, fmt.Sprintf("PGPASSWORD=%s", token))

Expand Down

0 comments on commit 268fb16

Please sign in to comment.