pub struct SafetyConfig {
pub paths: PathAllowlist,
pub hosts: HostAllowlist,
pub env_vars: Option<HashSet<String>>,
pub allow_process: bool,
pub allowed_commands: Option<HashSet<String>>,
pub default_timeout: Duration,
pub max_timeout: Duration,
}Expand description
Safety configuration for stdlib operations.
Fields§
§paths: PathAllowlistPath allowlist.
hosts: HostAllowlistHost allowlist.
env_vars: Option<HashSet<String>>Allowed environment variable names (None = all denied).
allow_process: boolWhether process execution is allowed.
allowed_commands: Option<HashSet<String>>Allowed process commands (None = all allowed if allow_process is true).
default_timeout: DurationDefault timeout for operations.
max_timeout: DurationMaximum timeout allowed.
Implementations§
Source§impl SafetyConfig
impl SafetyConfig
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive configuration (for trusted code only).
Sourcepub fn with_paths(self, paths: PathAllowlist) -> Self
pub fn with_paths(self, paths: PathAllowlist) -> Self
Set path allowlist.
Sourcepub fn with_hosts(self, hosts: HostAllowlist) -> Self
pub fn with_hosts(self, hosts: HostAllowlist) -> Self
Set host allowlist.
Sourcepub fn with_env_vars<I, S>(self, vars: I) -> Self
pub fn with_env_vars<I, S>(self, vars: I) -> Self
Allow specific environment variables.
Sourcepub fn allow_all_env(self) -> Self
pub fn allow_all_env(self) -> Self
Allow all environment variables.
Sourcepub fn with_allow_process(self, allow: bool) -> Self
pub fn with_allow_process(self, allow: bool) -> Self
Allow process execution.
Sourcepub fn with_allowed_commands<I, S>(self, commands: I) -> Self
pub fn with_allowed_commands<I, S>(self, commands: I) -> Self
Set allowed commands.
Sourcepub fn with_default_timeout(self, timeout: Duration) -> Self
pub fn with_default_timeout(self, timeout: Duration) -> Self
Set default timeout.
Sourcepub fn with_max_timeout(self, timeout: Duration) -> Self
pub fn with_max_timeout(self, timeout: Duration) -> Self
Set maximum timeout.
Sourcepub fn can_access_env(&self, name: &str) -> bool
pub fn can_access_env(&self, name: &str) -> bool
Check if an environment variable is accessible.
Sourcepub fn check_env(&self, name: &str) -> Result<()>
pub fn check_env(&self, name: &str) -> Result<()>
Check environment variable access, returning error if denied.
Sourcepub fn can_execute(&self, command: &str) -> bool
pub fn can_execute(&self, command: &str) -> bool
Check if a command is allowed.
Sourcepub fn check_execute(&self, command: &str) -> Result<()>
pub fn check_execute(&self, command: &str) -> Result<()>
Check command execution, returning error if denied.
Sourcepub fn clamp_timeout(&self, timeout: Duration) -> Duration
pub fn clamp_timeout(&self, timeout: Duration) -> Duration
Clamp a timeout to the maximum allowed.
Trait Implementations§
Source§impl Clone for SafetyConfig
impl Clone for SafetyConfig
Source§fn clone(&self) -> SafetyConfig
fn clone(&self) -> SafetyConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more