From d2869ba66fa334ebc7d802fa8e58746813ccb3c6 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 10 Nov 2020 17:34:56 +0100 Subject: [PATCH] Make yup-oauth2 optional --- Cargo.toml | 7 ++++--- src/lib.rs | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd696ff53..4ebe1f40d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ futures = "0.3" hex = "0.4" http = "0.2" hyper = "0.13" -hyper-rustls = "0.20" +hyper-rustls = { version = "0.20", optional = true } log = "0.4" opentelemetry = "0.8" prost = "0.6" @@ -37,9 +37,10 @@ prost-types = "0.6" rustls = "0.18" tonic = { version = "0.3.1", features = ["transport", "tls"] } tokio = { version = "0.2", optional = true } -yup-oauth2 = "4.1" +yup-oauth2 = { version = "4.1", optional = true } webpki-roots = "0.20" [features] -default = [] +default = ["yup-authorizer"] +yup-authorizer = ["hyper-rustls", "yup-oauth2"] tokio_adapter = ["tokio"] diff --git a/src/lib.rs b/src/lib.rs index a797ebc4e..dc7c8b0d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,11 +36,13 @@ use std::{ }, time::{Duration, Instant}, }; +#[cfg(feature = "yup-authorizer")] +use tonic::metadata::MetadataValue; use tonic::{ - metadata::MetadataValue, transport::{Channel, ClientTlsConfig}, Request, }; +#[cfg(feature = "yup-authorizer")] use yup_oauth2::authenticator::Authenticator; pub mod proto { @@ -248,11 +250,13 @@ pub trait Authorizer: Sync + Send + 'static { async fn authorize(&self, request: &mut Request) -> Result<(), Self::Error>; } +#[cfg(feature = "yup-authorizer")] pub struct YupAuthorizer { authenticator: Authenticator>, project_name: String, } +#[cfg(feature = "yup-authorizer")] impl YupAuthorizer { pub async fn new( credentials_path: impl AsRef, @@ -272,6 +276,7 @@ impl YupAuthorizer { } } +#[cfg(feature = "yup-authorizer")] #[async_trait] impl Authorizer for YupAuthorizer { type Error = Box;