pub struct ConfigClient { /* private fields */ }Expand description
Client for reading configuration values from the Smoo AI config server.
SMOODEV-975: now uses an Arc<TokenProvider>
to mint a JWT via OAuth2 client_credentials before each request. Pass
client_id + client_secret (or call ConfigClient::with_token_provider)
on construction.
Implementations§
Source§impl ConfigClient
impl ConfigClient
Sourcepub fn new(
base_url: &str,
client_id: &str,
client_secret: &str,
org_id: &str,
) -> Self
pub fn new( base_url: &str, client_id: &str, client_secret: &str, org_id: &str, ) -> Self
Create a new config client with explicit parameters.
SMOODEV-975: takes both client_id and client_secret to mint
OAuth tokens. The OAuth issuer URL is read from the
SMOOAI_CONFIG_AUTH_URL env var (or SMOOAI_AUTH_URL, or the
default https://auth.smoo.ai). Use Self::with_token_provider
for tests where you want to inject a stub provider.
Sourcepub fn with_environment(
base_url: &str,
client_id: &str,
client_secret: &str,
org_id: &str,
environment: &str,
) -> Self
pub fn with_environment( base_url: &str, client_id: &str, client_secret: &str, org_id: &str, environment: &str, ) -> Self
Create a new config client with an explicit default environment.
Sourcepub fn with_token_provider(
base_url: &str,
token_provider: SharedTokenProvider,
org_id: &str,
environment: &str,
) -> Self
pub fn with_token_provider( base_url: &str, token_provider: SharedTokenProvider, org_id: &str, environment: &str, ) -> Self
Construct a client that uses the provided TokenProvider.
Useful in tests to inject a stub provider that returns a fixed JWT without performing a real OAuth handshake, and for callers that want to share a single provider across multiple clients.
Sourcepub fn set_cache_ttl(&mut self, ttl: Option<Duration>)
pub fn set_cache_ttl(&mut self, ttl: Option<Duration>)
Set the cache TTL duration. None means cache never expires (manual invalidation only).
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a config client from environment variables.
SMOODEV-975: Reads SMOOAI_CONFIG_API_URL, SMOOAI_CONFIG_CLIENT_ID,
SMOOAI_CONFIG_CLIENT_SECRET (or the legacy SMOOAI_CONFIG_API_KEY),
SMOOAI_CONFIG_ORG_ID, and optionally SMOOAI_CONFIG_ENV
(defaults to “development”) and SMOOAI_CONFIG_AUTH_URL.
§Panics
Panics if any required environment variable is missing.
Sourcepub async fn get_value(
&mut self,
key: &str,
environment: Option<&str>,
) -> Result<Value, ConfigClientError>
pub async fn get_value( &mut self, key: &str, environment: Option<&str>, ) -> Result<Value, ConfigClientError>
Get a single config value.
Pass None for environment to use the default.
Sourcepub async fn get_all_values(
&mut self,
environment: Option<&str>,
) -> Result<HashMap<String, Value>, ConfigClientError>
pub async fn get_all_values( &mut self, environment: Option<&str>, ) -> Result<HashMap<String, Value>, ConfigClientError>
Get all config values for an environment.
Pass None for environment to use the default.
Sourcepub async fn evaluate_feature_flag(
&self,
key: &str,
context: Option<HashMap<String, Value>>,
environment: Option<&str>,
) -> Result<EvaluateFeatureFlagResponse, FeatureFlagEvaluationError>
pub async fn evaluate_feature_flag( &self, key: &str, context: Option<HashMap<String, Value>>, environment: Option<&str>, ) -> Result<EvaluateFeatureFlagResponse, FeatureFlagEvaluationError>
Evaluate a segment-aware feature flag on the server.
Unlike get_value, this is always a network call —
segment rules (percentage rollout, attribute matching, bucketing) live
server-side and the response depends on the context you pass. Callers
that don’t need segment evaluation should keep using get_value for the
static flag value.
§Arguments
key— Feature-flag key. URL-encoded before being placed in the path.context— Attributes the server’s segment rules may reference (e.g.{ "userId": ..., "plan": ... }).Noneis equivalent to an empty map. Values must be JSON-serializable — the server hashesbucketByvalues by their string representation, so numbers and booleans bucket stably across client rebuilds.environment— Environment name (defaults to the client’s default environment whenNone).
§Errors
FeatureFlagEvaluationError::NotFound— 404, flag not defined.FeatureFlagEvaluationError::ContextError— 400, bad context.FeatureFlagEvaluationError::Evaluation— other non-2xx status.FeatureFlagEvaluationError::Request— transport / parse failure.
Sourcepub fn get_cached_value(
&self,
key: &str,
environment: Option<&str>,
) -> Option<Value>
pub fn get_cached_value( &self, key: &str, environment: Option<&str>, ) -> Option<Value>
Read a value from the local cache only, without hitting the server.
Returns None when the key is absent or its TTL has expired. Used by
container mode’s sync getters and last-good fallback (SMOODEV-1494): on
a background HTTP refresh failure the previously-fetched value is served
from cache until the TTL hard-expires.
Sourcepub fn seed_cache(&mut self, key: &str, value: Value, environment: Option<&str>)
pub fn seed_cache(&mut self, key: &str, value: Value, environment: Option<&str>)
Seed a single value into the local cache (subject to the configured TTL) without a network round-trip.
Used by container mode’s env tier (SMOODEV-1494): when an explicit
process env override wins, the value is mirrored into the cache so a
later get_cached_value / sync read sees it.
Sourcepub fn invalidate_cache(&mut self)
pub fn invalidate_cache(&mut self)
Clear the entire local cache.
Sourcepub fn invalidate_cache_for_environment(&mut self, environment: &str)
pub fn invalidate_cache_for_environment(&mut self, environment: &str)
Clear cached values for a specific environment.