Config expressions passing tests.
This commit is contained in:
@@ -27,9 +27,12 @@ use deadpool::{
|
||||
};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use store::{Store, Stores};
|
||||
use utils::config::{
|
||||
utils::{AsKey, ParseValue},
|
||||
Config, Servers,
|
||||
use utils::{
|
||||
config::{
|
||||
utils::{AsKey, ParseValue},
|
||||
Config, Servers,
|
||||
},
|
||||
expr::Token,
|
||||
};
|
||||
|
||||
use ahash::AHashMap;
|
||||
@@ -171,9 +174,13 @@ impl AddressMapping {
|
||||
"Invalid value for address mapping {key:?}: {value:?}",
|
||||
)),
|
||||
}
|
||||
} else if let Some(if_block) =
|
||||
config.parse_if_block(key, |name| Err(format!("Invalid variable name {name:?}.",)))?
|
||||
{
|
||||
} else if let Some(if_block) = config.parse_if_block(key, |name| {
|
||||
if ["address", "email"].contains(&name) {
|
||||
Ok(Token::Variable(1))
|
||||
} else {
|
||||
Err(format!("Invalid variable name {name:?}.",))
|
||||
}
|
||||
})? {
|
||||
Ok(AddressMapping::Custom(if_block))
|
||||
} else {
|
||||
Ok(AddressMapping::Disable)
|
||||
|
||||
@@ -300,15 +300,21 @@ impl AddressMapping {
|
||||
}
|
||||
}
|
||||
AddressMapping::Custom(if_block) => {
|
||||
let result = if_block
|
||||
.eval(
|
||||
|_| Variable::default(),
|
||||
|_, _| async { Variable::default() },
|
||||
)
|
||||
.await
|
||||
.into_string();
|
||||
if !result.is_empty() {
|
||||
return result.into_owned().into();
|
||||
if let Ok(result) = String::try_from(
|
||||
if_block
|
||||
.eval(
|
||||
|name| {
|
||||
if name == 1 {
|
||||
Variable::from(address)
|
||||
} else {
|
||||
Variable::default()
|
||||
}
|
||||
},
|
||||
|_, _| async { Variable::default() },
|
||||
)
|
||||
.await,
|
||||
) {
|
||||
return result.into();
|
||||
}
|
||||
}
|
||||
AddressMapping::Disable => (),
|
||||
@@ -323,16 +329,23 @@ impl AddressMapping {
|
||||
.rsplit_once('@')
|
||||
.map(|(_, domain_part)| format!("@{}", domain_part))
|
||||
.map(Cow::Owned),
|
||||
|
||||
AddressMapping::Custom(if_block) => {
|
||||
let result = if_block
|
||||
.eval(
|
||||
|_| Variable::default(),
|
||||
|_, _| async { Variable::default() },
|
||||
)
|
||||
.await
|
||||
.into_string();
|
||||
if !result.is_empty() {
|
||||
Some(result.into_owned().into())
|
||||
if let Ok(result) = String::try_from(
|
||||
if_block
|
||||
.eval(
|
||||
|name| {
|
||||
if name == 1 {
|
||||
Variable::from(address)
|
||||
} else {
|
||||
Variable::default()
|
||||
}
|
||||
},
|
||||
|_, _| async { Variable::default() },
|
||||
)
|
||||
.await,
|
||||
) {
|
||||
Some(result.into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user