pgdsn

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pgdsn reads PostgreSQL connection strings (DSNs) the way the driver does, to keep their secrets out of places they must not reach: Redact for `sqi-server config print`, and WithoutPassword for a pg_dump command line, which any local user can read from the process list.

It imports only the standard library, so any package can use it. The keyword/value tokenizer mirrors pgx's (and libpq's), because a regular expression cannot: see [parseKeywordValueDSN]. A URL-form DSN is checked for every way Go's url.Parse and the driver's libpq-style parser can disagree (see [urlDSNAmbiguous]), and refused where they can.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redact

func Redact(dsn string) string

Redact returns dsn with its password (and sslpassword, the client key's passphrase) replaced by a placeholder, in either DSN form. A DSN without a password is returned unchanged.

The form is chosen as pgx chooses it: a DSN is a URL only when it starts with exactly "postgres://" or "postgresql://", and anything else is keyword/value.

It fails closed. A URL-form DSN whose password cannot be reliably located, because url.Parse refuses it or because [urlDSNAmbiguous] says that Go's reading of it and the PostgreSQL driver's can differ, is reduced to its scheme and a placeholder. A keyword/value DSN is tokenized as pgx tokenizes it (see [parseKeywordValueDSN]); one it cannot tokenize is reduced to the placeholder alone. A keyword/value DSN that does carry a password is rebuilt from its pairs, so its spacing and quoting may change, but pgx reads every other setting back exactly as before.

func SetsSSLPassword

func SetsSSLPassword(dsn string) bool

SetsSSLPassword reports whether dsn sets a non-empty sslpassword, the client key's passphrase, or cannot be read reliably enough to tell (see WithoutPassword), so a caller with no safe way to pass one on can refuse.

func WithoutPassword

func WithoutPassword(dsn string) (rest string, ok bool)

WithoutPassword returns dsn with its password and sslpassword removed, for a place the DSN can be seen but its secrets must not be: a pg_dump command line. It reads dsn exactly as Redact does, and refuses (rest "", ok false) wherever Redact fails closed: a URL-form DSN that url.Parse refuses or that [urlDSNAmbiguous] says the driver may read differently, and a keyword/value DSN that [parseKeywordValueDSN] cannot tokenize.

A URL-form DSN keeps every byte but those removed: the password of the userinfo (with its ":"; with the "@" too when no user name is left), and every query pair whose key is password or sslpassword in any case. A keyword/value DSN with no such key is returned as it came; otherwise it is rebuilt from its other pairs, as Redact rebuilds it. Either way pgx (and libpq, whose parsers pgx's mirror) reads back every other setting as before.

An upper-case PASSWORD key goes too: pgx sends it to the server as a runtime parameter and libpq rejects it, and it is most likely a password either way.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL