MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / postgresClient

Function postgresClient

cmd/pad/postgres_client.go:13–27  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
13func 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
29func postgresClientConninfo(raw string) (string, *string, error) {
30 invalid := errors.New("invalid PostgreSQL connection string")

Callers 3

dumpPostgresFunction · 0.85
dbRestoreCmdFunction · 0.85

Calls 2

postgresClientConninfoFunction · 0.85
appendFunction · 0.85

Tested by 1