From 87316f0afb831155fb96e2d0f413e86eb94b369c Mon Sep 17 00:00:00 2001 From: Julius de Bruijn Date: Wed, 22 Jul 2020 15:29:12 +0200 Subject: [PATCH 1/2] Configuration to disable internal stmt cache This enables usage with pgBouncer's transaction mode. Typically when using the transaction mode, a client gets a new connection from pgBouncer for every new transaction. It's quite useful and allows one to use prepared statements in this mode. The workflow goes: ```sql -- start a new transaction BEGIN -- deallocate all stored statements from the server to prevent -- collisions DEALLOCATE ALL -- run the queries here -- .. -- .. COMMIT -- or ROLLBACK ``` Now in a case where the query uses custom types such as enums, what tokio-postgres does is it fetches the type info for the given type, stores the info to the cache and also caches the statements for fetching the info to the client. Now when we have two tables with different custom types in both of them, we can imagine the following workflow: ```rust // first query client.simple_query("BEGIN")?; client.simple_query("DEALLOCATE ALL")?; let stmt = client.prepare("SELECT \"public\".\"User\".\"id\", \"public\".\"User\".\"userType\" FROM \"public\".\"User\" WHERE 1=1 OFFSET $1")?; dbg!(client.query(&stmt, &[&0i64])?); client.simple_query("COMMIT")?; // second query client.simple_query("BEGIN")?; client.simple_query("DEALLOCATE ALL")?; let stmt = client.prepare("SELECT \"public\".\"Work\".\"id\", \"public\".\"Work\".\"workType\" FROM \"public\".\"Work\" WHERE 1=1 OFFSET $1")?; dbg!(client.query(&stmt, &[&0i64])?); client.simple_query("COMMIT")?; ``` The `userType` and `workType` are both enums, and the preparing of the second query will give an error `prepared statement "s1" does not exist`, where `s1` is the query to the `pg_catalog` for the type info. The change here gives an extra flag for the client to disable caching of statements. --- postgres/src/config.rs | 15 ++++++++++++++ tokio-postgres/src/client.rs | 33 +++++++++++++++++++++++++------ tokio-postgres/src/config.rs | 17 ++++++++++++++++ tokio-postgres/src/connect_raw.rs | 8 +++++++- 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/postgres/src/config.rs b/postgres/src/config.rs index b344efdd2..7ce7d7133 100644 --- a/postgres/src/config.rs +++ b/postgres/src/config.rs @@ -307,6 +307,21 @@ impl Config { self.config.get_channel_binding() } + /// When enabled, the client skips all internal caching for statements, + /// allowing usage with pgBouncer's transaction mode and clearing of + /// statements in the session with `DEALLOCATE ALL`. + /// + /// Defaults to `false`. + pub fn pgbouncer_mode(&mut self, enable: bool) -> &mut Config { + self.config.pgbouncer_mode(enable); + self + } + + /// Gets the pgBouncer mode status. + pub fn get_pgbouncer_mode(&self) -> bool { + self.config.get_pgbouncer_mode() + } + /// Opens a connection to a PostgreSQL database. pub fn connect(&self, tls: T) -> Result where diff --git a/tokio-postgres/src/client.rs b/tokio-postgres/src/client.rs index 2d9b79728..861bec880 100644 --- a/tokio-postgres/src/client.rs +++ b/tokio-postgres/src/client.rs @@ -64,6 +64,7 @@ struct State { pub struct InnerClient { sender: mpsc::UnboundedSender, state: Mutex, + pgbouncer_mode: bool, } impl InnerClient { @@ -81,27 +82,45 @@ impl InnerClient { } pub fn typeinfo(&self) -> Option { - self.state.lock().typeinfo.clone() + if self.pgbouncer_mode { + None + } else { + self.state.lock().typeinfo.clone() + } } pub fn set_typeinfo(&self, statement: &Statement) { - self.state.lock().typeinfo = Some(statement.clone()); + if !self.pgbouncer_mode { + self.state.lock().typeinfo = Some(statement.clone()); + } } pub fn typeinfo_composite(&self) -> Option { - self.state.lock().typeinfo_composite.clone() + if self.pgbouncer_mode { + None + } else { + self.state.lock().typeinfo_composite.clone() + } } pub fn set_typeinfo_composite(&self, statement: &Statement) { - self.state.lock().typeinfo_composite = Some(statement.clone()); + if !self.pgbouncer_mode { + self.state.lock().typeinfo_composite = Some(statement.clone()); + } } pub fn typeinfo_enum(&self) -> Option { - self.state.lock().typeinfo_enum.clone() + if self.pgbouncer_mode { + None + } else { + self.state.lock().typeinfo_enum.clone() + } } pub fn set_typeinfo_enum(&self, statement: &Statement) { - self.state.lock().typeinfo_enum = Some(statement.clone()); + if !self.pgbouncer_mode { + self.state.lock().typeinfo_enum = Some(statement.clone()); + } } pub fn type_(&self, oid: Oid) -> Option { @@ -151,6 +170,7 @@ impl Client { ssl_mode: SslMode, process_id: i32, secret_key: i32, + pgbouncer_mode: bool, ) -> Client { Client { inner: Arc::new(InnerClient { @@ -162,6 +182,7 @@ impl Client { types: HashMap::new(), buf: BytesMut::new(), }), + pgbouncer_mode, }), #[cfg(feature = "runtime")] socket_config: None, diff --git a/tokio-postgres/src/config.rs b/tokio-postgres/src/config.rs index da171cc79..e32121c6d 100644 --- a/tokio-postgres/src/config.rs +++ b/tokio-postgres/src/config.rs @@ -159,6 +159,7 @@ pub struct Config { pub(crate) keepalives_idle: Duration, pub(crate) target_session_attrs: TargetSessionAttrs, pub(crate) channel_binding: ChannelBinding, + pub(crate) pgbouncer_mode: bool, } impl Default for Config { @@ -184,6 +185,7 @@ impl Config { keepalives_idle: Duration::from_secs(2 * 60 * 60), target_session_attrs: TargetSessionAttrs::Any, channel_binding: ChannelBinding::Prefer, + pgbouncer_mode: false, } } @@ -387,6 +389,21 @@ impl Config { self.channel_binding } + /// When enabled, the client skips all internal caching for statements, + /// allowing usage with pgBouncer's transaction mode and clearing of + /// statements in the session with `DEALLOCATE ALL`. + /// + /// Defaults to `false`. + pub fn pgbouncer_mode(&mut self, enable: bool) -> &mut Config { + self.pgbouncer_mode = enable; + self + } + + /// Gets the pgBouncer mode status. + pub fn get_pgbouncer_mode(&self) -> bool { + self.pgbouncer_mode + } + fn param(&mut self, key: &str, value: &str) -> Result<(), Error> { match key { "user" => { diff --git a/tokio-postgres/src/connect_raw.rs b/tokio-postgres/src/connect_raw.rs index d07d5a2df..4c4ba953d 100644 --- a/tokio-postgres/src/connect_raw.rs +++ b/tokio-postgres/src/connect_raw.rs @@ -100,7 +100,13 @@ where let (process_id, secret_key, parameters) = read_info(&mut stream).await?; let (sender, receiver) = mpsc::unbounded(); - let client = Client::new(sender, config.ssl_mode, process_id, secret_key); + let client = Client::new( + sender, + config.ssl_mode, + process_id, + secret_key, + config.pgbouncer_mode, + ); let connection = Connection::new(stream.inner, stream.delayed, parameters, receiver); Ok((client, connection)) From 11b4788ed414f6308a93c5e1c05aa13923d043d3 Mon Sep 17 00:00:00 2001 From: Julius de Bruijn Date: Fri, 15 Jan 2021 16:07:53 +0100 Subject: [PATCH 2/2] Fork everything as prisma-postgres --- Cargo.toml | 1 - README.md | 28 ++-- postgres-derive-test/Cargo.toml | 8 +- postgres-derive/Cargo.toml | 6 +- postgres-native-tls/Cargo.toml | 15 +- postgres-openssl/CHANGELOG.md | 37 ----- postgres-openssl/Cargo.toml | 27 ---- postgres-openssl/LICENSE-APACHE | 1 - postgres-openssl/LICENSE-MIT | 1 - postgres-openssl/src/lib.rs | 242 -------------------------------- postgres-openssl/src/test.rs | 111 --------------- postgres-protocol/Cargo.toml | 6 +- postgres-types/Cargo.toml | 10 +- postgres/Cargo.toml | 9 +- tokio-postgres/Cargo.toml | 13 +- 15 files changed, 41 insertions(+), 474 deletions(-) delete mode 100644 postgres-openssl/CHANGELOG.md delete mode 100644 postgres-openssl/Cargo.toml delete mode 120000 postgres-openssl/LICENSE-APACHE delete mode 120000 postgres-openssl/LICENSE-MIT delete mode 100644 postgres-openssl/src/lib.rs delete mode 100644 postgres-openssl/src/test.rs diff --git a/Cargo.toml b/Cargo.toml index 4752836a7..7ab3e7e34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ members = [ "postgres-derive", "postgres-derive-test", "postgres-native-tls", - "postgres-openssl", "postgres-protocol", "postgres-types", "tokio-postgres", diff --git a/README.md b/README.md index 3af068174..b8e6c9f23 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,34 @@ # Rust-Postgres -[![CircleCI](https://circleci.com/gh/sfackler/rust-postgres.svg?style=shield)](https://circleci.com/gh/sfackler/rust-postgres) -PostgreSQL support for Rust. +PostgreSQL support for Rust. This version adds a new config option for +pgbouncer, allowing prepared statement use on pgbouncer's transaction mode. If +you don't need this, you're much better off with the [original +crate](https://crates.io/crates/postgres). -## postgres [![Latest Version](https://img.shields.io/crates/v/postgres.svg)](https://crates.io/crates/postgres) +## postgres [![Latest Version](https://img.shields.io/crates/v/prisma-postgres.svg)](https://crates.io/crates/prisma-postgres) -[Documentation](https://docs.rs/postgres) +[Documentation](https://docs.rs/prisma-postgres) A native, synchronous PostgreSQL client. -## tokio-postgres [![Latest Version](https://img.shields.io/crates/v/tokio-postgres.svg)](https://crates.io/crates/tokio-postgres) +## tokio-postgres [![Latest Version](https://img.shields.io/crates/v/tokio-postgres.svg)](https://crates.io/crates/prisma-tokio-postgres) -[Documentation](https://docs.rs/tokio-postgres) +[Documentation](https://docs.rs/prisma-tokio-postgres) A native, asynchronous PostgreSQL client. -## postgres-types [![Latest Version](https://img.shields.io/crates/v/postgres-types.svg)](https://crates.io/crates/postgres-types) +## postgres-types [![Latest Version](https://img.shields.io/crates/v/postgres-types.svg)](https://crates.io/crates/prisma-postgres-types) -[Documentation](https://docs.rs/postgres-types) +[Documentation](https://docs.rs/prisma-postgres-types) Conversions between Rust and Postgres types. -## postgres-native-tls [![Latest Version](https://img.shields.io/crates/v/postgres-native-tls.svg)](https://crates.io/crates/postgres-native-tls) +## postgres-native-tls [![Latest Version](https://img.shields.io/crates/v/postgres-native-tls.svg)](https://crates.io/crates/prisma-postgres-native-tls) -[Documentation](https://docs.rs/postgres-native-tls) +[Documentation](https://docs.rs/prisma-postgres-native-tls) TLS support for postgres and tokio-postgres via native-tls. -## postgres-openssl [![Latest Version](https://img.shields.io/crates/v/postgres-openssl.svg)](https://crates.io/crates/postgres-openssl) - -[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: diff --git a/postgres-derive-test/Cargo.toml b/postgres-derive-test/Cargo.toml index 24fd1614f..6414cbc1d 100644 --- a/postgres-derive-test/Cargo.toml +++ b/postgres-derive-test/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "postgres-derive-test" +name = "prisma-postgres-derive-test" version = "0.1.0" -authors = ["Steven Fackler "] +authors = ["Steven Fackler ", "Julius de Bruijn "] edition = "2018" [dev-dependencies] trybuild = "1.0" -postgres-types = { path = "../postgres-types", features = ["derive"] } -postgres = { path = "../postgres" } +prisma-postgres-types = { path = "../postgres-types", features = ["derive"] } +prisma-postgres = { path = "../postgres" } diff --git a/postgres-derive/Cargo.toml b/postgres-derive/Cargo.toml index 293c294a0..d0091e840 100644 --- a/postgres-derive/Cargo.toml +++ b/postgres-derive/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "postgres-derive" +name = "prisma-postgres-derive" version = "0.4.0" -authors = ["Steven Fackler "] +authors = ["Steven Fackler ", "Julius de Bruijn "] license = "MIT/Apache-2.0" edition = "2018" description = "An internal crate used by postgres-types" -repository = "https://github.com/sfackler/rust-postgres" +repository = "https://github.com/pimeys/rust-postgres" [lib] proc-macro = true diff --git a/postgres-native-tls/Cargo.toml b/postgres-native-tls/Cargo.toml index 8180cd012..e020f30e4 100644 --- a/postgres-native-tls/Cargo.toml +++ b/postgres-native-tls/Cargo.toml @@ -1,27 +1,24 @@ [package] name = "postgres-native-tls" version = "0.5.0" -authors = ["Steven Fackler "] +authors = ["Steven Fackler ", "Julius de Bruijn "] edition = "2018" license = "MIT/Apache-2.0" -description = "TLS support for tokio-postgres via native-tls" -repository = "https://github.com/sfackler/rust-postgres" +description = "TLS support for prisma-tokio-postgres via native-tls" +repository = "https://github.com/pimeys/rust-postgres" readme = "../README.md" -[badges] -circle-ci = { repository = "sfackler/rust-postgres" } - [features] default = ["runtime"] -runtime = ["tokio-postgres/runtime"] +runtime = ["prisma-tokio-postgres/runtime"] [dependencies] futures = "0.3" native-tls = "0.2" tokio = "1.0" tokio-native-tls = "0.3" -tokio-postgres = { version = "0.7.0", path = "../tokio-postgres", default-features = false } +prisma-tokio-postgres = { version = "0.7.0", path = "../tokio-postgres", default-features = false } [dev-dependencies] tokio = { version = "1.0", features = ["full"] } -postgres = { version = "0.19.0", path = "../postgres" } +prisma-postgres = { version = "0.19.0", path = "../postgres" } diff --git a/postgres-openssl/CHANGELOG.md b/postgres-openssl/CHANGELOG.md deleted file mode 100644 index 346214ae8..000000000 --- a/postgres-openssl/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# 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 - -* Upgraded to `tokio-postgres` 0.5. - -## v0.3.0-alpha.2 - 2019-11-27 - -### Changed - -* Upgraded `tokio-postgres` v0.5.0-alpha.2. - -## v0.3.0-alpha.1 - 2019-10-14 - -### Changed - -* Updated to `tokio-postgres` v0.5.0-alpha.1. - -## v0.2.0-rc.1 - 2019-03-06 - -### Changed - -* Updated to `tokio-postgres` v0.4.0-rc. diff --git a/postgres-openssl/Cargo.toml b/postgres-openssl/Cargo.toml deleted file mode 100644 index 5738e74d2..000000000 --- a/postgres-openssl/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "postgres-openssl" -version = "0.5.0" -authors = ["Steven Fackler "] -edition = "2018" -license = "MIT/Apache-2.0" -description = "TLS support for tokio-postgres via openssl" -repository = "https://github.com/sfackler/rust-postgres" -readme = "../README.md" - -[badges] -circle-ci = { repository = "sfackler/rust-postgres" } - -[features] -default = ["runtime"] -runtime = ["tokio-postgres/runtime"] - -[dependencies] -futures = "0.3" -openssl = "0.10" -tokio = "1.0" -tokio-openssl = "0.6" -tokio-postgres = { version = "0.7.0", path = "../tokio-postgres", default-features = false } - -[dev-dependencies] -tokio = { version = "1.0", features = ["full"] } -postgres = { version = "0.19.0", path = "../postgres" } diff --git a/postgres-openssl/LICENSE-APACHE b/postgres-openssl/LICENSE-APACHE deleted file mode 120000 index b9e46b0fc..000000000 --- a/postgres-openssl/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../tokio-postgres/LICENSE-APACHE \ No newline at end of file diff --git a/postgres-openssl/LICENSE-MIT b/postgres-openssl/LICENSE-MIT deleted file mode 120000 index 162832a42..000000000 --- a/postgres-openssl/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../tokio-postgres/LICENSE-MIT \ No newline at end of file diff --git a/postgres-openssl/src/lib.rs b/postgres-openssl/src/lib.rs deleted file mode 100644 index dce3dff5d..000000000 --- a/postgres-openssl/src/lib.rs +++ /dev/null @@ -1,242 +0,0 @@ -//! TLS support for `tokio-postgres` and `postgres` via `openssl`. -//! -//! # Examples -//! -//! ```no_run -//! use openssl::ssl::{SslConnector, SslMethod}; -//! use postgres_openssl::MakeTlsConnector; -//! -//! # fn main() -> Result<(), Box> { -//! let mut builder = SslConnector::builder(SslMethod::tls())?; -//! builder.set_ca_file("database_cert.pem")?; -//! let connector = MakeTlsConnector::new(builder.build()); -//! -//! let connect_future = tokio_postgres::connect( -//! "host=localhost user=postgres sslmode=require", -//! connector, -//! ); -//! -//! // ... -//! # Ok(()) -//! # } -//! ``` -//! -//! ```no_run -//! use openssl::ssl::{SslConnector, SslMethod}; -//! use postgres_openssl::MakeTlsConnector; -//! -//! # fn main() -> Result<(), Box> { -//! let mut builder = SslConnector::builder(SslMethod::tls())?; -//! builder.set_ca_file("database_cert.pem")?; -//! let connector = MakeTlsConnector::new(builder.build()); -//! -//! let client = postgres::Client::connect( -//! "host=localhost user=postgres sslmode=require", -//! connector, -//! )?; -//! -//! // ... -//! # Ok(()) -//! # } -//! ``` -#![warn(rust_2018_idioms, clippy::all, missing_docs)] - -#[cfg(feature = "runtime")] -use openssl::error::ErrorStack; -use openssl::hash::MessageDigest; -use openssl::nid::Nid; -#[cfg(feature = "runtime")] -use openssl::ssl::SslConnector; -use openssl::ssl::{self, ConnectConfiguration, SslRef}; -use openssl::x509::X509VerifyResult; -use std::error::Error; -use std::fmt::{self, Debug}; -use std::future::Future; -use std::io; -use std::pin::Pin; -#[cfg(feature = "runtime")] -use std::sync::Arc; -use std::task::{Context, Poll}; -use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; -use tokio_openssl::SslStream; -use tokio_postgres::tls; -#[cfg(feature = "runtime")] -use tokio_postgres::tls::MakeTlsConnect; -use tokio_postgres::tls::{ChannelBinding, TlsConnect}; - -#[cfg(test)] -mod test; - -/// A `MakeTlsConnect` implementation using the `openssl` crate. -/// -/// Requires the `runtime` Cargo feature (enabled by default). -#[cfg(feature = "runtime")] -#[derive(Clone)] -pub struct MakeTlsConnector { - connector: SslConnector, - config: Arc Result<(), ErrorStack> + Sync + Send>, -} - -#[cfg(feature = "runtime")] -impl MakeTlsConnector { - /// Creates a new connector. - pub fn new(connector: SslConnector) -> MakeTlsConnector { - MakeTlsConnector { - connector, - config: Arc::new(|_, _| Ok(())), - } - } - - /// Sets a callback used to apply per-connection configuration. - /// - /// The the callback is provided the domain name along with the `ConnectConfiguration`. - pub fn set_callback(&mut self, f: F) - where - F: Fn(&mut ConnectConfiguration, &str) -> Result<(), ErrorStack> + 'static + Sync + Send, - { - self.config = Arc::new(f); - } -} - -#[cfg(feature = "runtime")] -impl MakeTlsConnect for MakeTlsConnector -where - S: AsyncRead + AsyncWrite + Unpin + Debug + 'static + Sync + Send, -{ - type Stream = TlsStream; - type TlsConnect = TlsConnector; - type Error = ErrorStack; - - fn make_tls_connect(&mut self, domain: &str) -> Result { - let mut ssl = self.connector.configure()?; - (self.config)(&mut ssl, domain)?; - Ok(TlsConnector::new(ssl, domain)) - } -} - -/// A `TlsConnect` implementation using the `openssl` crate. -pub struct TlsConnector { - ssl: ConnectConfiguration, - domain: String, -} - -impl TlsConnector { - /// Creates a new connector configured to connect to the specified domain. - pub fn new(ssl: ConnectConfiguration, domain: &str) -> TlsConnector { - TlsConnector { - ssl, - domain: domain.to_string(), - } - } -} - -impl TlsConnect for TlsConnector -where - S: AsyncRead + AsyncWrite + Unpin + Send + 'static, -{ - type Stream = TlsStream; - type Error = Box; - #[allow(clippy::type_complexity)] - type Future = Pin, Self::Error>> + Send>>; - - fn connect(self, stream: S) -> Self::Future { - let future = async move { - let ssl = self.ssl.into_ssl(&self.domain)?; - let mut stream = SslStream::new(ssl, stream)?; - match Pin::new(&mut stream).connect().await { - Ok(()) => Ok(TlsStream(stream)), - Err(error) => Err(Box::new(ConnectError { - error, - verify_result: stream.ssl().verify_result(), - }) as _), - } - }; - - Box::pin(future) - } -} - -#[derive(Debug)] -struct ConnectError { - error: ssl::Error, - verify_result: X509VerifyResult, -} - -impl fmt::Display for ConnectError { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&self.error, fmt)?; - - if self.verify_result != X509VerifyResult::OK { - fmt.write_str(": ")?; - fmt::Display::fmt(&self.verify_result, fmt)?; - } - - Ok(()) - } -} - -impl Error for ConnectError { - fn source(&self) -> Option<&(dyn Error + 'static)> { - Some(&self.error) - } -} - -/// The stream returned by `TlsConnector`. -pub struct TlsStream(SslStream); - -impl AsyncRead for TlsStream -where - S: AsyncRead + AsyncWrite + Unpin, -{ - fn poll_read( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut ReadBuf<'_>, - ) -> Poll> { - Pin::new(&mut self.0).poll_read(cx, buf) - } -} - -impl AsyncWrite for TlsStream -where - S: AsyncRead + AsyncWrite + Unpin, -{ - fn poll_write( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &[u8], - ) -> Poll> { - Pin::new(&mut self.0).poll_write(cx, buf) - } - - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.0).poll_flush(cx) - } - - fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.0).poll_shutdown(cx) - } -} - -impl tls::TlsStream for TlsStream -where - S: AsyncRead + AsyncWrite + Unpin, -{ - fn channel_binding(&self) -> ChannelBinding { - match tls_server_end_point(self.0.ssl()) { - Some(buf) => ChannelBinding::tls_server_end_point(buf), - None => ChannelBinding::none(), - } - } -} - -fn tls_server_end_point(ssl: &SslRef) -> Option> { - let cert = ssl.peer_certificate()?; - let algo_nid = cert.signature_algorithm().object().nid(); - let signature_algorithms = algo_nid.signature_algorithms()?; - let md = match signature_algorithms.digest { - Nid::MD5 | Nid::SHA1 => MessageDigest::sha256(), - nid => MessageDigest::from_nid(nid)?, - }; - cert.digest(md).ok().map(|b| b.to_vec()) -} diff --git a/postgres-openssl/src/test.rs b/postgres-openssl/src/test.rs deleted file mode 100644 index 15ed90ad5..000000000 --- a/postgres-openssl/src/test.rs +++ /dev/null @@ -1,111 +0,0 @@ -use futures::FutureExt; -use openssl::ssl::{SslConnector, SslMethod}; -use tokio::net::TcpStream; -use tokio_postgres::tls::TlsConnect; - -use super::*; - -async fn smoke_test(s: &str, tls: T) -where - T: TlsConnect, - T::Stream: 'static + Send, -{ - let stream = TcpStream::connect("127.0.0.1:5433").await.unwrap(); - - let builder = s.parse::().unwrap(); - let (client, connection) = builder.connect_raw(stream, tls).await.unwrap(); - - let connection = connection.map(|r| r.unwrap()); - tokio::spawn(connection); - - let stmt = client.prepare("SELECT $1::INT4").await.unwrap(); - let rows = client.query(&stmt, &[&1i32]).await.unwrap(); - - assert_eq!(rows.len(), 1); - assert_eq!(rows[0].get::<_, i32>(0), 1); -} - -#[tokio::test] -async fn require() { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder.set_ca_file("../test/server.crt").unwrap(); - let ctx = builder.build(); - smoke_test( - "user=ssl_user dbname=postgres sslmode=require", - TlsConnector::new(ctx.configure().unwrap(), "localhost"), - ) - .await; -} - -#[tokio::test] -async fn prefer() { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder.set_ca_file("../test/server.crt").unwrap(); - let ctx = builder.build(); - smoke_test( - "user=ssl_user dbname=postgres", - TlsConnector::new(ctx.configure().unwrap(), "localhost"), - ) - .await; -} - -#[tokio::test] -async fn scram_user() { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder.set_ca_file("../test/server.crt").unwrap(); - let ctx = builder.build(); - smoke_test( - "user=scram_user password=password dbname=postgres sslmode=require", - TlsConnector::new(ctx.configure().unwrap(), "localhost"), - ) - .await; -} - -#[tokio::test] -async fn require_channel_binding_err() { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder.set_ca_file("../test/server.crt").unwrap(); - let ctx = builder.build(); - let connector = TlsConnector::new(ctx.configure().unwrap(), "localhost"); - - let stream = TcpStream::connect("127.0.0.1:5433").await.unwrap(); - let builder = "user=pass_user password=password dbname=postgres channel_binding=require" - .parse::() - .unwrap(); - builder.connect_raw(stream, connector).await.err().unwrap(); -} - -#[tokio::test] -async fn require_channel_binding_ok() { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder.set_ca_file("../test/server.crt").unwrap(); - let ctx = builder.build(); - smoke_test( - "user=scram_user password=password dbname=postgres channel_binding=require", - TlsConnector::new(ctx.configure().unwrap(), "localhost"), - ) - .await; -} - -#[tokio::test] -#[cfg(feature = "runtime")] -async fn runtime() { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder.set_ca_file("../test/server.crt").unwrap(); - let connector = MakeTlsConnector::new(builder.build()); - - let (client, connection) = tokio_postgres::connect( - "host=localhost port=5433 user=postgres sslmode=require", - connector, - ) - .await - .unwrap(); - let connection = connection.map(|r| r.unwrap()); - tokio::spawn(connection); - - let stmt = client.prepare("SELECT $1::INT4").await.unwrap(); - let rows = client.query(&stmt, &[&1i32]).await.unwrap(); - - assert_eq!(rows.len(), 1); - assert_eq!(rows[0].get::<_, i32>(0), 1); -} diff --git a/postgres-protocol/Cargo.toml b/postgres-protocol/Cargo.toml index 1224c633d..98803c785 100644 --- a/postgres-protocol/Cargo.toml +++ b/postgres-protocol/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "postgres-protocol" +name = "prisma-postgres-protocol" version = "0.6.0" -authors = ["Steven Fackler "] +authors = ["Steven Fackler ", "Julius de Bruijn "] edition = "2018" description = "Low level Postgres protocol APIs" license = "MIT/Apache-2.0" -repository = "https://github.com/sfackler/rust-postgres" +repository = "https://github.com/pimeys/rust-postgres" readme = "../README.md" [dependencies] diff --git a/postgres-types/Cargo.toml b/postgres-types/Cargo.toml index 40edc621b..b4212f503 100644 --- a/postgres-types/Cargo.toml +++ b/postgres-types/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "postgres-types" +name = "prisma-postgres-types" version = "0.2.0" -authors = ["Steven Fackler "] +authors = ["Steven Fackler ", "Julius de Bruijn "] edition = "2018" license = "MIT/Apache-2.0" description = "Conversions between Rust and Postgres values" -repository = "https://github.com/sfackler/rust-postgres" +repository = "https://github.com/pimeys/rust-postgres" readme = "../README.md" keywords = ["database", "postgres", "postgresql", "sql"] categories = ["database"] @@ -23,8 +23,8 @@ with-time-0_2 = ["time-02"] [dependencies] bytes = "1.0" fallible-iterator = "0.2" -postgres-protocol = { version = "0.6.0", path = "../postgres-protocol" } -postgres-derive = { version = "0.4.0", optional = true, path = "../postgres-derive" } +prisma-postgres-protocol = { version = "0.6.0", path = "../postgres-protocol" } +prisma-postgres-derive = { version = "0.4.0", optional = true, path = "../postgres-derive" } bit-vec-06 = { version = "0.6", package = "bit-vec", optional = true } chrono-04 = { version = "0.4.16", package = "chrono", default-features = false, features = ["clock"], optional = true } diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index ed63d0c1a..eb02a3ac8 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "postgres" +name = "prisma-postgres" version = "0.19.0" -authors = ["Steven Fackler "] +authors = ["Steven Fackler ", "Julius de Bruijn "] edition = "2018" license = "MIT/Apache-2.0" description = "A native, synchronous PostgreSQL client" @@ -17,9 +17,6 @@ harness = false [package.metadata.docs.rs] all-features = true -[badges] -circle-ci = { repository = "sfackler/rust-postgres" } - [features] with-bit-vec-0_6 = ["tokio-postgres/with-bit-vec-0_6"] with-chrono-0_4 = ["tokio-postgres/with-chrono-0_4"] @@ -33,7 +30,7 @@ with-time-0_2 = ["tokio-postgres/with-time-0_2"] bytes = "1.0" fallible-iterator = "0.2" futures = "0.3" -tokio-postgres = { version = "0.7.0", path = "../tokio-postgres" } +prisma-tokio-postgres = { version = "0.7.0", path = "../tokio-postgres" } tokio = { version = "1.0", features = ["rt", "time"] } log = "0.4" diff --git a/tokio-postgres/Cargo.toml b/tokio-postgres/Cargo.toml index 613af127f..368ed8a54 100644 --- a/tokio-postgres/Cargo.toml +++ b/tokio-postgres/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "tokio-postgres" +name = "prisma-tokio-postgres" version = "0.7.0" -authors = ["Steven Fackler "] +authors = ["Steven Fackler ", "Julius de Bruijn "] edition = "2018" license = "MIT/Apache-2.0" description = "A native, asynchronous PostgreSQL client" -repository = "https://github.com/sfackler/rust-postgres" +repository = "https://github.com/pimeys/rust-postgres" readme = "../README.md" keywords = ["database", "postgres", "postgresql", "sql", "async"] categories = ["database"] @@ -20,9 +20,6 @@ harness = false [package.metadata.docs.rs] all-features = true -[badges] -circle-ci = { repository = "sfackler/rust-postgres" } - [features] default = ["runtime"] runtime = ["tokio/net", "tokio/time"] @@ -46,8 +43,8 @@ parking_lot = "0.11" percent-encoding = "2.0" pin-project-lite = "0.2" phf = "0.8" -postgres-protocol = { version = "0.6.0", path = "../postgres-protocol" } -postgres-types = { version = "0.2.0", path = "../postgres-types" } +prisma-postgres-protocol = { version = "0.6.0", path = "../postgres-protocol" } +prisma-postgres-types = { version = "0.2.0", path = "../postgres-types" } socket2 = "0.3" tokio = { version = "1.0", features = ["io-util"] } tokio-util = { version = "0.6", features = ["codec"] }