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

chore: align the token method semantics #5045

Merged
merged 1 commit into from
Aug 24, 2024
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
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
Loading