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 Apolloconfig_server
: The Apollo configuration server URLcluster
: The cluster name (typically “default”)
§Optional Fields
secret
: Authentication secret key for secure accesscache_dir
: Local cache directory (native targets only)label
: Labels for grayscale release targetingip
: IP address for grayscale release targetingallow_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
impl ClientConfig
Sourcepub fn from_env() -> Result<Self, Error>
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
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ClientConfig
impl Debug for ClientConfig
Source§impl From<ClientConfig> for JsValue
impl From<ClientConfig> for JsValue
Source§fn from(value: ClientConfig) -> Self
fn from(value: ClientConfig) -> Self
Source§impl FromWasmAbi for ClientConfig
impl FromWasmAbi for ClientConfig
Source§impl IntoWasmAbi for ClientConfig
impl IntoWasmAbi for ClientConfig
Source§impl LongRefFromWasmAbi for ClientConfig
impl LongRefFromWasmAbi for ClientConfig
Source§impl OptionFromWasmAbi for ClientConfig
impl OptionFromWasmAbi for ClientConfig
Source§impl OptionIntoWasmAbi for ClientConfig
impl OptionIntoWasmAbi for ClientConfig
Source§impl RefFromWasmAbi for ClientConfig
impl RefFromWasmAbi for ClientConfig
Source§type Anchor = RcRef<ClientConfig>
type Anchor = RcRef<ClientConfig>
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§impl RefMutFromWasmAbi for ClientConfig
impl RefMutFromWasmAbi for ClientConfig
Source§impl TryFromJsValue for ClientConfig
impl TryFromJsValue for ClientConfig
Source§impl VectorFromWasmAbi for ClientConfig
impl VectorFromWasmAbi for ClientConfig
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[ClientConfig]>
Source§impl VectorIntoJsValue for ClientConfig
impl VectorIntoJsValue for ClientConfig
fn vector_into_jsvalue(vector: Box<[ClientConfig]>) -> JsValue
Source§impl VectorIntoWasmAbi for ClientConfig
impl VectorIntoWasmAbi for ClientConfig
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[ClientConfig]>) -> Self::Abi
Source§impl WasmDescribeVector for ClientConfig
impl WasmDescribeVector for ClientConfig
impl SupportsConstructor for ClientConfig
impl SupportsInstanceProperty for ClientConfig
impl SupportsStaticProperty for ClientConfig
Auto Trait Implementations§
impl Freeze for ClientConfig
impl RefUnwindSafe for ClientConfig
impl Send for ClientConfig
impl Sync for ClientConfig
impl Unpin for ClientConfig
impl UnwindSafe for ClientConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
Source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.