Skip to content

Commit

Permalink
chore(tonic): Deprecate API when they only return None (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Nov 15, 2023
1 parent 15663f1 commit 7cb1cd2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tonic/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::metadata::{MetadataMap, MetadataValue};
#[cfg(feature = "transport")]
use crate::transport::server::TcpConnectInfo;
#[cfg(all(feature = "transport", feature = "tls"))]
use crate::transport::server::TlsConnectInfo;
#[cfg(feature = "transport")]
use crate::transport::{server::TcpConnectInfo, Certificate};
#[allow(deprecated)]
use crate::transport::Certificate;
use crate::Extensions;
#[cfg(feature = "transport")]
use std::sync::Arc;
Expand Down Expand Up @@ -207,6 +210,13 @@ impl<T> Request<T> {
/// This will return `None` if the `IO` type used
/// does not implement `Connected` or when using a unix domain socket.
/// This currently only works on the server side.
#[cfg_attr(
not(feature = "transport"),
deprecated(
since = "0.10.3",
note = "`remote_addr` only returns `None` without transport feature. This API will require transport feature.",
)
)]
pub fn local_addr(&self) -> Option<SocketAddr> {
#[cfg(feature = "transport")]
{
Expand Down Expand Up @@ -241,6 +251,13 @@ impl<T> Request<T> {
/// This will return `None` if the `IO` type used
/// does not implement `Connected` or when using a unix domain socket.
/// This currently only works on the server side.
#[cfg_attr(
not(feature = "transport"),
deprecated(
since = "0.10.3",
note = "`remote_addr` only returns `None` without transport feature. This API will require transport feature.",
)
)]
pub fn remote_addr(&self) -> Option<SocketAddr> {
#[cfg(feature = "transport")]
{
Expand Down Expand Up @@ -277,7 +294,15 @@ impl<T> Request<T> {
/// `Some` on the server side of the `transport` server with
/// TLS enabled connections.
#[cfg(feature = "transport")]
#[cfg_attr(
all(feature = "transport", not(feature = "tls")),
deprecated(
since = "0.10.3",
note = "`peer_certs` only returns `None` without tls feature. This API will require tls feature.",
)
)]
#[cfg_attr(docsrs, doc(cfg(feature = "transport")))]
#[allow(deprecated)]
pub fn peer_certs(&self) -> Option<Arc<Vec<Certificate>>> {
#[cfg(feature = "tls")]
{
Expand Down
1 change: 1 addition & 0 deletions tonic/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub use self::error::Error;
pub use self::server::Server;
#[doc(inline)]
pub use self::service::grpc_timeout::TimeoutExpired;
#[allow(deprecated)]
pub use self::tls::Certificate;
#[doc(inline)]
/// A deprecated re-export. Please use `tonic::server::NamedService` directly.
Expand Down
9 changes: 9 additions & 0 deletions tonic/src/transport/tls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
/// Represents a X509 certificate.
#[cfg_attr(
not(feature = "tls"),
deprecated(
since = "0.10.3",
note = "`Certificate` is used only by deprecated API without tls feature.",
)
)]
#[derive(Debug, Clone)]
pub struct Certificate {
pub(crate) pem: Vec<u8>,
Expand All @@ -13,6 +20,7 @@ pub struct Identity {
pub(crate) key: Vec<u8>,
}

#[allow(deprecated)]
impl Certificate {
/// Parse a PEM encoded X509 Certificate.
///
Expand All @@ -38,6 +46,7 @@ impl Certificate {
}
}

#[allow(deprecated)]
impl AsRef<[u8]> for Certificate {
fn as_ref(&self) -> &[u8] {
self.pem.as_ref()
Expand Down

0 comments on commit 7cb1cd2

Please sign in to comment.