1
0
Fork 0
forked from wry/wry

config: add uid client criteria

This commit is contained in:
Julian Orth 2025-05-03 12:48:44 +02:00
parent 9bf79bf23c
commit 587ffc7ee5
13 changed files with 63 additions and 2 deletions

View file

@ -232,6 +232,7 @@ pub struct ClientMatch {
pub sandbox_instance_id: Option<String>,
pub sandbox_instance_id_regex: Option<String>,
pub sandboxed: Option<bool>,
pub uid: Option<i32>,
}
#[derive(Debug, Clone)]

View file

@ -3,7 +3,7 @@ use {
config::{
ClientMatch, GenericMatch, MatchExactly,
context::Context,
extractor::{Extractor, ExtractorError, arr, bol, n32, opt, str, val},
extractor::{Extractor, ExtractorError, arr, bol, n32, opt, s32, str, val},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
},
toml::{
@ -49,7 +49,7 @@ impl Parser for ClientMatchParser<'_> {
sandbox_app_id,
sandbox_app_id_regex,
),
(sandbox_instance_id, sandbox_instance_id_regex),
(sandbox_instance_id, sandbox_instance_id_regex, uid),
) = ext.extract((
(
opt(str("name")),
@ -66,6 +66,7 @@ impl Parser for ClientMatchParser<'_> {
(
opt(str("sandbox-instance-id")),
opt(str("sandbox-instance-id-regex")),
opt(s32("uid")),
),
))?;
let mut not = None;
@ -106,6 +107,7 @@ impl Parser for ClientMatchParser<'_> {
sandbox_instance_id: sandbox_instance_id.despan_into(),
sandbox_instance_id_regex: sandbox_instance_id_regex.despan_into(),
sandboxed: sandboxed.despan(),
uid: uid.despan(),
})
}
}

View file

@ -95,6 +95,13 @@ impl Rule for ClientRule {
}
};
}
macro_rules! value {
($ty:ident, $field:ident) => {
if let Some(value) = match_.$field {
all.push(m(ClientCriterion::$ty(value)));
}
};
}
macro_rules! bool {
($ty:ident, $field:ident) => {
if let Some(value) = &match_.$field {
@ -113,6 +120,7 @@ impl Rule for ClientRule {
value_ref!(SandboxAppIdRegex, sandbox_app_id_regex);
value_ref!(SandboxInstanceId, sandbox_instance_id);
value_ref!(SandboxInstanceIdRegex, sandbox_instance_id_regex);
value!(Uid, uid);
bool!(Sandboxed, sandboxed);
Some(())
}