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

            
3
use fs_mistrust::{Mistrust, MistrustBuilder};
4

            
5
use crate::ConfigBuildError;
6

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

            
10
/// Extension trait for `MistrustBuilder` to convert the error type on
11
/// build.
12
pub trait BuilderExt {
13
    /// Type that this builder provides.
14
    type Built;
15
    /// Run this builder and convert its error type (if any)
16
    fn build_for_arti(&self) -> Result<Self::Built, ConfigBuildError>;
17
}
18

            
19
impl BuilderExt for MistrustBuilder {
20
    type Built = Mistrust;
21

            
22
2560
    fn build_for_arti(&self) -> Result<Self::Built, ConfigBuildError> {
23
2560
        self.clone()
24
2560
            .controlled_by_env_var_if_not_set(FS_PERMISSIONS_CHECKS_DISABLE_VAR)
25
2560
            .build()
26
2560
            .map_err(|e| ConfigBuildError::Invalid {
27
                field: "permissions".to_string(),
28
                problem: e.to_string(),
29
2560
            })
30
2560
    }
31
}