1
//! Helpers for [`fs-mistrust`](fs_mistrust) configuration.
2

            
3
use extend::ext;
4
use fs_mistrust::{Mistrust, MistrustBuilder};
5

            
6
use crate::ConfigBuildError;
7

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

            
11
/// Extension trait for `MistrustBuilder` to convert the error type on
12
/// build.
13
#[ext(name = BuilderExt)]
14
pub impl MistrustBuilder {
15
    /// Run this builder and convert its error type (if any)
16
7956
    fn build_for_arti(&self) -> Result<Mistrust, ConfigBuildError> {
17
7956
        self.clone()
18
7956
            .controlled_by_env_var_if_not_set(FS_PERMISSIONS_CHECKS_DISABLE_VAR)
19
7956
            .build()
20
7956
            .map_err(|e| ConfigBuildError::Invalid {
21
                field: "permissions".to_string(),
22
                problem: e.to_string(),
23
            })
24
7956
    }
25
}