postgresClient passes an explicit conninfo to libpq: PGDATABASE alone does not expand a URI. Extract the database password so it stays off argv.
(name, conninfo string, args ...string)
| 11 | // postgresClient passes an explicit conninfo to libpq: PGDATABASE alone does |
| 12 | // not expand a URI. Extract the database password so it stays off argv. |
| 13 | func postgresClient(name, conninfo string, args ...string) (*exec.Cmd, error) { |
| 14 | dsn, password, err := postgresClientConninfo(conninfo) |
| 15 | if err != nil { |
| 16 | return nil, err |
| 17 | } |
| 18 | if password != nil && os.Getenv("PGSERVICE") != "" { |
| 19 | return nil, errors.New("configure the password in the PostgreSQL service instead of inline with PGSERVICE") |
| 20 | } |
| 21 | cmd := exec.Command(name, append(args, "--dbname", dsn)...) |
| 22 | cmd.Env = os.Environ() |
| 23 | if password != nil { |
| 24 | cmd.Env = append(cmd.Env, "PGPASSWORD="+*password) |
| 25 | } |
| 26 | return cmd, nil |
| 27 | } |
| 28 | |
| 29 | func postgresClientConninfo(raw string) (string, *string, error) { |
| 30 | invalid := errors.New("invalid PostgreSQL connection string") |