Compare commits
12
Commits
717988c53b
...
babd77b1ef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
babd77b1ef | ||
|
|
27d7030963 | ||
|
|
ad2296610c | ||
|
|
d26f3a88af | ||
|
|
14b5727923 | ||
|
|
cdf35a9e68 | ||
|
|
d5fd468498 | ||
|
|
24ea9a7a14 | ||
|
|
4b92e82ea6 | ||
|
|
950707386a | ||
|
|
d492d78a70 | ||
|
|
a574a595dc |
+1
-1
@@ -1,5 +1,5 @@
|
||||
from plugins import rmass
|
||||
from core import buildOperation
|
||||
|
||||
outputs = buildOperation(rmass.operations.checkavailable)
|
||||
responses = buildOperation(rmass.operations.checkavailable)
|
||||
|
||||
|
||||
@@ -8,23 +8,26 @@ from core.runtime.runtimecontract import buildRuntimeAttr, buildPreRuntimeAttr
|
||||
def buildAction (action, outputs, process):
|
||||
action_log = True
|
||||
|
||||
outputs, resolved, match, filter = buildPreRuntimeAttr(action, outputs, process)
|
||||
resolved, match, filter = buildPreRuntimeAttr(action, outputs, process)
|
||||
|
||||
if hasattr(action, "allowaction"):
|
||||
if not action.allowaction:
|
||||
return outputs, None
|
||||
return None
|
||||
|
||||
if match:
|
||||
return outputs, None
|
||||
if filter.get("execute", False):
|
||||
response, outputs = executeRequest(filter["execute"], outputs, resolved)
|
||||
|
||||
return None
|
||||
|
||||
response, outputs = executeRequest(action, outputs, resolved)
|
||||
|
||||
if response is None:
|
||||
return outputs, None
|
||||
|
||||
outputs, response = buildRuntimeAttr(action, outputs, resolved, response, process)
|
||||
response = buildRuntimeAttr(action, outputs, resolved, response, process)
|
||||
|
||||
if action_log:
|
||||
logging.info(f"{action.name} completed")
|
||||
|
||||
return outputs, response
|
||||
return response
|
||||
|
||||
@@ -5,29 +5,28 @@ from core.execution.monitor import buildMonitor
|
||||
from core.execution.recursive import buildRecursive
|
||||
|
||||
def executeContract(module, outputs, process):
|
||||
#print("DEBUGGING")
|
||||
#print(module.name)
|
||||
|
||||
if module.kind == "operation":
|
||||
|
||||
outputs, responses = buildOperation(module, outputs)
|
||||
responses = buildOperation(module, outputs)
|
||||
|
||||
return outputs, responses
|
||||
return responses
|
||||
|
||||
elif module.kind == "action":
|
||||
|
||||
outputs, response = buildAction(module, outputs, process)
|
||||
response = buildAction(module, outputs, process)
|
||||
|
||||
return outputs, response
|
||||
return response
|
||||
|
||||
elif module.kind == "monitor":
|
||||
outputs, response= buildMonitor(module, outputs)
|
||||
response = buildMonitor(module, outputs)
|
||||
|
||||
return outputs, response
|
||||
return response
|
||||
|
||||
elif module.kind == "recursiveset":
|
||||
outputs, response = buildRecursive(module, outputs)
|
||||
response = buildRecursive(module, outputs)
|
||||
|
||||
return outputs, response
|
||||
return response
|
||||
|
||||
#except Exception as error:
|
||||
#outputs = manageFailure(error, module)
|
||||
@@ -6,19 +6,18 @@ from core.apirequest.execute import getSession
|
||||
from core.execution.lifecyclemanager.lifecycleregistry import registerLifecycle
|
||||
|
||||
lifecycles = {}
|
||||
outputs = {}
|
||||
|
||||
def manageLifecycle(module):
|
||||
lifecycle_log = os.environ.get("LOGS_LIFECYCLE", "false").lower() == "true"
|
||||
|
||||
outputs = {}
|
||||
|
||||
registerLifecycle (module, lifecycles)
|
||||
|
||||
if lifecycles[module.name]["mode"] == "continuous":
|
||||
while lifecycles[module.name]["mode"] == "continuous":
|
||||
lifecycles[module.name]["state"] = "active"
|
||||
|
||||
outputs, response = executeContract(module, outputs, None)
|
||||
response = executeContract(module, outputs, None)
|
||||
|
||||
if lifecycle_log:
|
||||
print(f"{module.name} thread {lifecycles[module.name][module.name]} running in {lifecycles[module.name]['mode']} mode")
|
||||
@@ -35,7 +34,7 @@ def manageLifecycle(module):
|
||||
print(f"{module.name} thread {lifecycles[module.name][module.name]} running in {lifecycles[module.name]['mode']} mode")
|
||||
print(lifecycles)
|
||||
|
||||
outputs, response = executeContract(module, outputs, None)
|
||||
response = executeContract(module, outputs, None)
|
||||
|
||||
lifecycles[module.name]["state"] = "stopped"
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ from core.execution.operation import buildOperation
|
||||
from core.apirequest import executeRequest
|
||||
from core.runtime.resolver import resolveItem
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
#from plugins.rmass.actions import login, refresh_tokens
|
||||
from core.runtime import buildOutput
|
||||
from core.runtime.savedata import loadSave
|
||||
|
||||
@@ -14,12 +13,12 @@ outputs = {}
|
||||
resolved = {}
|
||||
|
||||
def buildMonitor(monitor, outputs):
|
||||
outputs = loadSave(monitor, outputs)
|
||||
loadSave(monitor, outputs)
|
||||
|
||||
response, outputs = executeRequest(monitor, outputs, resolved)
|
||||
|
||||
if response is None:
|
||||
return outputs, None
|
||||
return None
|
||||
|
||||
responsedata = response.json()
|
||||
|
||||
@@ -34,9 +33,9 @@ def buildMonitor(monitor, outputs):
|
||||
module = filter["execute"]
|
||||
|
||||
if module.kind == "action":
|
||||
outputs, response = buildAction(module, outputs, None)
|
||||
response = buildAction(module, outputs, None)
|
||||
if module.kind == "operation":
|
||||
outputs, responses = buildOperation(module, outputs)
|
||||
responses = buildOperation(module, outputs)
|
||||
response = responses
|
||||
|
||||
return outputs, response
|
||||
return response
|
||||
@@ -10,45 +10,36 @@ from core.console import console
|
||||
|
||||
outputs = {}
|
||||
|
||||
#console = Console(stderr=True)
|
||||
|
||||
def buildOperation(definition, outputs):
|
||||
process_log = True
|
||||
|
||||
from core.execution.executioncontract import executeContract
|
||||
|
||||
actions = definition.actions
|
||||
outputs = registerProcess(definition, outputs)
|
||||
registerProcess(definition, outputs)
|
||||
responses = []
|
||||
|
||||
if getattr(definition, "track", False):
|
||||
actions = track(
|
||||
actions,
|
||||
#description=definition.name
|
||||
description=f"[green]{definition.name}[/green]",
|
||||
console=console
|
||||
)
|
||||
|
||||
for action in actions:
|
||||
|
||||
#Check if dependencies are in stop signal registry
|
||||
stop = checkDependency(action, outputs, definition)
|
||||
|
||||
if stop:
|
||||
continue
|
||||
|
||||
#Register action before its execution
|
||||
if action.kind == "action":
|
||||
outputs["processes"][definition.name][action.name] = {}
|
||||
|
||||
#Pass the definition through to the action so it can be passed into buildPreRuntimeAttr
|
||||
#Definition should be passed through in order to give access to addStopSignal so it can write directly to the definition during buildPreRuntimeAttr
|
||||
#Stop signal can optionally be engaged by doing addStopSignal inside the action definition
|
||||
outputs, response = executeContract(action, outputs, definition)
|
||||
response = executeContract(action, outputs, definition)
|
||||
|
||||
responses.append(response)
|
||||
|
||||
#Register responses in process registry
|
||||
if action.kind == "action":
|
||||
outputs["processes"][definition.name][action.name]["response"] = response
|
||||
|
||||
@@ -76,4 +67,4 @@ def buildOperation(definition, outputs):
|
||||
|
||||
|
||||
|
||||
return outputs, responses
|
||||
return responses
|
||||
|
||||
@@ -9,4 +9,4 @@ def registerProcess(module, outputs):
|
||||
outputs["processes"][module.name]["stopsignals"] = []
|
||||
outputs["processes"][module.name]["completed"] = []
|
||||
|
||||
return outputs
|
||||
return
|
||||
@@ -19,7 +19,7 @@ def buildRecursive(definition, outputs):
|
||||
logging.debug(f"No items available in {source} for {definition.name}")
|
||||
return outputs, []
|
||||
|
||||
outputs = registerProcess(definition, outputs)
|
||||
registerProcess(definition, outputs)
|
||||
|
||||
responses = []
|
||||
from core.execution.executioncontract import executeContract
|
||||
@@ -65,7 +65,7 @@ def buildRecursive(definition, outputs):
|
||||
if job.kind == "action":
|
||||
outputs["processes"][definition.name][job.name] = {}
|
||||
|
||||
outputs, response = executeContract(job, outputs, definition)
|
||||
response = executeContract(job, outputs, definition)
|
||||
responses.append(response)
|
||||
if job.kind == "action":
|
||||
outputs["processes"][definition.name][job.name]["response"] = response
|
||||
@@ -88,4 +88,4 @@ def buildRecursive(definition, outputs):
|
||||
|
||||
outputs.pop("stopsignals", None)
|
||||
|
||||
return outputs, responses
|
||||
return responses
|
||||
|
||||
@@ -17,6 +17,11 @@ def applyConditions(definition, dictionary, outputs):
|
||||
if filtervalue is None:
|
||||
continue
|
||||
|
||||
if filter.get("filterkey_format", None):
|
||||
if filter["filterkey_format"] == "length":
|
||||
resolvedvalue = len(dictionary.get(filter["filterkey"]))
|
||||
|
||||
else:
|
||||
resolvedvalue = dictionary.get(filter["filterkey"])
|
||||
|
||||
if filter["operator"] == ">=":
|
||||
|
||||
@@ -22,7 +22,7 @@ def manageFailure(error, action, outputs):
|
||||
else:
|
||||
print(f"{type(error).__name__} detected during {action.name}. Applying recovery policy.")
|
||||
|
||||
outputs, response = buildAction(repair, outputs, None)
|
||||
response = buildAction(repair, outputs, None)
|
||||
|
||||
return outputs
|
||||
print(f"{error}")
|
||||
|
||||
@@ -7,11 +7,11 @@ def buildPreRuntimeAttr(action, outputs, process):
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
from core.runtime.resolver import resolveItem
|
||||
|
||||
outputs = loadSave(action, outputs)
|
||||
loadSave(action, outputs)
|
||||
|
||||
resolved = resolveItem(action, outputs)
|
||||
|
||||
resolved, outputs = readRow(action, resolved, outputs)
|
||||
readRow(action, resolved, outputs)
|
||||
|
||||
match, filter = applyConditions(action, resolved, outputs)
|
||||
|
||||
@@ -19,7 +19,7 @@ def buildPreRuntimeAttr(action, outputs, process):
|
||||
logging.info(filter.get("print"))
|
||||
addStopSignal(action, outputs, process)
|
||||
|
||||
return outputs, resolved, match, filter
|
||||
return resolved, match, filter
|
||||
|
||||
|
||||
def buildRuntimeAttr(action, outputs, resolved, response, process):
|
||||
@@ -48,4 +48,4 @@ def buildRuntimeAttr(action, outputs, resolved, response, process):
|
||||
|
||||
buildLog(action, outputs, response)
|
||||
|
||||
return outputs, response
|
||||
return response
|
||||
@@ -41,7 +41,7 @@ def buildSave(action, outputs):
|
||||
|
||||
if savedata_log:
|
||||
logging.info(f"Data saved by {action.name} to {action.savepath}")
|
||||
return outputs
|
||||
return
|
||||
|
||||
def loadSave(action, outputs):
|
||||
savedata_log = os.environ.get("LOGS_SAVE_DATA_ACCESS", "false").lower() == "true"
|
||||
@@ -55,7 +55,7 @@ def loadSave(action, outputs):
|
||||
|
||||
if savedata_log:
|
||||
logging.info(f"Data loaded by {action.name} from {action.savepath}")
|
||||
return outputs
|
||||
return
|
||||
|
||||
def saveRow(action, outputs, resolved):
|
||||
import sqlite3
|
||||
@@ -151,7 +151,7 @@ def saveRow(action, outputs, resolved):
|
||||
|
||||
logging.info(f"Successfully saved data to {table} during {action.name}")
|
||||
|
||||
return True
|
||||
return
|
||||
|
||||
|
||||
def readRow(action, resolved, outputs):
|
||||
@@ -221,9 +221,9 @@ def readRow(action, resolved, outputs):
|
||||
logging.debug(outputs[output_name])
|
||||
logging.debug(dbtarget)
|
||||
|
||||
return resolved, outputs
|
||||
return
|
||||
else:
|
||||
logging.info(f"Search target {value} not found in database table {table}")
|
||||
return resolved, outputs
|
||||
return
|
||||
|
||||
return resolved, outputs
|
||||
return
|
||||
@@ -36,7 +36,7 @@ def buildListener(listener, self):
|
||||
logging.info(outputs["firewall_allowed"])
|
||||
|
||||
#Process and forward to RMASS
|
||||
outputs, responses = executeContract(listener.execute, outputs, None)
|
||||
responses = executeContract(listener.execute, outputs, None)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@ from core.execution.operation import buildOperation
|
||||
|
||||
outputs = {}
|
||||
|
||||
outputs = buildOperation(rmass.operations.login, outputs)
|
||||
responses = buildOperation(rmass.operations.login, outputs)
|
||||
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ definition = rmassmonitor
|
||||
outputs = {}
|
||||
resolved = {}
|
||||
while True:
|
||||
outputs = buildMonitor(definition, outputs)
|
||||
response = buildMonitor(definition, outputs)
|
||||
|
||||
time.sleep(definition.refreshrate)
|
||||
+1
-1
@@ -2,5 +2,5 @@ from plugins import rmass
|
||||
from core import buildAction
|
||||
|
||||
outputs = {}
|
||||
outputs = buildAction(rmass.actions.pingsynapse, outputs)
|
||||
response = buildAction(rmass.actions.pingsynapse, outputs)
|
||||
|
||||
|
||||
@@ -88,6 +88,15 @@ outputs = {
|
||||
##Filter test against recursiveset
|
||||
|
||||
filters = [
|
||||
{
|
||||
"filterkey": "message_body",
|
||||
#"filterkey_lib": "outputs",
|
||||
"filterkey_format": "length",
|
||||
"execute": synapsenotify,
|
||||
"operator": "<",
|
||||
"filtervalue": 5,
|
||||
"print": f"Message body is less than 5 characters. Notifying with {synapsenotify.name}...",
|
||||
},
|
||||
{
|
||||
"filterkey": "msgtype",
|
||||
"operator": "==",
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from . import synapsenotify
|
||||
|
||||
name = "Synapse Message Push"
|
||||
|
||||
kind = "action"
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ from core.execution.operation import buildOperation
|
||||
outputs ={}
|
||||
|
||||
while True:
|
||||
outputs = buildOperation(rmass.operations.setavailable, outputs)
|
||||
responses = buildOperation(rmass.operations.setavailable, outputs)
|
||||
|
||||
time.sleep(rmass.operations.setavailable.sleeptime)
|
||||
|
||||
@@ -3,5 +3,5 @@ from core.execution.operation import buildOperation
|
||||
|
||||
|
||||
outputs = {}
|
||||
outputs = buildOperation(rmass.operations.synapsemessagepush, outputs)
|
||||
responses = buildOperation(rmass.operations.synapsemessagepush, outputs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user