Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transport): Remove with_rustls for tls config #188

Merged
merged 1 commit into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/src/gcp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let certs = tokio::fs::read("tonic-examples/data/gcp/roots.pem").await?;

let tls_config = ClientTlsConfig::with_rustls()
let tls_config = ClientTlsConfig::new()
.ca_certificate(Certificate::from_pem(certs.as_slice()))
.domain_name("pubsub.googleapis.com");

Expand Down
2 changes: 1 addition & 1 deletion examples/src/tls/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pem = tokio::fs::read("tonic-examples/data/tls/ca.pem").await?;
let ca = Certificate::from_pem(pem);

let tls = ClientTlsConfig::with_rustls()
let tls = ClientTlsConfig::new()
.ca_certificate(ca)
.domain_name("example.com");

Expand Down
2 changes: 1 addition & 1 deletion examples/src/tls/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = EchoServer::default();

Server::builder()
.tls_config(ServerTlsConfig::with_rustls().identity(identity))
.tls_config(ServerTlsConfig::new().identity(identity))
.add_service(pb::echo_server::EchoServer::new(server))
.serve(addr)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/tls_client_auth/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client_key = tokio::fs::read("tonic-examples/data/tls/client1.key").await?;
let client_identity = Identity::from_pem(client_cert, client_key);

let tls = ClientTlsConfig::with_rustls()
let tls = ClientTlsConfig::new()
.domain_name("localhost")
.ca_certificate(server_root_ca_cert)
.identity(client_identity);
Expand Down
2 changes: 1 addition & 1 deletion examples/src/tls_client_auth/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse().unwrap();
let server = EchoServer::default();

let tls = ServerTlsConfig::with_rustls()
let tls = ServerTlsConfig::new()
.identity(server_identity)
.client_ca_root(client_ca_cert);

Expand Down
2 changes: 1 addition & 1 deletion interop/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pem = tokio::fs::read("interop/data/ca.pem").await?;
let ca = Certificate::from_pem(pem);
endpoint = endpoint.tls_config(
ClientTlsConfig::with_rustls()
ClientTlsConfig::new()
.ca_certificate(ca)
.domain_name("foo.test.google.fr"),
);
Expand Down
2 changes: 1 addition & 1 deletion interop/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let key = tokio::fs::read("interop/data/server1.key").await?;
let identity = Identity::from_pem(cert, key);

builder = builder.tls_config(ServerTlsConfig::with_rustls().identity(identity));
builder = builder.tls_config(ServerTlsConfig::new().identity(identity));
}

let test_service = server::TestServiceServer::new(server::TestService::default());
Expand Down
1 change: 1 addition & 0 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl Endpoint {

/// Configures TLS for the endpoint.
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
pub fn tls_config(self, tls_config: ClientTlsConfig) -> Self {
Endpoint {
tls: Some(tls_config.tls_connector(self.uri.clone()).unwrap()),
Expand Down
1 change: 1 addition & 0 deletions tonic/src/transport/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod endpoint;
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
mod tls;

pub use endpoint::Endpoint;
Expand Down
3 changes: 2 additions & 1 deletion tonic/src/transport/channel/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt;

/// Configures TLS settings for endpoints.
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
#[derive(Clone)]
pub struct ClientTlsConfig {
domain: Option<String>,
Expand All @@ -29,7 +30,7 @@ impl fmt::Debug for ClientTlsConfig {
#[cfg(feature = "tls")]
impl ClientTlsConfig {
/// Creates a new `ClientTlsConfig` using Rustls.
pub fn with_rustls() -> Self {
pub fn new() -> Self {
ClientTlsConfig {
domain: None,
cert: None,
Expand Down
2 changes: 2 additions & 0 deletions tonic/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ pub use self::tls::{Certificate, Identity};
pub use hyper::Body;

#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
pub use self::channel::ClientTlsConfig;
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
pub use self::server::ServerTlsConfig;

pub(crate) use self::error::ErrorKind;
2 changes: 2 additions & 0 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod incoming;
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
mod tls;

#[cfg(feature = "tls")]
Expand Down Expand Up @@ -96,6 +97,7 @@ impl Server {
impl Server {
/// Configure TLS for this server.
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
pub fn tls_config(self, tls_config: ServerTlsConfig) -> Self {
Server {
tls: Some(tls_config.tls_acceptor().unwrap()),
Expand Down
3 changes: 2 additions & 1 deletion tonic/src/transport/server/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt;

/// Configures TLS settings for servers.
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
#[derive(Clone)]
pub struct ServerTlsConfig {
identity: Option<Identity>,
Expand All @@ -23,7 +24,7 @@ impl fmt::Debug for ServerTlsConfig {
#[cfg(feature = "tls")]
impl ServerTlsConfig {
/// Creates a new `ServerTlsConfig`.
pub fn with_rustls() -> Self {
pub fn new() -> Self {
ServerTlsConfig {
identity: None,
client_ca_root: None,
Expand Down