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

feat(services/gcs): Add customed token loader support #1908

Merged
merged 2 commits into from
Apr 11, 2023
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ redis = { version = "0.22", features = [
], optional = true }
# NOTE: we keep this for service migration one by one. And finally we will replace reqsign by v0.9.
reqsign = "0.8.5"
reqsign_0_9 = { package = "reqsign", git = "https://github.com/Xuanwo/reqsign", rev = "c1e44223a984a612b63c80ee8092f0c089ff62bd" }
reqsign_0_9 = { package = "reqsign", git = "https://github.com/Xuanwo/reqsign", rev = "877292a171bfec9593df27cb4ec94676e77a9d57" }
reqwest = { version = "0.11.13", features = [
"multipart",
"stream",
Expand Down
24 changes: 9 additions & 15 deletions core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use http::StatusCode;
use log::debug;
use reqsign_0_9::GoogleCredentialLoader;
use reqsign_0_9::GoogleSigner;
use reqsign_0_9::GoogleTokenLoad;
use reqsign_0_9::GoogleTokenLoader;
use serde::Deserialize;
use serde_json;
Expand Down Expand Up @@ -91,7 +92,7 @@ const DEFAULT_GCS_SCOPE: &str = "https://www.googleapis.com/auth/devstorage.read
/// Ok(())
/// }
/// ```
#[derive(Clone, Default)]
#[derive(Default)]
pub struct GcsBuilder {
/// root URI, all operations happens under `root`
root: Option<String>,
Expand All @@ -111,7 +112,7 @@ pub struct GcsBuilder {
credential_path: Option<String>,

http_client: Option<HttpClient>,
signer: Option<Arc<GoogleSigner>>,
customed_token_loader: Option<Box<dyn GoogleTokenLoad>>,
}

impl GcsBuilder {
Expand Down Expand Up @@ -194,19 +195,9 @@ impl GcsBuilder {
self
}

/// Specify the signer directly instead of building by OpenDAL.
///
/// If signer is specified, the following settings will not be used
/// any more:
///
/// - `scope`
/// - `service_account`
/// - `credential`
/// - `credential_path`
///
/// PLEASE USE THIS API CAREFULLY.
pub fn signer(&mut self, signer: GoogleSigner) -> &mut Self {
self.signer = Some(Arc::new(signer));
/// Specify the customed token loader used by this service.
pub fn customed_token_loader(&mut self, token_load: Box<dyn GoogleTokenLoad>) -> &mut Self {
self.customed_token_loader = Some(token_load);
self
}
}
Expand Down Expand Up @@ -295,6 +286,9 @@ impl Builder for GcsBuilder {
if let Ok(Some(cred)) = cred_loader.load() {
token_loader = token_loader.with_credentials(cred)
}
if let Some(loader) = self.customed_token_loader.take() {
token_loader = token_loader.with_customed_token_loader(loader)
}

let signer = GoogleSigner::new("storage");

Expand Down