"then" is now applicable to filters as well as actions

master
Yves G 2018-01-31 11:58:12 +01:00
parent 298a4c3a11
commit d73780cacd
2 changed files with 9 additions and 12 deletions

View File

@ -1,5 +1,5 @@
# pyruse is intended as a replacement to both fail2ban and epylog # pyruse is intended as a replacement to both fail2ban and epylog
# Copyright © 2017 Y. Gablin # Copyright © 20172018 Y. Gablin
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing. # Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
import importlib import importlib
from pyruse import log from pyruse import log
@ -19,16 +19,15 @@ def get(moduleDesc):
isAction = False isAction = False
mod = _getModule("pyruse.filters." + moduleDesc["filter"]) mod = _getModule("pyruse.filters." + moduleDesc["filter"])
obj = mod.Filter(moduleDesc.get("args", {})) obj = mod.Filter(moduleDesc.get("args", {}))
thenRun = None
elseRun = moduleDesc["else"] if "else" in moduleDesc else None elseRun = moduleDesc["else"] if "else" in moduleDesc else None
elif "action" in moduleDesc: elif "action" in moduleDesc:
isAction = True isAction = True
mod = _getModule("pyruse.actions." + moduleDesc["action"]) mod = _getModule("pyruse.actions." + moduleDesc["action"])
obj = mod.Action(moduleDesc.get("args", {})) obj = mod.Action(moduleDesc.get("args", {}))
thenRun = moduleDesc["then"] if "then" in moduleDesc else None
elseRun = None elseRun = None
else: else:
raise ValueError("Step is neither “filter” nor “action”: %s\n" % str(moduleDesc)) raise ValueError("Step is neither “filter” nor “action”: %s\n" % str(moduleDesc))
thenRun = moduleDesc["then"] if "then" in moduleDesc else None
return Module(isAction, obj, thenRun, elseRun) return Module(isAction, obj, thenRun, elseRun)
def _getModule(modName): def _getModule(modName):

View File

@ -1,5 +1,5 @@
# pyruse is intended as a replacement to both fail2ban and epylog # pyruse is intended as a replacement to both fail2ban and epylog
# Copyright © 2017 Y. Gablin # Copyright © 20172018 Y. Gablin
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing. # Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
from pyruse import log, module from pyruse import log, module
@ -33,19 +33,17 @@ class Workflow:
break break
mod = module.get(step) mod = module.get(step)
obj = mod.module obj = mod.module
if mod.isAction: if mod.thenRun:
if mod.thenRun: (seen, dangling) = \
(seen, dangling) = \ self._branchToChain(obj.setNextStep, mod.thenRun, actions, seen, dangling)
self._branchToChain(obj.setNextStep, mod.thenRun, actions, seen, dangling) isThenCalled = True
isThenCalled = True if mod.isFilter:
isPreviousDangling = False
else:
if mod.elseRun: if mod.elseRun:
(seen, dangling) = \ (seen, dangling) = \
self._branchToChain(obj.setAltStep, mod.elseRun, actions, seen, dangling) self._branchToChain(obj.setAltStep, mod.elseRun, actions, seen, dangling)
else: else:
dangling.append(obj.setAltStep) dangling.append(obj.setAltStep)
isPreviousDangling = True isPreviousDangling = mod.isFilter and not isThenCalled
if previousSetter: if previousSetter:
previousSetter(obj) previousSetter(obj)
else: else: