Skip to content

Commit

Permalink
feat(services/oss): remove unused builder prop allow_anonymous (#1913)
Browse files Browse the repository at this point in the history
chore(services/oss): remove unused builder prop allow_anonymous

Signed-off-by: suyanhanx <suyanhanx@gmail.com>
  • Loading branch information
suyanhanx authored Apr 11, 2023
1 parent 42ad2dd commit 8c6d502
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
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

0 comments on commit 8c6d502

Please sign in to comment.