Skip to content

Commit

Permalink
Merge branch 'master' into pgbouncer-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn committed Jan 15, 2021
2 parents 87316f0 + 096f4f5 commit 7d3753e
Show file tree
Hide file tree
Showing 68 changed files with 1,393 additions and 751 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ version: 2
jobs:
build:
docker:
- image: rust:1.41.0
- image: rust:1.45.0
environment:
RUSTFLAGS: -D warnings
- image: sfackler/rust-postgres-test:6
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ TLS support for postgres and tokio-postgres via native-tls.
[Documentation](https://docs.rs/postgres-openssl)

TLS support for postgres and tokio-postgres via openssl.

# Running test suite

The test suite requires postgres to be running in the correct configuration. The easiest way to do this is with docker:

1. Install `docker` and `docker-compose`.
1. On ubuntu: `sudo apt install docker.io docker-compose`.
1. Make sure your user has permissions for docker.
1. On ubuntu: ``sudo usermod -aG docker $USER``
1. Change to top-level directory of `rust-postgres` repo.
1. Run `docker-compose up -d`.
1. Run `cargo test`.
1. Run `docker-compose stop`.
3 changes: 2 additions & 1 deletion codegen/src/errcodes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# errcodes.txt
# PostgreSQL error codes
#
# Copyright (c) 2003-2019, PostgreSQL Global Development Group
# Copyright (c) 2003-2020, PostgreSQL Global Development Group
#
# This list serves as the basis for generating source files containing error
# codes. It is kept in a common format to make sure all these source files have
Expand Down Expand Up @@ -207,6 +207,7 @@ Section: Class 22 - Data Exception
2200S E ERRCODE_INVALID_XML_COMMENT invalid_xml_comment
2200T E ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION invalid_xml_processing_instruction
22030 E ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE duplicate_json_object_key_value
22031 E ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION invalid_argument_for_sql_json_datetime_function
22032 E ERRCODE_INVALID_JSON_TEXT invalid_json_text
22033 E ERRCODE_INVALID_SQL_JSON_SUBSCRIPT invalid_sql_json_subscript
22034 E ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM more_than_one_sql_json_item
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/pg_range.dat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pg_range.dat
# Initial contents of the pg_range system catalog.
#
# Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
# Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# src/include/catalog/pg_range.dat
Expand Down
53 changes: 44 additions & 9 deletions codegen/src/pg_type.dat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pg_type.dat
# Initial contents of the pg_type system catalog.
#
# Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
# Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# src/include/catalog/pg_type.dat
Expand Down Expand Up @@ -177,6 +177,10 @@
typtype => 'p', typcategory => 'P', typinput => 'pg_ddl_command_in',
typoutput => 'pg_ddl_command_out', typreceive => 'pg_ddl_command_recv',
typsend => 'pg_ddl_command_send', typalign => 'ALIGNOF_POINTER' },
{ oid => '5069', array_type_oid => '271', descr => 'full transaction id',
typname => 'xid8', typlen => '8', typbyval => 'FLOAT8PASSBYVAL',
typcategory => 'U', typinput => 'xid8in', typoutput => 'xid8out',
typreceive => 'xid8recv', typsend => 'xid8send', typalign => 'd' },

# OIDS 600 - 699

Expand Down Expand Up @@ -215,9 +219,9 @@

{ oid => '700', array_type_oid => '1021',
descr => 'single-precision floating point number, 4-byte storage',
typname => 'float4', typlen => '4', typbyval => 'FLOAT4PASSBYVAL',
typcategory => 'N', typinput => 'float4in', typoutput => 'float4out',
typreceive => 'float4recv', typsend => 'float4send', typalign => 'i' },
typname => 'float4', typlen => '4', typbyval => 't', typcategory => 'N',
typinput => 'float4in', typoutput => 'float4out', typreceive => 'float4recv',
typsend => 'float4send', typalign => 'i' },
{ oid => '701', array_type_oid => '1022',
descr => 'double-precision floating point number, 8-byte storage',
typname => 'float8', typlen => '8', typbyval => 'FLOAT8PASSBYVAL',
Expand Down Expand Up @@ -379,6 +383,11 @@
typname => 'regclass', typlen => '4', typbyval => 't', typcategory => 'N',
typinput => 'regclassin', typoutput => 'regclassout',
typreceive => 'regclassrecv', typsend => 'regclasssend', typalign => 'i' },
{ oid => '4191', array_type_oid => '4192', descr => 'registered collation',
typname => 'regcollation', typlen => '4', typbyval => 't', typcategory => 'N',
typinput => 'regcollationin', typoutput => 'regcollationout',
typreceive => 'regcollationrecv', typsend => 'regcollationsend',
typalign => 'i' },
{ oid => '2206', array_type_oid => '2211', descr => 'registered type',
typname => 'regtype', typlen => '4', typbyval => 't', typcategory => 'N',
typinput => 'regtypein', typoutput => 'regtypeout',
Expand Down Expand Up @@ -451,6 +460,11 @@
typcategory => 'U', typinput => 'txid_snapshot_in',
typoutput => 'txid_snapshot_out', typreceive => 'txid_snapshot_recv',
typsend => 'txid_snapshot_send', typalign => 'd', typstorage => 'x' },
{ oid => '5038', array_type_oid => '5039', descr => 'snapshot',
typname => 'pg_snapshot', typlen => '-1', typbyval => 'f', typcategory => 'U',
typinput => 'pg_snapshot_in', typoutput => 'pg_snapshot_out',
typreceive => 'pg_snapshot_recv', typsend => 'pg_snapshot_send',
typalign => 'd', typstorage => 'x' },

