From fe833ee98a5e67944d6831e2950140691574f793 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 11 Apr 2023 19:14:01 +0800 Subject: [PATCH 1/2] feat(services/gcs): Add customed token loader support Signed-off-by: Xuanwo --- Cargo.lock | 4 ++-- core/Cargo.toml | 2 +- core/src/services/gcs/backend.rs | 24 +++++++++--------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4c0a267210..bf9603c4cbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2252,7 +2252,7 @@ dependencies = [ "rand 0.8.5", "redis", "reqsign 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", - "reqsign 0.8.5 (git+https://github.com/Xuanwo/reqsign?rev=c1e44223a984a612b63c80ee8092f0c089ff62bd)", + "reqsign 0.8.5 (git+https://github.com/Xuanwo/reqsign?rev=877292a171bfec9593df27cb4ec94676e77a9d57)", "reqwest", "rocksdb", "serde", @@ -3165,7 +3165,7 @@ dependencies = [ [[package]] name = "reqsign" version = "0.8.5" -source = "git+https://github.com/Xuanwo/reqsign?rev=c1e44223a984a612b63c80ee8092f0c089ff62bd#c1e44223a984a612b63c80ee8092f0c089ff62bd" +source = "git+https://github.com/Xuanwo/reqsign?rev=877292a171bfec9593df27cb4ec94676e77a9d57#877292a171bfec9593df27cb4ec94676e77a9d57" dependencies = [ "anyhow", "async-trait", diff --git a/core/Cargo.toml b/core/Cargo.toml index de7dcbae13f..1f741e0e6a8 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -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", diff --git a/core/src/services/gcs/backend.rs b/core/src/services/gcs/backend.rs index 8a2e8fc2cb9..ae7a572aeb9 100644 --- a/core/src/services/gcs/backend.rs +++ b/core/src/services/gcs/backend.rs @@ -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; @@ -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, @@ -111,7 +112,7 @@ pub struct GcsBuilder { credential_path: Option, http_client: Option, - signer: Option>, + customed_token_loader: Option>, } impl GcsBuilder { @@ -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 load used by this service. + pub fn customed_token_loader(&mut self, token_load: Box) -> &mut Self { + self.customed_token_loader = Some(token_load); self } } @@ -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"); From 5d04781b78d01df9b1cec807ceb5cb5dd4bbeba7 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 11 Apr 2023 19:28:10 +0800 Subject: [PATCH 2/2] Update core/src/services/gcs/backend.rs Co-authored-by: Suyan --- core/src/services/gcs/backend.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/services/gcs/backend.rs b/core/src/services/gcs/backend.rs index ae7a572aeb9..bca412fa290 100644 --- a/core/src/services/gcs/backend.rs +++ b/core/src/services/gcs/backend.rs @@ -195,7 +195,7 @@ impl GcsBuilder { self } - /// Specify the customed token load used by this service. + /// Specify the customed token loader used by this service. pub fn customed_token_loader(&mut self, token_load: Box) -> &mut Self { self.customed_token_loader = Some(token_load); self