Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crates/switchyard-runner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ use crate::{
const SUPPORTED_SCHEMA_VERSION: u32 = 1;
const MAX_CONFIGURED_RETRIES: u32 = 10;

/// This function returns a deployment's declared credential variable names without reading their values.
/// It parses the deployment and checks its schema version before returning names from LLM and decision clients.
pub fn api_key_variables(source: &str) -> Result<BTreeSet<String>, RunnerError> {
let config: DeploymentConfig = toml::from_str(source).map_err(|_| {
RunnerError::configuration(
"Could not parse the server config to read credential references.",
)
})?;
if config.schema_version != SUPPORTED_SCHEMA_VERSION {
return Err(RunnerError::configuration(
"Unsupported server config schema version.",
));
}
let mut variables: BTreeSet<_> = config
.llm_clients
.values()
.filter_map(|client| client.api_key_env.clone())
.collect();
for client in config.decision_clients.values() {
let DecisionClientConfig::SystemOne { api_key_env, .. } = client;
variables.insert(api_key_env.clone());
}
if variables
.iter()
.any(|name| name.trim().is_empty() || name.contains(['\0', '=']))
{
return Err(RunnerError::configuration(
"Invalid credential environment variable name.",
));
}
Ok(variables)
}

type RunnerResult<T> = Result<T, RunnerError>;

pub(crate) fn load_runner(path: impl AsRef<Path>) -> RunnerResult<Runner> {
Expand Down
2 changes: 2 additions & 0 deletions crates/switchyard-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod provider_key_redactor;
mod route;
mod runner;

pub use config::api_key_variables;

pub use algorithm::{
AdvisorTriggerConfig, AlgorithmConfigError, AlgorithmSpec, CategoryModelConfig, ClassifierMode,
ClassifierPolicyConfig, DecisionJudgeRouteConfig, LlmClassifierRouteConfig,
Expand Down
Loading