diff --git a/core/src/services/github/backend.rs b/core/src/services/github/backend.rs index d51bff52449..8bc8940c775 100644 --- a/core/src/services/github/backend.rs +++ b/core/src/services/github/backend.rs @@ -79,8 +79,9 @@ impl GithubBuilder { /// /// required. pub fn token(mut self, token: &str) -> Self { - self.config.token = Some(token.to_string()); - + if !token.is_empty() { + self.config.token = Some(token.to_string()); + } self } diff --git a/core/src/services/http/backend.rs b/core/src/services/http/backend.rs index 7908c2e58fd..8d80e5f2b51 100644 --- a/core/src/services/http/backend.rs +++ b/core/src/services/http/backend.rs @@ -97,7 +97,7 @@ impl HttpBuilder { /// default: no access token pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { - self.config.token = Some(token.to_owned()); + self.config.token = Some(token.to_string()); } self } diff --git a/core/src/services/vercel_blob/backend.rs b/core/src/services/vercel_blob/backend.rs index 35fdfdbcd1a..c2453fa5930 100644 --- a/core/src/services/vercel_blob/backend.rs +++ b/core/src/services/vercel_blob/backend.rs @@ -82,8 +82,9 @@ impl VercelBlobBuilder { /// Get from Vercel environment variable `BLOB_READ_WRITE_TOKEN`. /// It is required. pub fn token(mut self, token: &str) -> Self { - self.config.token = token.to_string(); - + if !token.is_empty() { + self.config.token = Some(token.to_string()); + } self } @@ -111,11 +112,11 @@ impl Builder for VercelBlobBuilder { debug!("backend use root {}", &root); // Handle token. - if self.config.token.is_empty() { + let Some(token) = self.config.token.clone() else { return Err(Error::new(ErrorKind::ConfigInvalid, "token is empty") .with_operation("Builder::build") .with_context("service", Scheme::VercelBlob)); - } + }; let client = if let Some(client) = self.http_client { client @@ -129,7 +130,7 @@ impl Builder for VercelBlobBuilder { Ok(VercelBlobBackend { core: Arc::new(VercelBlobCore { root, - token: self.config.token.clone(), + token, client, }), }) diff --git a/core/src/services/vercel_blob/config.rs b/core/src/services/vercel_blob/config.rs index 241ee039e6a..dc3d214d6fe 100644 --- a/core/src/services/vercel_blob/config.rs +++ b/core/src/services/vercel_blob/config.rs @@ -28,7 +28,7 @@ pub struct VercelBlobConfig { /// All operations will happen under this root. pub root: Option, /// vercel blob token. - pub token: String, + pub token: Option, } impl Debug for VercelBlobConfig { diff --git a/core/src/services/webdav/backend.rs b/core/src/services/webdav/backend.rs index e6f3b838b3f..66177f4dc92 100644 --- a/core/src/services/webdav/backend.rs +++ b/core/src/services/webdav/backend.rs @@ -99,7 +99,7 @@ impl WebdavBuilder { /// default: no access token pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { - self.config.token = Some(token.to_owned()); + self.config.token = Some(token.to_string()); } self }