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:49:19 UTC
(opendal-reqsign) branch main updated: feat: migrate huaweicloud-obs default credential provider API (#709)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
The following commit(s) were added to refs/heads/main by this push:
new 75decdb feat: migrate huaweicloud-obs default credential provider API (#709)
75decdb is described below
commit 75decdbd4899d5e06c3613ca1bae59ef85012ffc
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Mar 18 18:49:13 2026 +0800
feat: migrate huaweicloud-obs default credential provider API (#709)
This updates the Huawei Cloud OBS default credential provider to match
the repository's new builder API contract.
The builder now exposes explicit `env(...)` and `no_env()` slot
controls, removes the legacy `configure_*` and `disable_*(bool)` APIs,
and keeps removed slots out of the chain instead of re-enabling them
during `build()`.
---
.../src/provide_credential/default.rs | 60 +++++++++++++++-------
1 file changed, 41 insertions(+), 19 deletions(-)
diff --git a/services/huaweicloud-obs/src/provide_credential/default.rs b/services/huaweicloud-obs/src/provide_credential/default.rs
index 07b2f6e..403cd1b 100644
--- a/services/huaweicloud-obs/src/provide_credential/default.rs
+++ b/services/huaweicloud-obs/src/provide_credential/default.rs
@@ -77,36 +77,35 @@ impl DefaultCredentialProvider {
/// Builder for `DefaultCredentialProvider`.
///
-/// Use `configure_env` to customize environment loading and
-/// `disable_env(bool)` to control participation, then `build()` to create the provider.
-#[derive(Default)]
+/// Use `env(...)` to customize the environment provider or `no_env()` to
+/// remove it from the chain, then call `build()`.
pub struct DefaultCredentialProviderBuilder {
env: Option<EnvCredentialProvider>,
}
+impl Default for DefaultCredentialProviderBuilder {
+ fn default() -> Self {
+ Self {
+ env: Some(EnvCredentialProvider::default()),
+ }
+ }
+}
+
impl DefaultCredentialProviderBuilder {
/// Create a new builder with default state.
pub fn new() -> Self {
Self::default()
}
- /// Configure the environment credential provider.
- pub fn configure_env<F>(mut self, f: F) -> Self
- where
- F: FnOnce(EnvCredentialProvider) -> EnvCredentialProvider,
- {
- let p = self.env.take().unwrap_or_default();
- self.env = Some(f(p));
+ /// Set the environment credential provider.
+ pub fn env(mut self, provider: EnvCredentialProvider) -> Self {
+ self.env = Some(provider);
self
}
- /// Disable (true) or ensure enabled (false) the environment provider.
- pub fn disable_env(mut self, disable: bool) -> Self {
- if disable {
- self.env = None;
- } else if self.env.is_none() {
- self.env = Some(EnvCredentialProvider::new());
- }
+ /// Remove the environment credential provider from the chain.
+ pub fn no_env(mut self) -> Self {
+ self.env = None;
self
}
@@ -115,8 +114,6 @@ impl DefaultCredentialProviderBuilder {
let mut chain = ProvideCredentialChain::new();
if let Some(p) = self.env {
chain = chain.push(p);
- } else {
- chain = chain.push(EnvCredentialProvider::new());
}
DefaultCredentialProvider::with_chain(chain)
}
@@ -154,6 +151,31 @@ mod tests {
assert!(credential.is_none());
}
+ #[tokio::test]
+ async fn test_builder_no_env_removes_provider() {
+ 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().build();
+ let credential = loader.provide_credential(&ctx).await.unwrap();
+
+ assert!(credential.is_none());
+ }
+
#[tokio::test]
async fn test_default_loader_with_env() {
let ctx = Context::new()