# range types
{ oid => '3904', array_type_oid => '3905', descr => 'range of integers',
Expand Down Expand Up @@ -546,10 +560,6 @@
typtype => 'p', typcategory => 'P', typinput => 'internal_in',
typoutput => 'internal_out', typreceive => '-', typsend => '-',
typalign => 'ALIGNOF_POINTER' },
{ oid => '2282', descr => 'obsolete, deprecated pseudo-type',
typname => 'opaque', typlen => '4', typbyval => 't', typtype => 'p',
typcategory => 'P', typinput => 'opaque_in', typoutput => 'opaque_out',
typreceive => '-', typsend => '-', typalign => 'i' },
{ oid => '2283', descr => 'pseudo-type representing a polymorphic base type',
typname => 'anyelement', typlen => '4', typbyval => 't', typtype => 'p',
typcategory => 'P', typinput => 'anyelement_in',
Expand Down Expand Up @@ -590,9 +600,34 @@
typoutput => 'table_am_handler_out', typreceive => '-', typsend => '-',
typalign => 'i' },
{ oid => '3831',
descr => 'pseudo-type representing a polymorphic base type that is a range',
descr => 'pseudo-type representing a range over a polymorphic base type',
typname => 'anyrange', typlen => '-1', typbyval => 'f', typtype => 'p',
typcategory => 'P', typinput => 'anyrange_in', typoutput => 'anyrange_out',
typreceive => '-', typsend => '-', typalign => 'd', typstorage => 'x' },
{ oid => '5077',
descr => 'pseudo-type representing a polymorphic common type',
typname => 'anycompatible', typlen => '4', typbyval => 't', typtype => 'p',
typcategory => 'P', typinput => 'anycompatible_in',
typoutput => 'anycompatible_out', typreceive => '-', typsend => '-',
typalign => 'i' },
{ oid => '5078',
descr => 'pseudo-type representing an array of polymorphic common type elements',
typname => 'anycompatiblearray', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblearray_in',
typoutput => 'anycompatiblearray_out',
typreceive => 'anycompatiblearray_recv', typsend => 'anycompatiblearray_send',
typalign => 'd', typstorage => 'x' },
{ oid => '5079',
descr => 'pseudo-type representing a polymorphic common type that is not an array',
typname => 'anycompatiblenonarray', typlen => '4', typbyval => 't',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblenonarray_in',
typoutput => 'anycompatiblenonarray_out', typreceive => '-', typsend => '-',
typalign => 'i' },
{ oid => '5080',
descr => 'pseudo-type representing a range over a polymorphic common type',
typname => 'anycompatiblerange', typlen => '-1', typbyval => 'f',
typtype => 'p', typcategory => 'P', typinput => 'anycompatiblerange_in',
typoutput => 'anycompatiblerange_out', typreceive => '-', typsend => '-',
typalign => 'd', typstorage => 'x' },

]
5 changes: 1 addition & 4 deletions codegen/src/type_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ impl<'a> DatParser<'a> {
fn peek(&mut self, target: char) -> bool {
self.skip_ws();

match self.it.peek() {
Some((_, ch)) if *ch == target => true,
_ => false,
}
matches!(self.it.peek(), Some((_, ch)) if *ch == target)
}

fn eof(&mut self) {
Expand Down
12 changes: 12 additions & 0 deletions postgres-native-tls/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## v0.5.0 - 2020-12-25

### Changed

* Upgraded to `tokio-postgres` 0.7.

## v0.4.0 - 2020-10-17

### Changed

* Upgraded to `tokio-postgres` 0.6.

## v0.3.0 - 2019-12-23

### Changed
Expand Down
13 changes: 6 additions & 7 deletions postgres-native-tls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "postgres-native-tls"
version = "0.3.0"
version = "0.5.0"
authors = ["Steven Fackler <[email protected]>"]
edition = "2018"
license = "MIT/Apache-2.0"
Expand All @@ -16,13 +16,12 @@ default = ["runtime"]
runtime = ["tokio-postgres/runtime"]

[dependencies]
bytes = "0.5"
futures = "0.3"
native-tls = "0.2"
tokio = "0.2"
tokio-tls = "0.3"
tokio-postgres = { version = "0.5.0", path = "../tokio-postgres", default-features = false }
tokio = "1.0"
tokio-native-tls = "0.3"
tokio-postgres = { version = "0.7.0", path = "../tokio-postgres", default-features = false }

[dev-dependencies]
tokio = { version = "0.2", features = ["full"] }
postgres = { version = "0.17.0", path = "../postgres" }
tokio = { version = "1.0", features = ["full"] }
postgres = { version = "0.19.0", path = "../postgres" }
49 changes: 11 additions & 38 deletions postgres-native-tls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! TLS support for `tokio-postgres` and `postgres` via `native-tls.
//! TLS support for `tokio-postgres` and `postgres` via `native-tls`.
//!
//! # Examples
//!
Expand Down Expand Up @@ -45,16 +45,13 @@
//! # Ok(())
//! # }
//! ```
#![doc(html_root_url = "https://docs.rs/postgres-native-tls/0.3")]
#![warn(rust_2018_idioms, clippy::all, missing_docs)]

use bytes::{Buf, BufMut};
use std::future::Future;
use std::io;
use std::mem::MaybeUninit;
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio_postgres::tls;
#[cfg(feature = "runtime")]
use tokio_postgres::tls::MakeTlsConnect;
Expand Down Expand Up @@ -94,15 +91,15 @@ where

/// A `TlsConnect` implementation using the `native-tls` crate.
pub struct TlsConnector {
connector: tokio_tls::TlsConnector,
connector: tokio_native_tls::TlsConnector,
domain: String,
}

impl TlsConnector {
/// Creates a new connector configured to connect to the specified domain.
pub fn new(connector: native_tls::TlsConnector, domain: &str) -> TlsConnector {
TlsConnector {
connector: tokio_tls::TlsConnector::from(connector),
connector: tokio_native_tls::TlsConnector::from(connector),
domain: domain.to_string(),
}
}
Expand All @@ -129,34 +126,19 @@ where
}

/// The stream returned by `TlsConnector`.
pub struct TlsStream<S>(tokio_tls::TlsStream<S>);
pub struct TlsStream<S>(tokio_native_tls::TlsStream<S>);

impl<S> AsyncRead for TlsStream<S>
where
S: AsyncRead + AsyncWrite + Unpin,
{
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [MaybeUninit<u8>]) -> bool {
self.0.prepare_uninitialized_buffer(buf)
}

fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
Pin::new(&mut self.0).poll_read(cx, buf)
}

fn poll_read_buf<B: BufMut>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut B,
) -> Poll<io::Result<usize>>
where
Self: Sized,
{
Pin::new(&mut self.0).poll_read_buf(cx, buf)
}
}

