Config

Struct Config 

Source
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: TopLevelIngest

Common ingest configuration; mostly connection-related.

§mutation: TopLevelMutation

Common mutation configuration; mostly connection-related.

§plugin: T

The 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: String

timeline.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 Config<()>

Source

pub fn load_common() -> Result<Config<()>, Box<dyn Error + Send + Sync>>

Load common config only. This is useful if you’re writing a plugin with no specific configuartion options, or if you’re connecting from a context other than a reflector plugin.

Source§

impl<T: Serialize + DeserializeOwned> Config<T>

Source

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 param T).
Source

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 returns Ok(Some((key, toml_value))), a corresponding entry will be created in the metadata toml table, which is then deserialized to the custom config structure (type param T). 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)
      }
    }
Source

pub async fn connect_and_authenticate( &self, ) -> Result<Client, Box<dyn Error + Send + Sync>>

👎Deprecated: Prefer the more explicit ‘connect_and_authenticate_ingest’
Source

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.

Source

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.

Auto Trait Implementations§

§

impl<T> Freeze for Config<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Config<T>
where T: RefUnwindSafe,

§

impl<T> Send for Config<T>
where T: Send,

§

impl<T> Sync for Config<T>
where T: Sync,

§

impl<T> Unpin for Config<T>
where T: Unpin,

§

impl<T> UnwindSafe for Config<T>
where T: UnwindSafe,

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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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> Ungil for T
where T: Send,