From adb59f4e560219a332a8f70549d581845d970a04 Mon Sep 17 00:00:00 2001 From: Yujong Lee Date: Tue, 22 Sep 2026 21:52:56 -0700 Subject: [PATCH] refactor(secrets): move Python dispatch into bridge --- .../crates/python-bridge/src/secrets/mod.rs | 1 + .../python-bridge/src/secrets/mutation.rs | 3 +- .../src/secrets/operations.rs} | 67 ++++++------------- .../python-bridge/src/secrets/provider.rs | 3 +- .../python-bridge/src/secrets/runtime.rs | 10 +-- litellm-rust/crates/secrets/src/lib.rs | 6 -- 6 files changed, 30 insertions(+), 60 deletions(-) rename litellm-rust/crates/{secrets/src/provider.rs => python-bridge/src/secrets/operations.rs} (80%) diff --git a/litellm-rust/crates/python-bridge/src/secrets/mod.rs b/litellm-rust/crates/python-bridge/src/secrets/mod.rs index 5a01cc48d62..f0ad98dbbd8 100644 --- a/litellm-rust/crates/python-bridge/src/secrets/mod.rs +++ b/litellm-rust/crates/python-bridge/src/secrets/mod.rs @@ -2,6 +2,7 @@ pub(crate) mod callback; pub(crate) mod config; mod error; mod mutation; +mod operations; mod provider; pub(crate) mod resolved; pub(crate) mod runtime; diff --git a/litellm-rust/crates/python-bridge/src/secrets/mutation.rs b/litellm-rust/crates/python-bridge/src/secrets/mutation.rs index 26b740a0d5a..9de2585e51a 100644 --- a/litellm-rust/crates/python-bridge/src/secrets/mutation.rs +++ b/litellm-rust/crates/python-bridge/src/secrets/mutation.rs @@ -1,5 +1,6 @@ +use super::operations::{PythonMutationError, PythonMutationResponse}; use litellm_host_python::to_py; -use litellm_secrets::{PythonMutationError, PythonMutationResponse, cyberark}; +use litellm_secrets::cyberark; use pyo3::{exceptions::PyValueError, prelude::*, types::PyDict}; pub(super) fn mutation_value( diff --git a/litellm-rust/crates/secrets/src/provider.rs b/litellm-rust/crates/python-bridge/src/secrets/operations.rs similarity index 80% rename from litellm-rust/crates/secrets/src/provider.rs rename to litellm-rust/crates/python-bridge/src/secrets/operations.rs index 592ba54cb55..d7b34a7639b 100644 --- a/litellm-rust/crates/secrets/src/provider.rs +++ b/litellm-rust/crates/python-bridge/src/secrets/operations.rs @@ -1,23 +1,21 @@ -#[cfg(any(feature = "hashicorp", feature = "cyberark"))] -use crate::Secret; -use crate::{Error, SecretManager}; use litellm_core_utils::settings::Lookup; +use litellm_secrets::Secret; +use litellm_secrets::{Error, SecretManager}; use litellm_secrets_types::{PythonSecretRead, SecretOperationContext}; -pub struct PythonReadRequest { +pub(super) struct PythonReadRequest { pub secret_name: String, pub primary_secret_name: Option, pub context: SecretOperationContext, pub synchronous: bool, } -pub async fn read_python_provider( +pub(super) async fn read_python_provider( manager: &SecretManager, request: &PythonReadRequest, _environment: &(dyn Lookup + Send + Sync), ) -> Result { match (manager, &request.context) { - #[cfg(feature = "aws")] (SecretManager::AwsSecretsManagerV2(client), SecretOperationContext::Aws(context)) => { client .read_provider_payload_for_python( @@ -30,7 +28,6 @@ pub async fn read_python_provider( .await .map_err(Error::from) } - #[cfg(feature = "hashicorp")] (SecretManager::HashicorpVault(client), SecretOperationContext::Hashicorp(context)) => { Ok(PythonSecretRead::Value( client @@ -40,7 +37,6 @@ pub async fn read_python_provider( .map(Secret::String), )) } - #[cfg(feature = "cyberark")] (SecretManager::Cyberark(client), SecretOperationContext::Cyberark(_)) => { Ok(PythonSecretRead::Value( client @@ -50,7 +46,6 @@ pub async fn read_python_provider( .map(Secret::String), )) } - #[cfg(feature = "google")] (SecretManager::GoogleSecretManager(client), SecretOperationContext::Google(_)) => client .get_secret_for_python(&request.secret_name) .await @@ -61,29 +56,24 @@ pub async fn read_python_provider( } #[derive(Debug)] -pub enum PythonMutationError { +pub(super) enum PythonMutationError { Unsupported, - #[cfg(feature = "hashicorp")] - Vault(Box), - #[cfg(feature = "cyberark")] + Vault(Box), CyberarkWrite { name: String, - failure: Box, + failure: Box, }, CurrentMissing(String), ReplacementMissing(String), ReplacementMismatch, } -pub async fn write_python_provider( +pub(super) async fn write_python_provider( manager: &SecretManager, name: &str, - value: &crate::SecretValue, + value: &litellm_secrets::SecretValue, ) -> Result { - #[cfg(not(feature = "cyberark"))] - let _ = (name, value); match manager { - #[cfg(feature = "cyberark")] SecretManager::Cyberark(client) => { client .write_for_python(name, value) @@ -98,21 +88,18 @@ pub async fn write_python_provider( } } -pub async fn delete_python_provider( +pub(super) async fn delete_python_provider( manager: &SecretManager, name: &str, ) -> Result { - #[cfg(not(feature = "cyberark"))] - let _ = name; match manager { - #[cfg(feature = "cyberark")] SecretManager::Cyberark(client) => { client .async_delete_secret(name, None) .await .map_err(|failure| PythonMutationError::CyberarkWrite { name: name.to_owned(), - failure: Box::new(litellm_secrets_cyberark::PythonWriteFailure { + failure: Box::new(litellm_secrets::cyberark::PythonWriteFailure { source: failure, request_url: None, authentication: false, @@ -127,18 +114,15 @@ pub async fn delete_python_provider( } } -pub async fn rotate_python_provider( +pub(super) async fn rotate_python_provider( manager: &SecretManager, current_name: &str, new_name: &str, - value: &crate::SecretValue, + value: &litellm_secrets::SecretValue, ) -> Result { - #[cfg(not(feature = "cyberark"))] - let _ = (current_name, new_name, value); match manager { - #[cfg(feature = "cyberark")] SecretManager::Cyberark(client) => { - use litellm_secrets_cyberark::PythonRotationFailure; + use litellm_secrets::cyberark::PythonRotationFailure; client .rotate_for_python(current_name, new_name, value) .await @@ -162,26 +146,21 @@ pub async fn rotate_python_provider( _ => Err(PythonMutationError::Unsupported), } } - -#[cfg(feature = "cyberark")] fn write_success(name: &str) -> serde_json::Value { serde_json::json!({"status": "success", "message": format!("Secret {name} written successfully")}) } -pub enum PythonMutationResponse { +pub(super) enum PythonMutationResponse { Value(serde_json::Value), Json(Vec), } -pub async fn write_python_provider_with_context( +pub(super) async fn write_python_provider_with_context( manager: &SecretManager, name: &str, - value: &crate::SecretValue, + value: &litellm_secrets::SecretValue, context: &litellm_secrets_types::SecretWriteContext, ) -> Result { - #[cfg(not(feature = "hashicorp"))] - let _ = context; - #[cfg(feature = "hashicorp")] if let (SecretManager::HashicorpVault(client), SecretOperationContext::Hashicorp(operation)) = (manager, &context.operation) { @@ -204,14 +183,11 @@ pub async fn write_python_provider_with_context( .map(PythonMutationResponse::Value) } -pub async fn delete_python_provider_with_context( +pub(super) async fn delete_python_provider_with_context( manager: &SecretManager, name: &str, context: &SecretOperationContext, ) -> Result { - #[cfg(not(feature = "hashicorp"))] - let _ = context; - #[cfg(feature = "hashicorp")] if let (SecretManager::HashicorpVault(client), SecretOperationContext::Hashicorp(context)) = (manager, context) { @@ -228,16 +204,13 @@ pub async fn delete_python_provider_with_context( .map(PythonMutationResponse::Value) } -pub async fn rotate_python_provider_with_context( +pub(super) async fn rotate_python_provider_with_context( manager: &SecretManager, current_name: &str, new_name: &str, - value: &crate::SecretValue, + value: &litellm_secrets::SecretValue, context: &SecretOperationContext, ) -> Result { - #[cfg(not(feature = "hashicorp"))] - let _ = context; - #[cfg(feature = "hashicorp")] if let (SecretManager::HashicorpVault(client), SecretOperationContext::Hashicorp(context)) = (manager, context) { diff --git a/litellm-rust/crates/python-bridge/src/secrets/provider.rs b/litellm-rust/crates/python-bridge/src/secrets/provider.rs index d5d4dca423e..568a0cd2228 100644 --- a/litellm-rust/crates/python-bridge/src/secrets/provider.rs +++ b/litellm-rust/crates/python-bridge/src/secrets/provider.rs @@ -1,6 +1,7 @@ use std::time::Duration; -use litellm_secrets::{KeyManagementSystem, PythonReadRequest, SecretValue}; +use super::operations::PythonReadRequest; +use litellm_secrets::{KeyManagementSystem, SecretValue}; use litellm_secrets_types::{ AwsOperationContext, CyberarkOperationContext, GoogleOperationContext, HashicorpOperationContext, SecretOperationContext, diff --git a/litellm-rust/crates/python-bridge/src/secrets/runtime.rs b/litellm-rust/crates/python-bridge/src/secrets/runtime.rs index f2730140f67..1a89130ee82 100644 --- a/litellm-rust/crates/python-bridge/src/secrets/runtime.rs +++ b/litellm-rust/crates/python-bridge/src/secrets/runtime.rs @@ -223,7 +223,7 @@ impl NativeSecretManager { true, )?; run_sync_value(py, async move { - litellm_secrets::read_python_provider(&backend, &request, &ProcessEnvironment) + super::operations::read_python_provider(&backend, &request, &ProcessEnvironment) .await .map_err(|error| PyValueError::new_err(error.to_string())) .and_then(|value| python_secret_value(value, &request.secret_name)) @@ -249,7 +249,7 @@ impl NativeSecretManager { false, )?; run_async_value(py, async move { - litellm_secrets::read_python_provider(&backend, &request, &ProcessEnvironment) + super::operations::read_python_provider(&backend, &request, &ProcessEnvironment) .await .map_err(|error| PyValueError::new_err(error.to_string())) .and_then(|value| python_secret_value(value, &request.secret_name)) @@ -300,7 +300,7 @@ impl NativeSecretManager { super::vault::ErrorContext::capture(py, self.configuration.system, timeout)?; run_async_value(py, async move { super::mutation::mutation_value( - litellm_secrets::write_python_provider_with_context( + super::operations::write_python_provider_with_context( &backend, &secret_name, &litellm_secrets::SecretValue::new(secret_value), @@ -329,7 +329,7 @@ impl NativeSecretManager { super::vault::ErrorContext::capture(py, self.configuration.system, timeout)?; run_async_value(py, async move { super::mutation::mutation_value( - litellm_secrets::delete_python_provider_with_context( + super::operations::delete_python_provider_with_context( &backend, &secret_name, &context, @@ -357,7 +357,7 @@ impl NativeSecretManager { super::vault::ErrorContext::capture(py, self.configuration.system, timeout)?; run_async_value(py, async move { super::mutation::mutation_value( - litellm_secrets::rotate_python_provider_with_context( + super::operations::rotate_python_provider_with_context( &backend, ¤t_secret_name, &new_secret_name, diff --git a/litellm-rust/crates/secrets/src/lib.rs b/litellm-rust/crates/secrets/src/lib.rs index e9a4279dbda..8d0f0561608 100644 --- a/litellm-rust/crates/secrets/src/lib.rs +++ b/litellm-rust/crates/secrets/src/lib.rs @@ -5,7 +5,6 @@ mod error; mod handler; mod native; mod oidc; -mod provider; mod resolver; pub mod source; mod state; @@ -18,11 +17,6 @@ pub use litellm_secrets_types::{ }; pub use native::load_native_manager; pub use oidc::{OidcProvider, OidcReference, OidcResolver}; -pub use provider::{ - PythonMutationError, PythonMutationResponse, PythonReadRequest, delete_python_provider, - delete_python_provider_with_context, read_python_provider, rotate_python_provider, - rotate_python_provider_with_context, write_python_provider, write_python_provider_with_context, -}; pub use resolver::{FailurePolicy, SecretResolver, normalize_nonempty_secret_str}; pub use state::{SecretManagerState, secret_manager_would_be_consulted};