Skip to content

Commit

Permalink
chore: align the token method semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
yjhmelody committed Aug 24, 2024
1 parent c152360 commit b488139
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions core/src/services/github/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/http/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions core/src/services/vercel_blob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -129,7 +130,7 @@ impl Builder for VercelBlobBuilder {
Ok(VercelBlobBackend {
core: Arc::new(VercelBlobCore {
root,
token: self.config.token.clone(),
token,
client,
}),
})
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/vercel_blob/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct VercelBlobConfig {
/// All operations will happen under this root.
pub root: Option<String>,
/// vercel blob token.
pub token: String,
pub token: Option<String>,
}

impl Debug for VercelBlobConfig {
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/webdav/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b488139

Please sign in to comment.