ClientConfig

Struct ClientConfig 

Source
pub struct ClientConfig {
    pub app_id: String,
    pub cluster: String,
    pub cache_dir: Option<String>,
    pub config_server: String,
    pub secret: Option<String>,
    pub label: Option<String>,
    pub ip: Option<String>,
    pub allow_insecure_https: Option<bool>,
    pub cache_ttl: Option<u64>,
}
Expand description

Configuration settings for the Apollo client.

This struct contains all the necessary information to connect to and interact with an Apollo Configuration Center. It supports various configuration options including authentication, caching, and grayscale release targeting.

§Required Fields

  • app_id: Your application identifier in Apollo
  • config_server: The Apollo configuration server URL
  • cluster: The cluster name (typically “default”)

§Optional Fields

  • secret: Authentication secret key for secure access
  • cache_dir: Local cache directory (native targets only)
  • label: Labels for grayscale release targeting
  • ip: IP address for grayscale release targeting
  • allow_insecure_https: Whether to allow insecure HTTPS connections (self-signed certificates)

§Examples

§Minimal Configuration

use apollo_rust_client::client_config::ClientConfig;

let config = ClientConfig {
    app_id: "my-app".to_string(),
    config_server: "http://apollo-server:8080".to_string(),
    cluster: "default".to_string(),
    secret: None,
    cache_dir: None,
    label: None,
    ip: None,
    allow_insecure_https: None,
    #[cfg(not(target_arch = "wasm32"))]
    cache_ttl: None,
};

§Full Configuration

use apollo_rust_client::client_config::ClientConfig;

let config = ClientConfig {
    app_id: "my-app".to_string(),
    config_server: "http://apollo-server:8080".to_string(),
    cluster: "production".to_string(),
    secret: Some("secret-key".to_string()),
    cache_dir: Some("/custom/cache/path".to_string()),
    label: Some("canary,beta".to_string()),
    ip: Some("192.168.1.100".to_string()),
    allow_insecure_https: Some(true), // Allow self-signed certificates
    #[cfg(not(target_arch = "wasm32"))]
    cache_ttl: None,
};

Fields§

§app_id: String

The unique identifier for your application in Apollo.

This is used to identify which application’s configuration to retrieve from the Apollo Configuration Center.

§cluster: String

The cluster name to connect to.

Clusters allow you to organize different environments or deployment groups. Common values include “default”, “production”, “staging”, etc.

§cache_dir: Option<String>

The directory to store local cache files (native targets only).

On native Rust targets, this specifies where configuration files should be cached locally. If None, defaults to /opt/data/{app_id}/config-cache. On WebAssembly targets, this is always None as file system access is not available.

§config_server: String

The Apollo configuration server URL.

This should be the base URL of your Apollo Configuration Center server, including the protocol (http/https) and port if necessary. Example: “http://apollo-server:8080”

§secret: Option<String>

Optional secret key for authentication with the Apollo server.

If your Apollo namespace requires authentication, provide the secret key here. This is used to generate HMAC-SHA1 signatures for secure access to protected configuration namespaces.

§label: Option<String>

Labels for grayscale release targeting.

Comma-separated list of labels that identify this client instance. Apollo can use these labels to determine which configuration version to serve during grayscale releases. Example: “canary,beta”

§ip: Option<String>

IP address for grayscale release targeting.

The IP address of this client instance. Apollo can use this IP address to determine which configuration version to serve during grayscale releases based on IP-based targeting rules.

§allow_insecure_https: Option<bool>

Whether to allow insecure HTTPS connections (self-signed certificates).

When set to true, the client will accept self-signed SSL certificates and other insecure HTTPS connections. This is useful in company internal networks or development environments where self-signed certificates are used.

Warning: Setting this to true reduces security by bypassing SSL certificate validation. Only use this in trusted internal networks.

§cache_ttl: Option<u64>

Time-to-live for the cache, in seconds (native targets only).

When using from_env, this defaults to 600 seconds (10 minutes) if the APOLLO_CACHE_TTL environment variable is not set. This field is not available on WebAssembly targets as disk caching is not supported.

Implementations§

Source§

impl ClientConfig

Source

pub fn from_env() -> Result<Self, Error>

Creates a new ClientConfig by reading environment variables.

This function loads configuration values from the following environment variables:

  • APP_ID (required): The Apollo application ID.
  • APOLLO_ACCESS_KEY_SECRET (optional): Secret key for authentication.
  • IDC (optional): Cluster name. Defaults to "default" if not set.
  • APOLLO_CONFIG_SERVICE (required): The Apollo config server URL.
  • APOLLO_LABEL (optional): Comma-separated labels for grayscale release.
  • APOLLO_CACHE_DIR (optional): Directory for local cache storage.
  • APOLLO_ALLOW_INSECURE_HTTPS (optional): If set to "true", allows insecure HTTPS.
  • APOLLO_CACHE_TTL (optional): Cache time-to-live in seconds. Defaults to 600 if not set.
§Returns
  • Ok(ClientConfig) if all required environment variables are present and valid.
  • Err(Error) if a required environment variable is missing or invalid.
§Errors

This function will return an error if:

  • The APP_ID environment variable is missing.
  • The APOLLO_CONFIG_SERVICE environment variable is missing.
  • Any environment variable that is expected to be a number (such as APOLLO_CACHE_TTL) cannot be parsed as the correct type.
  • Any other required environment variable is missing or invalid.

Trait Implementations§

Source§

impl Clone for ClientConfig

Source§

fn clone(&self) -> ClientConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ClientConfig> for JsValue

Source§

fn from(value: ClientConfig) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for ClientConfig

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for ClientConfig

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for ClientConfig

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<ClientConfig>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for ClientConfig

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for ClientConfig

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for ClientConfig

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<ClientConfig>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for ClientConfig

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<ClientConfig>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for ClientConfig

Source§

type Error = JsValue

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

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for ClientConfig

Source§

impl VectorIntoJsValue for ClientConfig

Source§

impl VectorIntoWasmAbi for ClientConfig

Source§

impl WasmDescribe for ClientConfig

Source§

impl WasmDescribeVector for ClientConfig

Source§

impl SupportsConstructor for ClientConfig

Source§

impl SupportsInstanceProperty for ClientConfig

Source§

impl SupportsStaticProperty for ClientConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,