Skip to main content

ConfigClient

Struct ConfigClient 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn set_cache_ttl(&mut self, ttl: Option<Duration>)

Set the cache TTL duration. None means cache never expires (manual invalidation only).

Source

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.

Source

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.

Source

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.

Source

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": ... }). None is equivalent to an empty map. Values must be JSON-serializable — the server hashes bucketBy values by their string representation, so numbers and booleans bucket stably across client rebuilds.
  • environment — Environment name (defaults to the client’s default environment when None).
§Errors
Source

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.

Source

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.

Source

pub fn invalidate_cache(&mut self)

Clear the entire local cache.

Source

pub fn invalidate_cache_for_environment(&mut self, environment: &str)

Clear cached values for a specific environment.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more