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/oss): remove unused builder prop allow_anonymous #1913

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
11 changes: 0 additions & 11 deletions core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ pub struct OssBuilder {
access_key_id: Option<String>,
access_key_secret: Option<String>,

allow_anonymous: bool,

http_client: Option<HttpClient>,
}

Expand Down Expand Up @@ -206,12 +204,6 @@ impl OssBuilder {
self
}

/// Anonymously access the bucket.
pub fn allow_anonymous(&mut self) -> &mut Self {
self.allow_anonymous = true;
self
}

/// Specify the http client that used by this service.
///
/// # Notes
Expand Down Expand Up @@ -278,9 +270,6 @@ impl Builder for OssBuilder {
map.get("access_key_id").map(|v| builder.access_key_id(v));
map.get("access_key_secret")
.map(|v| builder.access_key_secret(v));
map.get("allow_anonymous")
.filter(|v| *v == "on" || *v == "true")
.map(|_| builder.allow_anonymous());

builder
}
Expand Down
23 changes: 15 additions & 8 deletions core/src/services/oss/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,37 @@ impl Debug for OssCore {
}

impl OssCore {
async fn load_credential(&self) -> Result<AliyunCredential> {
async fn load_credential(&self) -> Result<Option<AliyunCredential>> {
let cred = self
.loader
.load()
.await
.map_err(new_request_credential_error)?;

if let Some(cred) = cred {
Ok(cred)
Ok(Some(cred))
} else {
Err(Error::new(
ErrorKind::ConfigInvalid,
"no valid credential found",
))
Ok(None)
}
}

pub async fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
let cred = self.load_credential().await?;
let cred = if let Some(cred) = self.load_credential().await? {
cred
} else {
return Ok(());
};

self.signer.sign(req, &cred).map_err(new_request_sign_error)
}

pub async fn sign_query<T>(&self, req: &mut Request<T>, duration: Duration) -> Result<()> {
let cred = self.load_credential().await?;
let cred = if let Some(cred) = self.load_credential().await? {
cred
} else {
return Ok(());
};

self.signer
.sign_query(req, duration, &cred)
.map_err(new_request_sign_error)
Expand Down