This commit is contained in:
2026-04-22 09:05:16 +02:00
parent a9d26750fa
commit e9bcca21cc
6 changed files with 777 additions and 50 deletions

View File

@@ -166,7 +166,7 @@ impl KbConfig {
Ok(())
}
/// Returns a named HTTP endpoint by reference.
/// Finds one HTTP endpoint by its logical name.
pub fn find_http_endpoint(
&self,
endpoint_name: &str,
@@ -216,9 +216,9 @@ impl KbConfig {
endpoint.name
)));
}
if endpoint.burst == 0 {
if endpoint.burst_capacity == 0 {
return Err(crate::KbError::Config(format!(
"http endpoint '{}' burst must be > 0",
"http endpoint '{}' burst_capacity must be > 0",
endpoint.name
)));
}
@@ -384,33 +384,58 @@ pub struct KbSolanaConfig {
/// HTTP endpoint configuration.
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct KbHttpEndpointConfig {
/// Stable internal endpoint name used by the application.
/// Logical endpoint name.
pub name: std::string::String,
/// Enables or disables the endpoint.
/// Whether this endpoint is enabled.
pub enabled: bool,
/// Provider name such as `solana-public`, `helius`, or `custom`.
/// Provider name.
pub provider: std::string::String,
/// Base HTTP RPC URL.
/// Base HTTP URL.
pub url: std::string::String,
/// Optional environment variable name used to resolve an API key later.
/// Optional environment variable name containing an API key.
pub api_key_env_var: std::option::Option<std::string::String>,
/// Logical roles assigned to this endpoint.
/// Allowed roles for this endpoint.
pub roles: std::vec::Vec<std::string::String>,
/// Allowed average request rate.
/// Requests per second allowed by the local limiter.
pub requests_per_second: u32,
/// Burst capacity for future rate-limiting.
pub burst: u32,
/// HTTP connect timeout in milliseconds.
/// Maximum local burst capacity.
pub burst_capacity: u32,
/// Connect timeout in milliseconds.
pub connect_timeout_ms: u64,
/// HTTP request timeout in milliseconds.
/// Total request timeout in milliseconds.
pub request_timeout_ms: u64,
/// Maximum idle pooled connections per host.
pub max_idle_connections_per_host: usize,
}
impl KbHttpEndpointConfig {
/// Returns the resolved endpoint URL.
/// Returns the resolved URL, replacing an `${ENV_VAR}` placeholder when
/// `api_key_env_var` is configured.
pub fn resolved_url(&self) -> Result<std::string::String, crate::KbError> {
kb_resolve_endpoint_url(&self.url, &self.api_key_env_var)
let env_var_name_option = self.api_key_env_var.as_ref();
let env_var_name = match env_var_name_option {
Some(env_var_name) => env_var_name,
None => {
return Ok(self.url.clone());
}
};
let api_key_result = std::env::var(env_var_name);
let api_key = match api_key_result {
Ok(api_key) => api_key,
Err(error) => {
return Err(crate::KbError::Config(format!(
"cannot resolve api key env var '{}' for http endpoint '{}': {}",
env_var_name, self.name, error
)));
}
};
let placeholder = format!("${{{}}}", env_var_name);
if self.url.contains(&placeholder) {
return Ok(self.url.replace(&placeholder, &api_key));
}
Ok(self.url.clone())
}
}