Skip to main content

stackless_provider_sdk/
config.rs

1use std::collections::BTreeMap;
2
3use crate::error::IntegrationError;
4
5pub fn config_string(
6    config: &BTreeMap<String, toml::Value>,
7    key: &str,
8) -> Result<String, IntegrationError> {
9    config
10        .get(key)
11        .and_then(toml::Value::as_str)
12        .map(str::to_owned)
13        .ok_or_else(|| IntegrationError::ConfigInvalid {
14            location: format!("integrations.*.{key}"),
15            detail: format!("{key} is required"),
16        })
17}
18
19pub fn config_bool(config: &BTreeMap<String, toml::Value>, key: &str) -> bool {
20    config
21        .get(key)
22        .and_then(toml::Value::as_bool)
23        .unwrap_or(false)
24}
25
26pub fn config_optional_string(config: &BTreeMap<String, toml::Value>, key: &str) -> Option<String> {
27    config
28        .get(key)
29        .and_then(toml::Value::as_str)
30        .map(str::to_owned)
31}