aboutsummaryrefslogtreecommitdiff
path: root/crates/tor-config/src/mistrust.rs
blob: 1c11141f2fd8d4049c6e777c3a88c1f77ac8d619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Helpers for [`fs-mistrust`](fs_mistrust) configuration.

use extend::ext;
use fs_mistrust::{Mistrust, MistrustBuilder};

use crate::ConfigBuildError;

/// The environment variable we look at when deciding whether to disable FS permissions checking.
pub const FS_PERMISSIONS_CHECKS_DISABLE_VAR: &str = "ARTI_FS_DISABLE_PERMISSION_CHECKS";

/// Extension trait for `MistrustBuilder` to convert the error type on
/// build.
#[ext(name = BuilderExt)]
pub impl MistrustBuilder {
    /// Run this builder and convert its error type (if any)
    fn build_for_arti(&self) -> Result<Mistrust, ConfigBuildError> {
        self.clone()
            .controlled_by_env_var_if_not_set(FS_PERMISSIONS_CHECKS_DISABLE_VAR)
            .build()
            .map_err(|e| ConfigBuildError::Invalid {
                field: "permissions".to_string(),
                problem: e.to_string(),
            })
    }
}