You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2026/03/18 10:51:01 UTC
(opendal-reqsign) branch xuanwo/default-provider-api-huaweicloud-obs created (now f028c4e)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a change to branch xuanwo/default-provider-api-huaweicloud-obs
in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
at f028c4e refactor(huaweicloud-obs): align default provider builder api
This branch includes the following new commits:
new f028c4e refactor(huaweicloud-obs): align default provider builder api
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(opendal-reqsign) 01/01: refactor(huaweicloud-obs): align default provider builder api
Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch xuanwo/default-provider-api-huaweicloud-obs
in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
commit f028c4e87c243a1ce7ed7072babf83f230b8c711
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Mar 18 18:50:41 2026 +0800
refactor(huaweicloud-obs): align default provider builder api
---
services/huaweicloud-obs/examples/chain_logging.rs | 4 +-
.../src/provide_credential/default.rs | 45 +++++++++++++++++++++-
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/services/huaweicloud-obs/examples/chain_logging.rs b/services/huaweicloud-obs/examples/chain_logging.rs
index 0e8d54f..fb288e2 100644
--- a/services/huaweicloud-obs/examples/chain_logging.rs
+++ b/services/huaweicloud-obs/examples/chain_logging.rs
@@ -94,7 +94,9 @@ async fn main() -> Result<()> {
))
.push(LoggingProvider::new(
"Default",
- DefaultCredentialProvider::new(),
+ DefaultCredentialProvider::builder()
+ .env(EnvCredentialProvider::new())
+ .build(),
));
info!("Starting credential resolution...");
diff --git a/services/huaweicloud-obs/src/provide_credential/default.rs b/services/huaweicloud-obs/src/provide_credential/default.rs
index 403cd1b..2fc74a4 100644
--- a/services/huaweicloud-obs/src/provide_credential/default.rs
+++ b/services/huaweicloud-obs/src/provide_credential/default.rs
@@ -77,8 +77,20 @@ impl DefaultCredentialProvider {
/// Builder for `DefaultCredentialProvider`.
///
-/// Use `env(...)` to customize the environment provider or `no_env()` to
-/// remove it from the chain, then call `build()`.
+/// Use `env(...)` to set the environment slot or `no_env()` to remove it from
+/// the chain, then call `build()`.
+///
+/// # Examples
+///
+/// ```no_run
+/// use reqsign_huaweicloud_obs::{DefaultCredentialProvider, EnvCredentialProvider};
+///
+/// let provider = DefaultCredentialProvider::builder()
+/// .env(EnvCredentialProvider::new())
+/// .build();
+///
+/// let provider_without_env = DefaultCredentialProvider::builder().no_env().build();
+/// ```
pub struct DefaultCredentialProviderBuilder {
env: Option<EnvCredentialProvider>,
}
@@ -176,6 +188,35 @@ mod tests {
assert!(credential.is_none());
}
+ #[tokio::test]
+ async fn test_builder_env_readds_provider_after_no_env() {
+ let ctx = Context::new()
+ .with_file_read(TokioFileRead)
+ .with_http_send(ReqwestHttpSend::default());
+ let ctx = ctx.with_env(StaticEnv {
+ home_dir: None,
+ envs: HashMap::from_iter([
+ (
+ HUAWEI_CLOUD_ACCESS_KEY_ID.to_string(),
+ "access_key_id".to_string(),
+ ),
+ (
+ HUAWEI_CLOUD_SECRET_ACCESS_KEY.to_string(),
+ "secret_access_key".to_string(),
+ ),
+ ]),
+ });
+
+ let loader = DefaultCredentialProvider::builder()
+ .no_env()
+ .env(EnvCredentialProvider::new())
+ .build();
+ let credential = loader.provide_credential(&ctx).await.unwrap().unwrap();
+
+ assert_eq!("access_key_id", credential.access_key_id);
+ assert_eq!("secret_access_key", credential.secret_access_key);
+ }
+
#[tokio::test]
async fn test_default_loader_with_env() {
let ctx = Context::new()