55 Commits

Author SHA1 Message Date
mgoddard
bf76d1ed51 Solve issue with 'sslmode=verify-full' when there are multiple hosts 2021-06-19 10:14:17 -05:00
Jack Christensen
fb42201c18 Fix default host when parsing URL without host but with port
fixes https://github.com/jackc/pgconn/issues/72
2021-05-14 18:39:31 -05:00
Jack Christensen
3f76b98073 Allow dbname query parameter in URL conn string
fixes #69
2021-04-09 18:20:06 -05:00
Jack Christensen
cf5894e092 Use std errors instead of golang.org/x/xerrors
New error functionality was introduced in Go 1.13. pgconn only
officially supports 1.15+. Transitional xerrors package can now be
removed.
2021-03-06 14:45:33 -06:00
Jack Christensen
120139a206 Add link to PG docs for connString format
fixes #62
2021-01-14 18:22:21 -06:00
Moshe Katz
724bf94515 use proper pgpass location on Windows 2021-01-09 09:36:36 -06:00
Jack Christensen
be69c1c10b Fix parseDSNSettings with bad backslash
fixes #49
2020-09-10 19:40:52 -05:00
Jack Christensen
44079b0d2c Fix panic on parsing DSN with trailing '='
Also correctly return error with leading '='.

fixes #47
2020-07-29 22:11:15 -05:00
vahid-sohrabloo
271b0ac95e AppendCertsFromPEM doesn't have error and removes pgTLSArgs
AppendCertsFromPEM doesn't have error and removes pgTLSArgs because not used
2020-07-18 08:50:12 -05:00
Jack Christensen
65717779e4 Fix crash when PGSERVICE not found 2020-06-27 11:46:16 -05:00
Jack Christensen
473062b114 Remove NewConfig and add more docs for ParseConfig
refs #42
2020-06-27 11:29:21 -05:00
Jack Christensen
7cf5101bb2 Add NewConfig()
refs #42
2020-06-20 12:59:15 -05:00
Jack Christensen
a1b9eb4d4e Fix parseServiceSettings not returning error 2020-06-11 20:55:41 -05:00
Jack Christensen
6b254a445e Fix doc for ParseConfig 2020-06-11 20:51:40 -05:00
georgysavva
a6d9265506 Implement deep copy manually, stop using an external deep copy library. Add comment to the Config.Copy() method. 2020-06-01 20:52:08 +03:00
georgysavva
8d541d0004 Add Config.Copy() method that return a smart copy of the config. 2020-06-01 19:20:17 +03:00
Jack Christensen
18d2604119
Merge pull request #38 from lukedirtwalker/fixIPv6
Handle IPv6 in connection URLs
2020-05-13 08:50:38 -05:00
Lukas Vogel
08d071c094 Handle IPv6 in connection URLs
Previously IPv6 addresses were wrongly split and lead to a parse error.
This commit fixes the behavior.
2020-05-12 10:39:35 +02:00
georgysavva
391e1ef2ce Parse connect timeout setting into Config. Restrict context timeout via Config.ConnectTimeout on .Connect() call. 2020-05-02 16:35:22 +03:00
Petr Jediný
84aee0ab44 Fix behavior of sslmode=require with sslrootcert present
According to PostgreSQL documentation the behavior should be
the same as that of verify-ca sslmode

https://www.postgresql.org/docs/12/libpq-ssl.html
2020-04-08 00:08:53 +02:00
Greg Curtis
4ed48d05d2 Implement "verify-ca" SSL mode
ParseConfig currently treats the libpq "verify-ca" SSL mode as
"verify-full". This is okay from a security standpoint because
"verify-full" performs certificate verification and hostname
verification, whereas "verify-ca" only performs certificate
verification.

The downside to this approach is that checking the hostname is
unnecessary when the server's certificate has been signed by a private
CA. It can also cause the SSL handshake to fail when connecting to an
instance by IP. For example, a Google Cloud SQL instance typically
doesn't have a hostname and uses its own private CA to sign its
server and client certs.

This change uses the tls.Config.VerifyPeerCertificate function to
perform certificate verification without checking the hostname when the
"verify-ca" SSL mode is set. This brings pgconn's behavior closer to
that of libpq.

