Compare commits
30
Commits
3db6a5ae17
...
80c43578f3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80c43578f3 | ||
|
|
902d79c00a | ||
|
|
d63a54ebd0 | ||
|
|
5d56595463 | ||
|
|
5da12a10bb | ||
|
|
ff940e4771 | ||
|
|
3582c7b621 | ||
|
|
9d4e9d38ad | ||
|
|
cb3a2d90b0 | ||
|
|
148cd55c82 | ||
|
|
5ef08fc94f | ||
|
|
41495d3ed6 | ||
|
|
fbacfa72c8 | ||
|
|
3dfc70db45 | ||
|
|
fd200d5ece | ||
|
|
e61fa2c80d | ||
|
|
7ba41cdf67 | ||
|
|
e693a4fb25 | ||
|
|
469586fefb | ||
|
|
75a9ce1b66 | ||
|
|
f46ce89142 | ||
|
|
c8edaa65d6 | ||
|
|
480a49ced9 | ||
|
|
90a18805f0 | ||
|
|
5d17c74eaf | ||
|
|
5a805ec9b7 | ||
|
|
30c001fe0e | ||
|
|
924b49c6b5 | ||
|
|
90135afce7 | ||
|
|
75f42753a0 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
from .server import server
|
||||
from .apirequest import executeRequest
|
||||
from .runtime import buildSave, loadSave, buildLog, manageFailure, buildOutput
|
||||
from .runtime import buildSave, loadSave, buildLog, buildOutput
|
||||
#from .execution import buildOperation, buildAction
|
||||
from .execution.action import buildAction
|
||||
from .execution.operation import buildOperation
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import requests
|
||||
import threading
|
||||
import os
|
||||
import time
|
||||
from .request import buildRequest
|
||||
|
||||
#session = requests.Session()
|
||||
@@ -15,6 +16,7 @@ def getSession(reset=False):
|
||||
if not hasattr(_thread_local, "session"):
|
||||
session = requests.Session()
|
||||
session.name = threading.current_thread().name
|
||||
session.created_at = time.monotonic()
|
||||
_thread_local.session = session
|
||||
|
||||
return _thread_local.session
|
||||
@@ -23,7 +25,7 @@ def getSession(reset=False):
|
||||
def executeRequest(action, outputs, resolved):
|
||||
session = getSession()
|
||||
|
||||
session_log = bool(os.environ.get("LOGS_SESSION", False))
|
||||
session_log = os.environ.get("LOGS_SESSION", "false").lower() == "true"
|
||||
|
||||
if session_log:
|
||||
print(
|
||||
|
||||
@@ -18,7 +18,10 @@ def buildRequest(definition, outputs, resolved):
|
||||
request["headers"] = buildHeaders(definition, request, outputs, resolved)
|
||||
|
||||
if hasattr(definition, "requestdata"):
|
||||
if hasattr(definition, "requestdata"):
|
||||
###To potentially test moving requestdata to an outputs dict instead of a string
|
||||
if isinstance(definition.requestdata, str):
|
||||
request["data"] = outputs[definition.requestdata]
|
||||
else:
|
||||
request["data"] = buildObject2(
|
||||
definition.requestdata,
|
||||
outputs,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import logging
|
||||
|
||||
from core.apirequest import executeRequest
|
||||
from core.runtime.runtimecontract import buildRuntimeAttr, buildPreRuntimeAttr
|
||||
from core.runtime.stopsignals import addStopSignal
|
||||
#from core.runtime.stopsignals import addStopSignal
|
||||
|
||||
|
||||
def buildAction (action, outputs):
|
||||
def buildAction (action, outputs, process):
|
||||
action_log = True
|
||||
|
||||
outputs, resolved, match, filter = buildPreRuntimeAttr(action, outputs)
|
||||
outputs, resolved, match, filter = buildPreRuntimeAttr(action, outputs, process)
|
||||
|
||||
if hasattr(action, "allowaction"):
|
||||
if not action.allowaction:
|
||||
@@ -19,6 +22,10 @@ def buildAction (action, outputs):
|
||||
if response is None:
|
||||
return outputs, None
|
||||
|
||||
outputs, response = buildRuntimeAttr(action, outputs, resolved, response)
|
||||
#outputs["processes"][process.name][action.name]["response"] = response
|
||||
outputs, response = buildRuntimeAttr(action, outputs, resolved, response, process)
|
||||
|
||||
if action_log:
|
||||
logging.info(f"{action.name} completed")
|
||||
|
||||
return outputs, response
|
||||
|
||||
@@ -1,32 +1,15 @@
|
||||
import threading
|
||||
from .lifecyclemanager import registerLifecycle
|
||||
|
||||
from .lifecyclemanager import manageLifecycle
|
||||
|
||||
threadlist = []
|
||||
#threadnum = 0
|
||||
|
||||
def buildThread(module, lifecycles):
|
||||
#global threadnum
|
||||
#threadnum += 1
|
||||
|
||||
#threadname = f"thread.{threadnum}"
|
||||
def buildThread(module):
|
||||
|
||||
thread = threading.Thread(
|
||||
target=manageLifecycle,
|
||||
args=(module, lifecycles),
|
||||
args=(module,),
|
||||
name=module.name
|
||||
)
|
||||
|
||||
thread.start()
|
||||
|
||||
registryname = thread.name
|
||||
registryvalue = thread
|
||||
|
||||
lifecycles = registerLifecycle (module, lifecycles, registryname, registryvalue)
|
||||
|
||||
threadlist.append(thread)
|
||||
|
||||
#print(threadlist)
|
||||
#print(lifecycles)
|
||||
|
||||
return thread, lifecycles
|
||||
return thread
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from core.execution.action import buildAction
|
||||
from core.execution.operation import buildOperation
|
||||
from core.execution.monitor import buildMonitor
|
||||
from core.runtime import manageFailure
|
||||
#from core.runtime import manageFailure
|
||||
from core.execution.recursive import buildRecursive
|
||||
|
||||
def executeContract(module, outputs):
|
||||
def executeContract(module, outputs, process):
|
||||
#print("DEBUGGING")
|
||||
#print(module.name)
|
||||
if module.kind == "operation":
|
||||
@@ -15,7 +15,7 @@ def executeContract(module, outputs):
|
||||
|
||||
elif module.kind == "action":
|
||||
|
||||
outputs, response = buildAction(module, outputs)
|
||||
outputs, response = buildAction(module, outputs, process)
|
||||
|
||||
return outputs, response
|
||||
|
||||
|
||||
@@ -1,30 +1,42 @@
|
||||
import time
|
||||
import os
|
||||
|
||||
from core.execution.operation import buildOperation
|
||||
from core.execution.action import buildAction
|
||||
from core.execution.executioncontract import executeContract
|
||||
from core.apirequest.execute import getSession
|
||||
from core.execution.lifecyclemanager.lifecycleregistry import registerLifecycle
|
||||
|
||||
#sleeptime = int(os.environ.get("REFRESH_INTERVAL", 180))
|
||||
lifecycles = {}
|
||||
|
||||
def manageLifecycle(module, lifecycles): #lifecycles, state):
|
||||
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)
|
||||
outputs, response = executeContract(module, outputs, None)
|
||||
|
||||
lifecycle_log = bool(os.environ.get("LOGS_LIFECYCLE", False))
|
||||
if lifecycle_log:
|
||||
print(f"{module.name} thread {lifecycles[module.name][module.name]} running in {lifecycles[module.name]['mode']} mode")
|
||||
print(lifecycles)
|
||||
|
||||
time.sleep(module.sleeptime)
|
||||
lifecycles[module.name]["state"] = "sleep"
|
||||
time.sleep(lifecycles[module.name]["refresh_rate"])
|
||||
lifecycles[module.name]["state"] = "stopped"
|
||||
|
||||
elif lifecycles[module.name]["mode"] == "oneshot":
|
||||
lifecycles[module.name]["state"] = "active"
|
||||
|
||||
if lifecycle_log:
|
||||
print(f"{module.name} thread {lifecycles[module.name][module.name]} running in {lifecycles[module.name]['mode']} mode")
|
||||
print(lifecycles)
|
||||
outputs, response = executeContract(module)
|
||||
|
||||
outputs, response = executeContract(module, outputs, None)
|
||||
|
||||
lifecycles[module.name]["state"] = "stopped"
|
||||
|
||||
#print(lifecycles)
|
||||
return
|
||||
|
||||
@@ -1,8 +1,39 @@
|
||||
def registerLifecycle(module, lifecycles, registryname, registryvalue):
|
||||
import threading
|
||||
|
||||
from core.apirequest.execute import getSession
|
||||
|
||||
def registerLifecycle(module, lifecycles):
|
||||
if module.name not in lifecycles:
|
||||
lifecycles[module.name] = {}
|
||||
|
||||
thread = threading.current_thread()
|
||||
lifecycles[module.name][thread.name] = thread
|
||||
|
||||
session = getSession()
|
||||
|
||||
session_data = {
|
||||
"created_at": session.created_at,
|
||||
"lifetime": 1800,
|
||||
"valid": True
|
||||
}
|
||||
|
||||
session.name = f"{module.name} Session"
|
||||
|
||||
lifecycles[module.name][session.name] = session_data
|
||||
#print(lifecycles)
|
||||
|
||||
if "mode" not in lifecycles[module.name]:
|
||||
mode = getattr(module, "mode")
|
||||
lifecycles[module.name]["mode"] = mode
|
||||
|
||||
if lifecycles[module.name]["mode"] == "continuous":
|
||||
lifecycles[module.name]["refresh_rate"] = module.sleeptime
|
||||
|
||||
if not lifecycles[module.name]["mode"]:
|
||||
lifecycles[module.name]["mode"] = "oneshot"
|
||||
|
||||
#lifecycles[module.name][registryname] = registryvalue
|
||||
|
||||
|
||||
lifecycles[module.name][registryname] = registryvalue
|
||||
|
||||
return lifecycles
|
||||
|
||||
@@ -16,6 +16,9 @@ def buildMonitor(monitor, outputs):
|
||||
|
||||
response, outputs = executeRequest(monitor, outputs, resolved)
|
||||
|
||||
if response is None:
|
||||
return outputs, None
|
||||
|
||||
responsedata = response.json()
|
||||
|
||||
readitems = resolveItem(monitor, responsedata)
|
||||
@@ -24,12 +27,11 @@ def buildMonitor(monitor, outputs):
|
||||
|
||||
outputs = buildOutput(response, monitor, outputs)
|
||||
|
||||
|
||||
if match:
|
||||
module = filter["execute"]
|
||||
|
||||
if module.kind == "action":
|
||||
outputs, response = buildAction(module, outputs)
|
||||
outputs, response = buildAction(module, outputs, None)
|
||||
if module.kind == "operation":
|
||||
outputs, responses = buildOperation(module, outputs)
|
||||
response = responses
|
||||
|
||||
@@ -1,33 +1,69 @@
|
||||
import logging
|
||||
import pprint
|
||||
from rich.progress import track
|
||||
|
||||
from core.runtime.managefailure import manageFailure
|
||||
from core.execution.action.action import buildAction
|
||||
from core.runtime.stopsignals import checkDependency
|
||||
#from core.runtime.skipstep import skipStep
|
||||
#from core.runtime.recursive import recursiveSet
|
||||
from core.execution.processregistry import registerProcess
|
||||
|
||||
|
||||
outputs = {}
|
||||
def buildOperation(definition, outputs):
|
||||
from core.execution.executioncontract import executeContract
|
||||
actions = definition.actions
|
||||
responses = []
|
||||
outputs["stopsignals"] = []
|
||||
for action in actions:
|
||||
stop = checkDependency(action, outputs)
|
||||
|
||||
#print(f"STOP SIGNAL DEBUGGING during {action.name}")
|
||||
#print(outputs["stopsignals"])
|
||||
def buildOperation(definition, outputs):
|
||||
process_log = True
|
||||
|
||||
from core.execution.executioncontract import executeContract
|
||||
|
||||
actions = definition.actions
|
||||
outputs = registerProcess(definition, outputs)
|
||||
responses = []
|
||||
|
||||
if getattr(definition, "track", False):
|
||||
actions = track(
|
||||
actions,
|
||||
#description=definition.name
|
||||
description=f"[green]{definition.name}[/green]"
|
||||
)
|
||||
|
||||
for action in actions:
|
||||
|
||||
#Check if dependencies are in stop signal registry
|
||||
stop = checkDependency(action, outputs, definition)
|
||||
|
||||
if stop:
|
||||
continue
|
||||
|
||||
outputs, response = executeContract(action, outputs)
|
||||
#Register action before its execution
|
||||
if action.kind == "action":
|
||||
outputs["processes"][definition.name][action.name] = {}
|
||||
|
||||
#if hasattr(action, recursive)
|
||||
#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)
|
||||
|
||||
responses.append(response)
|
||||
|
||||
#Register responses in process registry
|
||||
if action.kind == "action":
|
||||
outputs["processes"][definition.name][action.name]["response"] = response
|
||||
|
||||
##Append completed process to process registry
|
||||
outputs["processes"][definition.name]["completed"].append(action.alias)
|
||||
|
||||
#Temporarily disabled manageFailure functions
|
||||
#except Exception as error:
|
||||
#outputs = manageFailure(error, action, outputs)
|
||||
|
||||
#Print completion status after runtime processes
|
||||
if process_log:
|
||||
logging.info(f"{definition.name} completed")
|
||||
|
||||
#For debugging purposes only
|
||||
process_registry_logs = False
|
||||
if process_registry_logs:
|
||||
pprint.pprint(outputs["processes"])
|
||||
|
||||
|
||||
|
||||
return outputs, responses
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
def registerProcess(module, outputs):
|
||||
if not "processes" in outputs:
|
||||
outputs["processes"] = {}
|
||||
|
||||
if not module.name in outputs["processes"]:
|
||||
outputs["processes"][module.name] = {}
|
||||
|
||||
#outputs["processes"][module.name] = {}
|
||||
outputs["processes"][module.name]["stopsignals"] = []
|
||||
outputs["processes"][module.name]["completed"] = []
|
||||
|
||||
return outputs
|
||||
+42
-10
@@ -1,10 +1,23 @@
|
||||
from core.execution import action
|
||||
from core.execution.action.action import buildAction
|
||||
from core.runtime.runtimecontract import buildPreRuntimeAttr, buildRuntimeAttr
|
||||
from core.apirequest import executeRequest
|
||||
import logging
|
||||
import os
|
||||
|
||||
from core.runtime.stopsignals import checkDependency
|
||||
from core.execution.processregistry import registerProcess
|
||||
from rich.progress import track
|
||||
|
||||
def buildRecursive(definition, outputs):
|
||||
process_log = True
|
||||
recursive_log = os.environ.get("LOGS_RECURSIVE", "false").lower() == "true"
|
||||
|
||||
#print(outputs[definition.recursiveset["source"]])
|
||||
|
||||
source = outputs.get(definition.recursiveset["source"])
|
||||
|
||||
if source is None or source == []:
|
||||
return outputs, []
|
||||
|
||||
outputs = registerProcess(definition, outputs)
|
||||
|
||||
responses = []
|
||||
from core.execution.executioncontract import executeContract
|
||||
recursiveset = definition.recursiveset["actions"]
|
||||
@@ -15,9 +28,12 @@ def buildRecursive(definition, outputs):
|
||||
#print(f"RECURSIVE DEBUG DURING {definition.name}")
|
||||
#print(items)
|
||||
|
||||
if items is None:
|
||||
print(f"No items available in {source} for {definition.name}")
|
||||
return outputs, None
|
||||
#if items is None:
|
||||
|
||||
# if recursive_log:
|
||||
# print(f"No items available in {source} for {definition.name}")
|
||||
#
|
||||
# return outputs, None
|
||||
|
||||
reverse = definition.recursiveset.get("reverse", False)
|
||||
|
||||
@@ -25,18 +41,25 @@ def buildRecursive(definition, outputs):
|
||||
#print("reversing")
|
||||
items = reversed(items)
|
||||
|
||||
for item in items:
|
||||
for item in track(
|
||||
items,
|
||||
description=f"[green]{definition.name}[/green]"
|
||||
):
|
||||
|
||||
#for item in items:
|
||||
outputs[definition.recursiveset["outputlabel"]] = item
|
||||
|
||||
outputs["stopsignals"] = []
|
||||
for job in recursiveset:
|
||||
stop = checkDependency(job, outputs)
|
||||
|
||||
stop = checkDependency(job, outputs, definition)
|
||||
|
||||
#print(f"STOP SIGNAL DEBUGGING during {job.name}")
|
||||
#print(outputs["stopsignals"])
|
||||
#print(stop)
|
||||
|
||||
if stop:
|
||||
#outputs["processes"][definition.name]["stopsignals"].append(job.alias)
|
||||
#print("STOP SIGNAL DETECTED")
|
||||
#print(f"Stopping {job.name} due to stop signal")
|
||||
continue
|
||||
@@ -44,9 +67,18 @@ def buildRecursive(definition, outputs):
|
||||
#print(f"RECURSIVE DEBUG DURING {job.name}")
|
||||
#print(item)
|
||||
#outputs, response = buildAction(job, outputs)
|
||||
if job.kind == "action":
|
||||
outputs["processes"][definition.name][job.name] = {}
|
||||
|
||||
outputs, response = executeContract(job, outputs)
|
||||
outputs, response = executeContract(job, outputs, definition)
|
||||
responses.append(response)
|
||||
if job.kind == "action":
|
||||
outputs["processes"][definition.name][job.name]["response"] = response
|
||||
|
||||
outputs["processes"][definition.name]["completed"].append(job.alias)
|
||||
|
||||
if process_log:
|
||||
logging.info(f"{definition.name} completed")
|
||||
|
||||
retain = definition.recursiveset.get("retain", True)
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@ from .outputs import buildOutput
|
||||
from .savedata import buildSave, loadSave, saveRow, readRow
|
||||
from .logs import buildLog
|
||||
#from . import managefailure
|
||||
from .managefailure import manageFailure
|
||||
#from .managefailure import manageFailure
|
||||
from .image import buildImage
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
|
||||
def buildFirewall(listener, outputs):
|
||||
firewall_log = os.environ.get("LOGS_FIREWALL", "false").lower() == "true"
|
||||
|
||||
status_code = 200
|
||||
outputs["firewall_allowed"] = []
|
||||
for item in outputs[listener.recursive["source"]]:
|
||||
|
||||
match, filter = applyConditions(listener, item, outputs)
|
||||
|
||||
if match:
|
||||
status_code = filter.get("status_code", 200)
|
||||
continue
|
||||
|
||||
#This needs to be moved into definitions but until logic is put in place it lives here.
|
||||
if "com.loxthelion.rmass_message_id" in item.get("content", {}):
|
||||
status_code = 200
|
||||
print("Excluding previously imported items")
|
||||
print(f"Returning status_code: {status_code}")
|
||||
|
||||
continue
|
||||
|
||||
outputs["firewall_allowed"].append(item)
|
||||
|
||||
if outputs["firewall_allowed"]:
|
||||
return True, outputs, status_code
|
||||
|
||||
#Needs to be present to prevent TypeError
|
||||
return False, outputs, status_code
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
def buildLog (action, outputs, response):
|
||||
if hasattr(action, "prints"):
|
||||
@@ -12,8 +13,11 @@ def buildLog (action, outputs, response):
|
||||
except (KeyError, TypeError):
|
||||
pass
|
||||
|
||||
response_log = os.environ.get("LOGS_SUCCESS_RESPONSE", "false").lower() == "true"
|
||||
|
||||
if action.showstatus is True and response.ok:
|
||||
print(f"{action.name} successful")
|
||||
if response_log:
|
||||
print(f"{action.name} request successful with response {response.status_code}")
|
||||
|
||||
elif action.showstatus is True and not response.ok:
|
||||
print(f"{action.name} failed with status code {response.status_code}")
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import os
|
||||
|
||||
def resolveItem(action, item):
|
||||
resolver_log = os.environ.get("LOGS_RESOLVER", "false").lower() == "true"
|
||||
|
||||
resolved = {}
|
||||
if hasattr(action, "resolve"):
|
||||
for label, keys in action.resolve["get"].items():
|
||||
@@ -8,6 +12,7 @@ def resolveItem(action, item):
|
||||
target = target[key]
|
||||
|
||||
except (KeyError, IndexError) as error:
|
||||
if resolver_log:
|
||||
print(f"Resolver target key/index {error} not found during {action.name}")
|
||||
target = None
|
||||
|
||||
|
||||
@@ -12,6 +12,6 @@ def responsePolicy(response, action, outputs, resolved):
|
||||
|
||||
response, outputs = executeRequest(policy["execute"], outputs, resolved)
|
||||
|
||||
return outputs, resolved
|
||||
return outputs
|
||||
|
||||
return outputs, resolved
|
||||
return outputs
|
||||
@@ -7,7 +7,7 @@ from core.runtime.applyconditions import applyConditions
|
||||
from core.runtime.responsepolicy import responsePolicy
|
||||
from core.runtime.stopsignals import addStopSignal
|
||||
|
||||
def buildPreRuntimeAttr(action, outputs):
|
||||
def buildPreRuntimeAttr(action, outputs, process):
|
||||
outputs = loadSave(action, outputs)
|
||||
|
||||
resolved = resolveItem(action, outputs)
|
||||
@@ -17,18 +17,21 @@ def buildPreRuntimeAttr(action, outputs):
|
||||
match, filter = applyConditions(action, resolved, outputs)
|
||||
|
||||
if match:
|
||||
outputs = addStopSignal(action, outputs)
|
||||
outputs = addStopSignal(action, outputs, process)
|
||||
|
||||
return outputs, resolved, match, filter
|
||||
|
||||
|
||||
def buildRuntimeAttr(action, outputs, resolved, response):
|
||||
outputs, resolved = responsePolicy(response, action, outputs, resolved)
|
||||
def buildRuntimeAttr(action, outputs, resolved, response, process):
|
||||
outputs = responsePolicy(response, action, outputs, resolved)
|
||||
|
||||
#print(f"Response status code: {response.status_code} during {action.name}")
|
||||
#print(f"Response content: {response.content} during {action.name}")
|
||||
|
||||
outputs = buildOutput(response, action, outputs)
|
||||
|
||||
if not response.ok:
|
||||
outputs = addStopSignal(action, outputs)
|
||||
outputs = addStopSignal(action, outputs, process)
|
||||
return outputs, response
|
||||
|
||||
resolved = extractItem(action, outputs, resolved)
|
||||
|
||||
@@ -2,6 +2,8 @@ import json
|
||||
import os
|
||||
|
||||
def buildSave(action, outputs):
|
||||
savedata_log = os.environ.get("LOGS_SAVE_DATA_ACCESS", "false").lower() == "true"
|
||||
|
||||
import tempfile
|
||||
|
||||
if hasattr(action, "savedata"):
|
||||
@@ -36,10 +38,13 @@ def buildSave(action, outputs):
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
#print(f"Data saved by {action.name} to {action.savepath}")
|
||||
if savedata_log:
|
||||
print(f"Data saved by {action.name} to {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def loadSave(action, outputs):
|
||||
savedata_log = os.environ.get("LOGS_SAVE_DATA_ACCESS", "false").lower() == "true"
|
||||
|
||||
if hasattr(action, "loaddata"):
|
||||
with open(f"{action.savepath}", "r") as save_file:
|
||||
load_data = json.load(save_file)
|
||||
@@ -47,7 +52,8 @@ def loadSave(action, outputs):
|
||||
for load_name in action.loaddata:
|
||||
outputs[load_name] = load_data[load_name]
|
||||
|
||||
#print(f"Data loaded by {action.name} from {action.savepath}")
|
||||
if savedata_log:
|
||||
print(f"Data loaded by {action.name} from {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def saveRow(action, outputs, resolved):
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import os
|
||||
|
||||
def buildSelect(action, outputs):
|
||||
#***THIS IS THE CANONICAL BUILD***
|
||||
|
||||
select_log = savedata_log = os.environ.get("LOGS_SELECT", "false").lower() == "true"
|
||||
|
||||
select_data = []
|
||||
|
||||
if hasattr(action, "select"):
|
||||
#outputs[f"{action.alias}_select"] = []
|
||||
try:
|
||||
target = outputs[action.select["source"]]
|
||||
includekey = action.select["include"]["key"]
|
||||
@@ -27,6 +33,9 @@ def buildSelect(action, outputs):
|
||||
#outputs[{action.select["source"]}] = select_data
|
||||
outputs[f"{action.alias}_select"] = select_data
|
||||
|
||||
#print(select_data)
|
||||
|
||||
if select_log:
|
||||
if select_data is None:
|
||||
print(f"No data selected during {action.name}")
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
def checkDependency(action, outputs):
|
||||
#def checkDependency(action, outputs):
|
||||
def checkDependency(action, outputs, operation):
|
||||
if hasattr(action, "depends"):
|
||||
stop = any(
|
||||
dependency in outputs["stopsignals"]
|
||||
dependency in outputs["processes"][operation.name]["stopsignals"]
|
||||
#dependency in outputs["stopsignals"]
|
||||
for dependency in action.depends
|
||||
)
|
||||
|
||||
@@ -10,8 +12,9 @@ def checkDependency(action, outputs):
|
||||
|
||||
return False
|
||||
|
||||
def addStopSignal(action, outputs):
|
||||
#def addStopSignal(action, outputs):
|
||||
def addStopSignal(action, outputs, operation):
|
||||
if hasattr(action, "depends"):
|
||||
outputs["stopsignals"].append(action.alias)
|
||||
|
||||
outputs["processes"][operation.name]["stopsignals"].append(action.alias)
|
||||
#outputs["stopsignals"].append(action.alias)
|
||||
return outputs
|
||||
@@ -3,6 +3,8 @@ from core.runtime.outputs import buildOutput
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
from core.execution.operation import buildOperation
|
||||
from core.execution.executioncontract import executeContract
|
||||
from core.runtime.firewall import buildFirewall
|
||||
from core.execution.createthread import buildThread
|
||||
|
||||
def buildListener(listener, self):
|
||||
|
||||
@@ -27,25 +29,30 @@ def buildListener(listener, self):
|
||||
|
||||
outputs = buildOutput(data, listener, outputs)
|
||||
|
||||
for item in outputs[listener.recursive["source"]]:
|
||||
#for item in outputs[listener.recursive["source"]]:
|
||||
|
||||
match, filter = applyConditions(listener, item, outputs)
|
||||
#match, filter = applyConditions(listener, item, outputs)
|
||||
|
||||
if not match:
|
||||
if "com.loxthelion.rmass_message_id" in item.get("content", {}):
|
||||
print("Excluding previously imported items")
|
||||
#print(item)
|
||||
continue
|
||||
#if not match:
|
||||
# if "com.loxthelion.rmass_message_id" in item.get("content", {}):
|
||||
# print("Excluding previously imported items")
|
||||
# #print(item)
|
||||
# continue
|
||||
|
||||
allow, item, status_code = buildFirewall(listener, outputs)
|
||||
|
||||
|
||||
if allow:
|
||||
#Print allowed items for logging purposes
|
||||
print(outputs["firewall_allowed"])
|
||||
|
||||
print(item)
|
||||
#Process and forward to RMASS
|
||||
|
||||
outputs, responses = executeContract(listener.execute, outputs)
|
||||
|
||||
continue
|
||||
#thread, lifecycles = buildThread(listener.execute, lifecycles)
|
||||
outputs, responses = executeContract(listener.execute, outputs, None)
|
||||
|
||||
|
||||
self.send_response(200)
|
||||
|
||||
self.send_response(status_code)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", "2")
|
||||
self.end_headers()
|
||||
|
||||
@@ -17,7 +17,7 @@ port = int(os.environ.get("SERVER_PORT", 19001))
|
||||
|
||||
class RequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
lifecycles = {}
|
||||
#lifecycles = {}
|
||||
print("POST request received")
|
||||
|
||||
max_request_size = 1024
|
||||
@@ -97,7 +97,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
|
||||
|
||||
def do_PUT(self):
|
||||
print("PUT request received")
|
||||
#print("PUT request received")
|
||||
|
||||
outputs = buildListener(synapselistener, self)
|
||||
|
||||
|
||||
+12
-8
@@ -1,23 +1,27 @@
|
||||
import threading
|
||||
import logging
|
||||
|
||||
from core.server.server import startServer
|
||||
#from core.execution.lifecyclemanager.lifecycleregistry import registerLifecycle
|
||||
from core.execution.createthread import buildThread
|
||||
from plugins.rmass.monitors import rmassmonitor
|
||||
from plugins.rmass.actions import refresh_tokens
|
||||
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.WARNING,
|
||||
format="%(levelname)s: %(message)s"
|
||||
)
|
||||
|
||||
import login
|
||||
import synapsemessagepush
|
||||
|
||||
lifecycles ={}
|
||||
rmassmonitor.mode = "continuous"
|
||||
refresh_tokens.mode = "continuous"
|
||||
|
||||
thread = buildThread(rmassmonitor)
|
||||
|
||||
lifecycles[rmassmonitor.name] = {}
|
||||
lifecycles[rmassmonitor.name]["mode"] = "continuous"
|
||||
thread, lifecycles = buildThread(rmassmonitor, lifecycles)
|
||||
|
||||
lifecycles[refresh_tokens.name] = {}
|
||||
lifecycles[refresh_tokens.name]["mode"] = "continuous"
|
||||
thread, lifecycles = buildThread(refresh_tokens, lifecycles)
|
||||
thread = buildThread(refresh_tokens)
|
||||
|
||||
thread = threading.Thread(
|
||||
target=startServer,
|
||||
|
||||
@@ -2,7 +2,9 @@ name = "Get CSRF token"
|
||||
|
||||
kind = "action"
|
||||
|
||||
showstatus = True
|
||||
alias = "getcsrf"
|
||||
|
||||
showstatus = False
|
||||
|
||||
method = "GET"
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import os
|
||||
|
||||
name = "Login"
|
||||
|
||||
alias = "login"
|
||||
|
||||
kind = "action"
|
||||
|
||||
showstatus = True
|
||||
|
||||
@@ -77,6 +77,7 @@ responsepolicy = [
|
||||
"statuscode": 400,
|
||||
"print": "Message is too short. Notifying...",
|
||||
"execute": synapsenotify,
|
||||
"response_update": False,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ alias = "synapseassigndmavatar"
|
||||
depends = [
|
||||
"getrmassuseravatar",
|
||||
"rmassavatartosynapse",
|
||||
"synapsegetroomid",
|
||||
"synapsecreatedmroom",
|
||||
#"synapsegetroomid",
|
||||
#"synapsecreatedmroom",
|
||||
]
|
||||
|
||||
kind = "action"
|
||||
|
||||
@@ -6,6 +6,8 @@ showstatus = True
|
||||
|
||||
alias = "synapsegetroomalias"
|
||||
|
||||
depends = []
|
||||
|
||||
## PRE-RUNTIME ACTIONS
|
||||
|
||||
resolve = {
|
||||
|
||||
@@ -4,6 +4,8 @@ name = "Synapse Message Push"
|
||||
|
||||
kind = "action"
|
||||
|
||||
alias = "synapsepushmessagesaction"
|
||||
|
||||
showstatus = True
|
||||
|
||||
resolve = {
|
||||
|
||||
@@ -24,18 +24,21 @@ filters = [
|
||||
"operator": "in",
|
||||
"filtervalue": "state_key",
|
||||
"print": "Excluding state.key event",
|
||||
"status_code": 200,
|
||||
},
|
||||
{
|
||||
"filterkey": "sender",
|
||||
"operator": "!=",
|
||||
"filtervalue": "@lyncoln:loxthelion.com",
|
||||
"print": "Excluding message loop item",
|
||||
"status_code": 200,
|
||||
},
|
||||
{
|
||||
"filterkey": "type",
|
||||
"operator": "!=",
|
||||
"filtervalue": "m.room.message",
|
||||
"print": "Excluding non-room message event",
|
||||
"status_code": 200,
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
@@ -6,7 +6,7 @@ name = "RMASS Message Push"
|
||||
kind = "recursiveset"
|
||||
|
||||
recursiveset = {
|
||||
"source": "events",
|
||||
"source": "firewall_allowed",
|
||||
#"retain": False,
|
||||
"outputlabel": "outmessageitem",
|
||||
"actions": [
|
||||
|
||||
@@ -2,10 +2,14 @@ from plugins.rmass.actions import pullmessagelist, refresh_tokens, getmessage, s
|
||||
from plugins.rmass.operations import getrmassconversations, synapsepushmessageitems
|
||||
|
||||
|
||||
name = "Get Message List"
|
||||
name = "Retrieve and Forward RMASS Messages"
|
||||
|
||||
kind = "operation"
|
||||
|
||||
alias = "synapsemessagepushoperation"
|
||||
|
||||
track = True
|
||||
|
||||
actions = [
|
||||
#refresh_tokens,
|
||||
pullmessagelist,
|
||||
|
||||
@@ -4,6 +4,8 @@ kind = "recursiveset"
|
||||
|
||||
name = "Synapse Attachment Push Recursive Set"
|
||||
|
||||
alias = "synapsepushmessageattachments"
|
||||
|
||||
recursiveset = {
|
||||
"source": "attachment_list",
|
||||
"reverse": False,
|
||||
|
||||
@@ -5,6 +5,8 @@ kind = "recursiveset"
|
||||
|
||||
name = "Synapse Message Push Recursive Set"
|
||||
|
||||
alias = "synapserecursivemessagepush"
|
||||
|
||||
recursiveset = {
|
||||
"source": "getmessage_select",
|
||||
"reverse": True,
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
requests
|
||||
rich
|
||||
@@ -1 +0,0 @@
|
||||
{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTMwNTE5ODUsIm5iZiI6MTc5MzA1MTgwNSwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MzA1MTg2NX0.pMPPsvgYfsRhTj7NJFc0hj3N-8gP1Th3oX9NQce9e2-NJw7ANxFv-7sdmeDE71_B71He7cych-kW5RFuJpc2ZA", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTU2NDM4NjUsIm5iZiI6MTc5MzA1MTgwNSwianRpIjoiU1BJbnZpSXBmTE5WY1NVQ1ZOQ0VvRUdGUWEwOVIrN3dKOHJuNGZqYU5ZMD0iLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MzA1MTg2NSwic3ViIjoiMjM4MzAyIn0.2N1mzB9BYKgd5tMK10ZuBxW0zqNDDmhN8JtVoQAoeKHcm9JtNzdRa4LfsNPiJ1MOzkXBkTBuktmUI8AiDq78YQ"}
|
||||
@@ -11,7 +11,7 @@ def manageLifecycle(module, lifecycles): #lifecycles, state):
|
||||
while lifecycles[module.name]["mode"] == "continuous":
|
||||
print(lifecycles)
|
||||
|
||||
outputs = executeContract(module)
|
||||
outputs = executeContract(module, None, None)
|
||||
|
||||
#print(lifecycles)
|
||||
|
||||
@@ -19,7 +19,7 @@ def manageLifecycle(module, lifecycles): #lifecycles, state):
|
||||
|
||||
elif lifecycles[module.name]["mode"] == "oneshot":
|
||||
print(lifecycles)
|
||||
outputs = executeContract(module)
|
||||
outputs = executeContract(module, None, None)
|
||||
|
||||
#print(lifecycles)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user