Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
Make yup-oauth2 optional
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Nov 11, 2020
1 parent 3ad40f6 commit f7238d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ 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"
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"]
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ use std::{
},
time::{Duration, Instant},
};
#[cfg(feature = "yup-oauth2")]
use tonic::metadata::MetadataValue;
use tonic::{
metadata::MetadataValue,
transport::{Channel, ClientTlsConfig},
Request,
};
#[cfg(feature = "yup-oauth2")]
use yup_oauth2::authenticator::Authenticator;

pub mod proto {
Expand Down Expand Up @@ -248,11 +250,13 @@ pub trait Authorizer: Sync + Send + 'static {
async fn authorize<T: Send + Sync>(&self, request: &mut Request<T>) -> Result<(), Self::Error>;
}

#[cfg(feature = "yup-oauth2")]
pub struct YupAuthorizer {
authenticator: Authenticator<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>,
project_name: String,
}

#[cfg(feature = "yup-oauth2")]
impl YupAuthorizer {
pub async fn new(
credentials_path: impl AsRef<std::path::Path>,
Expand All @@ -272,6 +276,7 @@ impl YupAuthorizer {
}
}

#[cfg(feature = "yup-oauth2")]
#[async_trait]
impl Authorizer for YupAuthorizer {
type Error = Box<dyn std::error::Error + Send + Sync>;
Expand Down

0 comments on commit f7238d8

Please sign in to comment.