impl<S> AsyncWrite for TlsStream<S>
Expand All @@ -178,25 +160,16 @@ where
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Pin::new(&mut self.0).poll_shutdown(cx)
}

fn poll_write_buf<B: Buf>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut B,
) -> Poll<io::Result<usize>>
where
Self: Sized,
{
Pin::new(&mut self.0).poll_write_buf(cx, buf)
}
}

impl<S> tls::TlsStream for TlsStream<S>
where
S: AsyncRead + AsyncWrite + Unpin,
{
fn channel_binding(&self) -> ChannelBinding {
// FIXME https://github.com/tokio-rs/tokio/issues/1383
ChannelBinding::none()
match self.0.get_ref().tls_server_end_point().ok().flatten() {
Some(buf) => ChannelBinding::tls_server_end_point(buf),
None => ChannelBinding::none(),
}
}
}
12 changes: 12 additions & 0 deletions postgres-openssl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## v0.5.0 - 2020-12-25

### Changed

* Upgraded to `tokio-postgres` 0.7.

## v0.4.0 - 2020-10-17

### Changed

* Upgraded to `tokio-postgres` 0.6.

## v0.3.0 - 2019-12-23

### Changed
Expand Down
13 changes: 6 additions & 7 deletions postgres-openssl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "postgres-openssl"
version = "0.3.0"
version = "0.5.0"
authors = ["Steven Fackler <[email protected]>"]
edition = "2018"
license = "MIT/Apache-2.0"
Expand All @@ -16,13 +16,12 @@ default = ["runtime"]
runtime = ["tokio-postgres/runtime"]

[dependencies]
bytes = "0.5"
futures = "0.3"
openssl = "0.10"
tokio = "0.2"
tokio-openssl = "0.4"
tokio-postgres = { version = "0.5.0", path = "../tokio-postgres", default-features = false }
tokio = "1.0"
tokio-openssl = "0.6"
tokio-postgres = { version = "0.7.0", path = "../tokio-postgres", default-features = false }

[dev-dependencies]
tokio = { version = "0.2", features = ["full"] }
postgres = { version = "0.17.0", path = "../postgres" }
tokio = { version = "1.0", features = ["full"] }
postgres = { version = "0.19.0", path = "../postgres" }
Loading

0 comments on commit 7d3753e

Please sign in to comment.