pub struct Config<T> {
pub ingest: TopLevelIngest,
pub mutation: TopLevelMutation,
pub plugin: T,
pub client_timeout: Option<Duration>,
pub run_id: String,
pub time_domain: Option<String>,
}Expand description
Plugin configuration structure; contains both common elements, and
plugin-specific elements, based on the type param T.
Fields§
§ingest: TopLevelIngestCommon ingest configuration; mostly connection-related.
mutation: TopLevelMutationCommon mutation configuration; mostly connection-related.
plugin: TThe plugin-specific portion of the configuration.
client_timeout: Option<Duration>The client connection timeout. This is automatically used when you call Config::connect_and_authenticate_ingest.
run_id: Stringtimeline.run_id will be set to this value for all created
timelines.
time_domain: Option<String>If Some(...), timeline.time_domain will be set to this value
for all created timelines.
Implementations§
Source§impl<T: Serialize + DeserializeOwned> Config<T>
impl<T: Serialize + DeserializeOwned> Config<T>
Sourcepub fn load(env_prefix: &str) -> Result<Config<T>, Box<dyn Error + Send + Sync>>
pub fn load(env_prefix: &str) -> Result<Config<T>, Box<dyn Error + Send + Sync>>
Load configuration from config file given in
MODALITY_REFLECTOR_CONFIG as well as from other environment
variables (see module documentation). The returned Config
structure represents the fully reconcicled configuration.
env_prefix: The prefix used for environment variable based settings for members of the configuration struct (type paramT).
Sourcepub fn load_custom(
env_prefix: &str,
map_env_val: impl Fn(&str, &str) -> Result<Option<(String, TomlValue)>, Box<dyn Error + Send + Sync>>,
) -> Result<Config<T>, Box<dyn Error + Send + Sync>>
pub fn load_custom( env_prefix: &str, map_env_val: impl Fn(&str, &str) -> Result<Option<(String, TomlValue)>, Box<dyn Error + Send + Sync>>, ) -> Result<Config<T>, Box<dyn Error + Send + Sync>>
Load configuration, like Config::load, but allows passing a
map_env_val hook. This can be used to implement
non-standard environment deserialization, for value types
which aren’t correctly handled by the envy crate.
-
map_env_val: A function which will be called for every environment variable. If it returnsOk(Some((key, toml_value))), a corresponding entry will be created in themetadatatoml table, which is then deserialized to the custom config structure (type paramT). This intermediate form is used as a basis for merging values from the config file and from the environment. Since this function returns environment-provided values, they take precedence over the config file.For example:
fn custom_map_val(env_key: &str, env_val: &str) -> Result<Option<(String, toml::Value)>, Box<dyn std::error::Error + Send + Sync>> { // look for MY_PLUGIN_PREFIX_STRONGLY_ENCRYPTED_PASSWORD env var if env_key == "STRONGLY_ENCRYPTED_PASSWORD" { Ok(Some(("password".to_string(), toml::Value::String(env_val.to_owned())))) } else { // All other env vars use default deserialization Ok(None) } }
pub async fn connect_and_authenticate( &self, ) -> Result<Client, Box<dyn Error + Send + Sync>>
Sourcepub async fn connect_and_authenticate_ingest(
&self,
) -> Result<Client, Box<dyn Error + Send + Sync>>
pub async fn connect_and_authenticate_ingest( &self, ) -> Result<Client, Box<dyn Error + Send + Sync>>
Connect to the configured Modality backend for ingest, authenticate, and return a high-level ingest client.
Sourcepub async fn connect_and_authenticate_mutation(
&self,
) -> Result<MutatorHost, Box<dyn Error + Send + Sync>>
pub async fn connect_and_authenticate_mutation( &self, ) -> Result<MutatorHost, Box<dyn Error + Send + Sync>>
Connect to the configured Modality backend for mutation, authenticate, and return a connected MutatorHost.
This also creates an ingest connection, which is used internally to log mutation-related events.