Add postgres examples to TLS crates

This commit is contained in:
Steven Fackler 2019-04-01 18:51:17 -07:00
parent aaaf8247ec
commit 49c22a8a39
4 changed files with 57 additions and 10 deletions

View File

@ -24,3 +24,4 @@ tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-f
[dev-dependencies] [dev-dependencies]
tokio = "0.1.7" tokio = "0.1.7"
postgres = { version = "0.1.0", path = "../postgres" }

View File

@ -1,18 +1,18 @@
//! TLS support for `tokio-postgres` via `native-tls. //! TLS support for `tokio-postgres` and `postgres` via `native-tls.
//! //!
//! # Example //! # Examples
//! //!
//! ```no_run //! ```no_run
//! use native_tls::{Certificate, TlsConnector}; //! use native_tls::{Certificate, TlsConnector};
//! use tokio_postgres_native_tls::MakeTlsConnector; //! use tokio_postgres_native_tls::MakeTlsConnector;
//! use std::fs; //! use std::fs;
//! //!
//! let cert = fs::read("database_cert.pem").unwrap(); //! # fn main() -> Result<(), Box<std::error::Error>> {
//! let cert = Certificate::from_pem(&cert).unwrap(); //! let cert = fs::read("database_cert.pem")?;
//! let cert = Certificate::from_pem(&cert)?;
//! let connector = TlsConnector::builder() //! let connector = TlsConnector::builder()
//! .add_root_certificate(cert) //! .add_root_certificate(cert)
//! .build() //! .build()?;
//! .unwrap();
//! let connector = MakeTlsConnector::new(connector); //! let connector = MakeTlsConnector::new(connector);
//! //!
//! let connect_future = tokio_postgres::connect( //! let connect_future = tokio_postgres::connect(
@ -21,6 +21,29 @@
//! ); //! );
//! //!
//! // ... //! // ...
//! # Ok(())
//! # }
//! ```
//!
//! ```no_run
//! use native_tls::{Certificate, TlsConnector};
//! use tokio_postgres_native_tls::MakeTlsConnector;
//! use std::fs;
//!
//! # fn main() -> Result<(), Box<std::error::Error>> {
//! let cert = fs::read("database_cert.pem")?;
//! let cert = Certificate::from_pem(&cert)?;
//! let connector = TlsConnector::builder()
//! .add_root_certificate(cert)
//! .build()?;
//! let connector = MakeTlsConnector::new(connector);
//!
//! let mut client = postgres::Client::connect(
//! "host=localhost user=postgres sslmode=require",
//! connector,
//! )?;
//! # Ok(())
//! # }
//! ``` //! ```
#![doc(html_root_url = "https://docs.rs/tokio-postgres-native-tls/0.1.0-rc.1")] #![doc(html_root_url = "https://docs.rs/tokio-postgres-native-tls/0.1.0-rc.1")]
#![warn(rust_2018_idioms, clippy::all, missing_docs)] #![warn(rust_2018_idioms, clippy::all, missing_docs)]

View File

@ -24,3 +24,4 @@ tokio-postgres = { version = "0.4.0-rc.1", path = "../tokio-postgres", default-f
[dev-dependencies] [dev-dependencies]
tokio = "0.1.7" tokio = "0.1.7"
postgres = { version = "0.1", path = "../postgres" }

View File

@ -1,13 +1,14 @@
//! TLS support for `tokio-postgres` via `openssl`. //! TLS support for `tokio-postgres` and `postgres` via `openssl`.
//! //!
//! # Example //! # Examples
//! //!
//! ```no_run //! ```no_run
//! use openssl::ssl::{SslConnector, SslMethod}; //! use openssl::ssl::{SslConnector, SslMethod};
//! use tokio_postgres_openssl::MakeTlsConnector; //! use tokio_postgres_openssl::MakeTlsConnector;
//! //!
//! let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); //! # fn main() -> Result<(), Box<std::error::Error>> {
//! builder.set_ca_file("database_cert.pem").unwrap(); //! let mut builder = SslConnector::builder(SslMethod::tls())?;
//! builder.set_ca_file("database_cert.pem")?;
//! let connector = MakeTlsConnector::new(builder.build()); //! let connector = MakeTlsConnector::new(builder.build());
//! //!
//! let connect_future = tokio_postgres::connect( //! let connect_future = tokio_postgres::connect(
@ -16,6 +17,27 @@
//! ); //! );
//! //!
//! // ... //! // ...
//! # Ok(())
//! # }
//! ```
//!
//! ```no_run
//! use openssl::ssl::{SslConnector, SslMethod};
//! use tokio_postgres_openssl::MakeTlsConnector;
//!
//! # fn main() -> Result<(), Box<std::error::Error>> {
//! let mut builder = SslConnector::builder(SslMethod::tls())?;
//! builder.set_ca_file("database_cert.pem")?;
//! let connector = MakeTlsConnector::new(builder.build());
//!
//! let mut client = postgres::Client::connect(
//! "host=localhost user=postgres sslmode=require",
//! connector,
//! )?;
//!
//! // ...
//! # Ok(())
//! # }
//! ``` //! ```
#![doc(html_root_url = "https://docs.rs/tokio-postgres-openssl/0.1.0-rc.1")] #![doc(html_root_url = "https://docs.rs/tokio-postgres-openssl/0.1.0-rc.1")]
#![warn(rust_2018_idioms, clippy::all, missing_docs)] #![warn(rust_2018_idioms, clippy::all, missing_docs)]