Implementation:ArroyoSystems Arroyo Var Str
| Knowledge Sources | |
|---|---|
| Domains | Streaming, Configuration, Security |
| Last Updated | 2026-02-08 08:00 GMT |
Overview
Provides VarStr, a string type that supports environment variable substitution using the {{ VAR_NAME }} template syntax, used for secrets and configuration values.
Description
VarStr is a string wrapper that stores a raw template value and performs environment variable substitution on demand via the sub_env_vars() method. The substitution pattern uses double-brace syntax: {{ VARIABLE_NAME }} with optional whitespace inside the braces.
Key characteristics:
- The raw template string is stored and serialized as-is (no substitution during serialization).
- Environment variable resolution happens only when sub_env_vars() is called.
- Missing environment variables produce an error rather than a silent empty substitution.
- Multiple substitutions within a single string are supported.
- Implements Serialize, Deserialize (custom visitor-based), and JsonSchema (with format "var-str").
- The regex pattern
\{\{\s*(\w+)\s*}}is compiled once using OnceLock.
This type is used throughout Arroyo's connector configuration to allow users to reference secrets stored in environment variables (e.g., API keys, passwords) without embedding them in the configuration JSON.
Usage
Use VarStr for any configuration field that may contain sensitive values that should be sourced from environment variables at runtime.
Code Reference
Source Location
- Repository: ArroyoSystems_Arroyo
- File: crates/arroyo-rpc/src/var_str.rs
Signature
pub struct VarStr {
raw_val: String,
}
impl VarStr {
pub fn new(raw_val: String) -> Self;
pub fn sub_env_vars(&self) -> anyhow::Result<String>;
}
Import
use arroyo_rpc::var_str::VarStr;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| raw_val | String | Yes | Template string with optional {{ VAR }} placeholders |
Outputs
| Name | Type | Description |
|---|---|---|
| String | String | Resolved string with environment variables substituted |
| Error | anyhow::Error | Returned if a referenced environment variable is not found |
Usage Examples
use arroyo_rpc::var_str::VarStr;
// Direct value (no substitution needed)
let direct = VarStr::new("my-api-key".to_string());
assert_eq!(direct.sub_env_vars().unwrap(), "my-api-key");
// Environment variable substitution
std::env::set_var("KAFKA_PASSWORD", "secret123");
let templated = VarStr::new("{{ KAFKA_PASSWORD }}".to_string());
assert_eq!(templated.sub_env_vars().unwrap(), "secret123");
// Multiple substitutions
std::env::set_var("HOST", "kafka.example.com");
std::env::set_var("PORT", "9092");
let combined = VarStr::new("{{ HOST }}:{{ PORT }}".to_string());
assert_eq!(combined.sub_env_vars().unwrap(), "kafka.example.com:9092");