Merge pull request #513 from matthiasbeyer/libimagstore/hooks/optionally-deny-mutable-hooks
Libimagstore/hooks/optionally deny mutable hooks
This commit is contained in:
commit
c6f9d91599
4 changed files with 28 additions and 1 deletions
|
@ -24,6 +24,7 @@ post-delete-hook-aspects = [ "debug" ]
|
|||
|
||||
[[aspects.debug]]
|
||||
parallel = false
|
||||
mutable_hooks = false
|
||||
|
||||
[store.hooks]
|
||||
|
||||
|
|
|
@ -193,6 +193,7 @@ pub fn get_post_move_aspect_names(value: &Option<Value>) -> Vec<String> {
|
|||
#[derive(Debug)]
|
||||
pub struct AspectConfig {
|
||||
parallel: bool,
|
||||
mutable_hooks: bool,
|
||||
config: Value,
|
||||
}
|
||||
|
||||
|
@ -200,8 +201,10 @@ impl AspectConfig {
|
|||
|
||||
pub fn new(init: Value) -> AspectConfig {
|
||||
let parallel = AspectConfig::is_parallel(&init);
|
||||
let muthooks = AspectConfig::allows_mutable_hooks(&init);
|
||||
AspectConfig {
|
||||
config: init,
|
||||
mutable_hooks: muthooks,
|
||||
parallel: parallel,
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +223,24 @@ impl AspectConfig {
|
|||
}
|
||||
}
|
||||
|
||||
fn allows_mutable_hooks(init: &Value) -> bool {
|
||||
match *init {
|
||||
Value::Table(ref t) =>
|
||||
t.get("mutable_hooks")
|
||||
.map_or(false, |value| {
|
||||
match *value {
|
||||
Value::Boolean(b) => b,
|
||||
_ => false,
|
||||
}
|
||||
}),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allow_mutable_hooks(&self) -> bool {
|
||||
self.mutable_hooks
|
||||
}
|
||||
|
||||
/// Get the aspect configuration for an aspect.
|
||||
///
|
||||
/// Pass the store configuration object, this searches in `[aspects][<aspect_name>]`.
|
||||
|
|
|
@ -73,6 +73,10 @@ impl StoreIdAccessor for Aspect {
|
|||
|
||||
impl MutableHookDataAccessor for Aspect {
|
||||
fn access_mut(&self, fle: &mut FileLockEntry) -> HookResult<()> {
|
||||
if !self.cfg.as_ref().map(|c| c.allow_mutable_hooks()).unwrap_or(false) {
|
||||
return Err(HE::new(HEK::MutableHooksNotAllowed, None));
|
||||
}
|
||||
|
||||
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect();
|
||||
|
||||
fn is_file_accessor(a: &HDA) -> bool {
|
||||
|
|
|
@ -3,7 +3,8 @@ generate_error_imports!();
|
|||
|
||||
generate_custom_error_types!(HookError, HookErrorKind, CustomData,
|
||||
HookExecutionError => "Hook exec error",
|
||||
AccessTypeViolation => "Hook access type violation"
|
||||
AccessTypeViolation => "Hook access type violation",
|
||||
MutableHooksNotAllowed => "Mutable Hooks are denied"
|
||||
);
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Copy)]
|
||||
|
|
Loading…
Reference in a new issue