See https://github.com/golang/go/issues/21971#issuecomment-332693931
and https://pkg.go.dev/crypto/tls?tab=doc#example-Config-VerifyPeerCertificate
for more details on how this is implemented.
2020-03-17 23:36:06 -07:00
Jack Christensen
cfbd2519e3 Add PGSERVICE and PGSERVICEFILE support 2020-03-07 13:17:39 -06:00
Jack Christensen
8be01d690f Make Host comment more precise 2020-01-17 17:38:07 -06:00
Skip Gibson
81b6ad72f6 config: fix ValidateConnect comment 2019-10-16 10:01:16 +01:00
Jack Christensen
3f377acc1e
Merge pull request #14 from furdarius/resolve-hostnames-into-addrs
Validate all addresses resolved from hostname
2019-09-20 08:51:22 -05:00
Jack Christensen
99f22ac8e4 Port DSN parser from pgx v3
Original implementation: 2d9d8dc52ac211c6191c08e050c03588aa633038 by
Joshua Barone <joshua.barone@gmail.com>.

Also changed DSN tests to use "dbname" as key rather than "database" as
that is what the PostgreSQL documentation specifies. "database" still
actually works but it should not be encouraged as it is non-standard.
2019-09-14 18:37:33 -05:00
Artemiy Ryabinkov
b2ca5d8f52
validate all addresses resolved from hostname
Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
2019-09-13 17:26:09 +03:00
Jack Christensen
a8362ef96d Parse postgresql:// protocol 2019-09-10 17:14:04 -05:00
Jack Christensen
2fabfa3c18 Update to newest pgproto3 2019-08-31 15:44:54 -05:00
Jack Christensen
138254da5b Refactor errors
- Use strongly typed errors internally
- SafeToRetry(error) streamlines retry logic over ErrNoBytesSent
- Timeout(error) removes the need to choose between returning a context
  and an i/o error
2019-08-27 18:05:50 -05:00
Jack Christensen
e6cf51b304 Expose min_read_buffer_size config param 2019-08-25 00:22:32 -05:00
Jack Christensen
595d09d6f1 Build fully operational Frontend 2019-08-24 23:57:24 -05:00
Jack Christensen
797a44bf04 Rename BuildFrontendFunc to BuildFrontend
For consistency with other functions supplied in Config.
2019-08-24 16:18:04 -05:00
Jack Christensen
760dd75542 Require Config to be created by ParseConfig 2019-08-24 09:28:44 -05:00
Artemiy Ryabinkov
0a99b543c0
Add BuildFrontendFunc in Config
Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
2019-08-08 11:46:25 +03:00
Artemiy Ryabinkov
fa7e06489b
Add MinReadBufferSize option to Config
Signed-off-by: Artemiy Ryabinkov <getlag@ya.ru>
2019-07-26 11:14:07 +03:00
Jack Christensen
3dec184811 Split ValidateConnect from AfterConnect
This avoids the foot-gun of ParseConfig setting AfterConnect because of
target_session_attrs and the user inadvertently overriding it with an
AfterConnect designed to setup the connection.

Now target_session_attrs will be handled with ValidateConnect.
2019-07-13 10:22:09 -05:00
Jack Christensen
59941377c8 Rename Config.AfterConnectFunc to AfterConnect
No need to include the type in the name.
2019-07-13 09:52:22 -05:00
Jack Christensen
d2440c7fe6 Improve documentation 2019-06-22 16:54:10 -05:00
Jack Christensen
cd629965e6 Use golang.org/x/xerrors 2019-04-20 12:57:52 -05:00
Jack Christensen
444bd6deaf Context cancellation is fatal during query 2019-03-30 16:44:20 -05:00
Jack Christensen
fbdfccf1f9 Use Go modules 2019-03-30 12:55:56 -05:00
Jack Christensen
cd4b0025c3 Add listen/notify to pgconn 2019-01-14 20:39:10 -06:00
Jack Christensen
bd777fe20c Add custom context cancellation hook 2019-01-12 11:37:13 -06:00
Jack Christensen
406e95650a Add more docs 2019-01-05 18:40:33 -06:00
Jack Christensen
2c8971b382 Rename some types and methods 2019-01-05 18:01:57 -06:00
Jack Christensen
cddf011806 Big restructure to better handle context cancel 2019-01-05 17:37:28 -06:00
Jack Christensen
460946d662 Move notice handling to pgconn 2019-01-02 13:15:26 -06:00
Jack Christensen
4ee6fef452 Add context to potentially blocking methods 2018-12-31 17:17:11 -06:00
Jack Christensen
4e12c08b04 Use buffered exec 2018-12-31 14:14:40 -06:00