Skip to content

Commit

Permalink
feat(obs): support loading credential from env (#2767)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Aug 3, 2023
1 parent 71dd3a5 commit f02d627
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ redis = { version = "0.23", features = [
"tokio-comp",
"connection-manager",
], optional = true }
reqsign = { version = "0.14.0", default-features = false, optional = true }
reqsign = { version = "0.14.1", default-features = false, optional = true }
reqwest = { version = "0.11.18", features = [
"stream",
], default-features = false }
Expand Down
20 changes: 13 additions & 7 deletions core/src/services/obs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,19 @@ impl Builder for ObsBuilder {
})?
};

let config = HuaweicloudObsConfig {
access_key_id: self.access_key_id.take(),
secret_access_key: self.secret_access_key.take(),
security_token: None,
};
let mut cfg = HuaweicloudObsConfig::default();
// Load cfg from env first.
cfg = cfg.from_env();

if let Some(v) = self.access_key_id.take() {
cfg.access_key_id = Some(v);
}

if let Some(v) = self.secret_access_key.take() {
cfg.secret_access_key = Some(v);
}

let cred_loader = HuaweicloudObsCredentialLoader::new(config);
let loader = HuaweicloudObsCredentialLoader::new(cfg);

// Set the bucket name in CanonicalizedResource.
// 1. If the bucket is bound to a user domain name, use the user domain name as the bucket name,
Expand Down Expand Up @@ -307,7 +313,7 @@ impl Builder for ObsBuilder {
root,
endpoint: format!("{}://{}", &scheme, &endpoint),
signer,
loader: cred_loader,
loader,
client,
write_min_size,
}),
Expand Down

0 comments on commit f02d627

Please sign in to comment.