mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
* refactor(messages): take the provider client from the injected HTTP pool The messages route kept its own process-wide reqwest client, so it ignored ssl_verify, CA bundles, client certs, proxies and every other setting that litellm-http resolves. The machine now takes the HttpClientPool and the call's HttpClientConfig, as OCR does, and the bridge passes its shared pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(http): hand out an owned Client and move chat, audio and OIDC onto the pool HttpClientPool now returns litellm_http::Client, a newtype only crates/http can build, so every provider client carries the resolved TLS, proxy and timeout settings. Chat completions and audio transcription drop their process-wide reqwest clients and take the pool and call config like messages; their 600s ceiling moves to the request. OidcResolver takes its client instead of building one, and the bridge hands it the pooled one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(secrets): build Google, Azure and CyberArk manager clients from the pool The native secret managers built bare reqwest clients, so they ignored the host's TLS and proxy settings. load_native_manager now takes the pool and the host config and hands each manager a pooled client. CyberArk's CYBERARK_SSL_VERIFY and CYBERARK_CLIENT_CERT/KEY become an override on the host config instead of a hand-built client. To express a certificate and key in separate files, HttpClientConfig::client_certificate is now a ClientIdentity that is either one PEM or a split pair. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(clippy): only crates/http may build a reqwest client Fence reqwest::Client, ClientBuilder and the TLS builder methods with disallowed-types and disallowed-methods so new code takes a litellm_http::Client from the pool. crates/http is exempt as the one place clients are built, and testkit as a dev-only installer. Tests move to litellm_http::Client::plain_for_test or a pooled client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(secrets-cyberark): keep verifying certificates when the host disables it Python hands CyberArk its own ssl_verify, which wins over the global setting, so CYBERARK_SSL_VERIFY unset or true still verifies even when the host sets ssl_verify false. The pooled client copied the host's Disabled and would send the API key unverified; fall back to the built-in roots instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(python-bridge): treat a missing litellm package as no host HTTP settings Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
143 lines
5 KiB
Rust
143 lines
5 KiB
Rust
#![cfg(feature = "hashicorp")]
|
|
|
|
#[tokio::test]
|
|
async fn hashicorp_handler_resolves_found_missing_and_failed_values() {
|
|
use std::sync::Arc;
|
|
|
|
use litellm_core_utils::settings::Lookup;
|
|
use litellm_secrets::{
|
|
Error, FailurePolicy, KeyManagementSettings, SecretManager, SecretManagerState,
|
|
SecretResolver, hashicorp::HashicorpVault, hashicorp::HashicorpVaultConfig,
|
|
};
|
|
use wiremock::{
|
|
Mock, MockServer, ResponseTemplate,
|
|
matchers::{method, path},
|
|
};
|
|
|
|
let found_server = MockServer::start().await;
|
|
Mock::given(method("GET"))
|
|
.and(path("/v1/secret/data/KEY"))
|
|
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
|
"data": {
|
|
"data": {"key": "remote"},
|
|
"metadata": {
|
|
"created_time": "",
|
|
"deletion_time": "",
|
|
"custom_metadata": null,
|
|
"destroyed": false,
|
|
"version": 1
|
|
}
|
|
},
|
|
"lease_id": "",
|
|
"lease_duration": 0,
|
|
"renewable": false,
|
|
"request_id": "",
|
|
"warnings": null,
|
|
"wrap_info": null
|
|
})))
|
|
.mount(&found_server)
|
|
.await;
|
|
let found_environment: Arc<dyn Lookup + Send + Sync> = Arc::new({
|
|
let address = found_server.uri();
|
|
move |name: &str| match name {
|
|
"HCP_VAULT_ADDR" => Some(address.clone()),
|
|
"HCP_VAULT_TOKEN" => Some("token".into()),
|
|
_ => None,
|
|
}
|
|
});
|
|
let found_config = HashicorpVaultConfig::from_environment(found_environment.as_ref()).unwrap();
|
|
let found_manager = HashicorpVault::from_config(found_config, true).unwrap();
|
|
let found_resolver = SecretResolver::new_python_compatible(
|
|
Arc::new(SecretManagerState::new(
|
|
SecretManager::HashicorpVault(found_manager),
|
|
KeyManagementSettings {
|
|
hosted_keys: Some(vec!["KEY".into()]),
|
|
..Default::default()
|
|
},
|
|
)),
|
|
Arc::new(|_: &str| None),
|
|
litellm_secrets::OidcResolver::new(litellm_http::Client::plain_for_test()),
|
|
);
|
|
assert_eq!(
|
|
found_resolver
|
|
.get_secret_str("KEY", None)
|
|
.await
|
|
.unwrap()
|
|
.unwrap()
|
|
.expose(),
|
|
"remote"
|
|
);
|
|
|
|
let missing_server = MockServer::start().await;
|
|
Mock::given(method("GET"))
|
|
.respond_with(
|
|
ResponseTemplate::new(404).set_body_json(serde_json::json!({"errors": ["missing"]})),
|
|
)
|
|
.mount(&missing_server)
|
|
.await;
|
|
let missing_environment: Arc<dyn Lookup + Send + Sync> = Arc::new({
|
|
let address = missing_server.uri();
|
|
move |name: &str| match name {
|
|
"HCP_VAULT_ADDR" => Some(address.clone()),
|
|
"HCP_VAULT_TOKEN" => Some("token".into()),
|
|
_ => None,
|
|
}
|
|
});
|
|
let missing_config =
|
|
HashicorpVaultConfig::from_environment(missing_environment.as_ref()).unwrap();
|
|
let missing_manager = HashicorpVault::from_config(missing_config, true).unwrap();
|
|
let missing_state = SecretManagerState::new(
|
|
SecretManager::HashicorpVault(missing_manager),
|
|
KeyManagementSettings {
|
|
hosted_keys: Some(vec!["KEY".into()]),
|
|
..Default::default()
|
|
},
|
|
);
|
|
let missing = litellm_secrets::get_secret_from_manager(
|
|
missing_state.backend().unwrap(),
|
|
"KEY",
|
|
missing_state.settings().unwrap(),
|
|
&|_: &str| None,
|
|
)
|
|
.await
|
|
.unwrap();
|
|
assert!(missing.is_none());
|
|
|
|
let failed_server = MockServer::start().await;
|
|
Mock::given(method("GET"))
|
|
.respond_with(
|
|
ResponseTemplate::new(500).set_body_json(serde_json::json!({"errors": ["failed"]})),
|
|
)
|
|
.mount(&failed_server)
|
|
.await;
|
|
let failed_environment: Arc<dyn Lookup + Send + Sync> = Arc::new({
|
|
let address = failed_server.uri();
|
|
move |name: &str| match name {
|
|
"HCP_VAULT_ADDR" => Some(address.clone()),
|
|
"HCP_VAULT_TOKEN" => Some("token".into()),
|
|
_ => None,
|
|
}
|
|
});
|
|
let failed_config =
|
|
HashicorpVaultConfig::from_environment(failed_environment.as_ref()).unwrap();
|
|
let failed_manager = HashicorpVault::from_config(failed_config, true).unwrap();
|
|
let failed_state = SecretManagerState::new(
|
|
SecretManager::HashicorpVault(failed_manager),
|
|
KeyManagementSettings {
|
|
hosted_keys: Some(vec!["KEY".into()]),
|
|
..Default::default()
|
|
},
|
|
);
|
|
let failed_resolver = SecretResolver::new_python_compatible(
|
|
Arc::new(failed_state),
|
|
Arc::new(|_: &str| None),
|
|
litellm_secrets::OidcResolver::new(litellm_http::Client::plain_for_test()),
|
|
)
|
|
.with_failure_policy(FailurePolicy::Propagate);
|
|
assert!(matches!(
|
|
failed_resolver.get_secret_str("KEY", None).await,
|
|
Err(Error::Hashicorp(
|
|
litellm_secrets::hashicorp::Error::Status { status: 500 }
|
|
))
|
|
));
|
|
}
|