Compare commits
82
Commits
3db6a5ae17
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e937d7686 | ||
|
|
75b4cc92da | ||
|
|
f90c3b1424 | ||
|
|
12b28f037a | ||
|
|
4ccd44937f | ||
|
|
53021d381e | ||
|
|
433c1e4b77 | ||
|
|
c230939b45 | ||
|
|
2c2a41fafb | ||
|
|
b3094f75a9 | ||
|
|
b5591ade62 | ||
|
|
fe2a54ca00 | ||
|
|
f2df751294 | ||
|
|
50cb0e0924 | ||
|
|
dafde0a805 | ||
|
|
f10ab522c9 | ||
|
|
476ef608f3 | ||
|
|
63330c9ecd | ||
|
|
b59401c64f | ||
|
|
4189812957 | ||
|
|
1a3caa1022 | ||
|
|
c66d139cca | ||
|
|
9b5feffe93 | ||
|
|
1956b9bed4 | ||
|
|
af2817cc12 | ||
|
|
dd4abbd81a | ||
|
|
afbe0e1add | ||
|
|
8fc85db44a | ||
|
|
a6bd89bb7e | ||
|
|
babd77b1ef | ||
|
|
27d7030963 | ||
|
|
ad2296610c | ||
|
|
d26f3a88af | ||
|
|
14b5727923 | ||
|
|
cdf35a9e68 | ||
|
|
d5fd468498 | ||
|
|
24ea9a7a14 | ||
|
|
4b92e82ea6 | ||
|
|
950707386a | ||
|
|
d492d78a70 | ||
|
|
a574a595dc | ||
|
|
717988c53b | ||
|
|
0ca65c7c6d | ||
|
|
25c5d642b3 | ||
|
|
8a784cdaec | ||
|
|
71f27e27e0 | ||
|
|
e456902a1d | ||
|
|
925e35f38e | ||
|
|
fafbabd9e8 | ||
|
|
0322eca845 | ||
|
|
a48e761622 | ||
|
|
a42c5446d8 | ||
|
|
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,8 +0,0 @@
|
||||
.git
|
||||
.gitignore
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.venv/
|
||||
venv/
|
||||
@@ -0,0 +1,182 @@
|
||||
|
||||
name: Build and Publish RMManager Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# ---------------------------------------------
|
||||
# Checkout repository (no external actions)
|
||||
# ---------------------------------------------
|
||||
- name: Checkout repository
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.TEA_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
BASE="${GITHUB_SERVER_URL%/}"
|
||||
REPO="${GITHUB_REPOSITORY}"
|
||||
|
||||
git init .
|
||||
git remote add origin "$BASE/$REPO.git"
|
||||
|
||||
if [ -n "${GITEA_TOKEN:-}" ]; then
|
||||
AUTH="$(printf 'oauth2:%s' "$GITEA_TOKEN" | base64 -w0)"
|
||||
git -c "http.extraHeader=Authorization: Basic $AUTH" \
|
||||
fetch --depth 1 origin "$GITHUB_SHA"
|
||||
else
|
||||
git fetch --depth 1 origin "$GITHUB_SHA"
|
||||
fi
|
||||
|
||||
git checkout --detach FETCH_HEAD
|
||||
git config --global --add safe.directory "$PWD"
|
||||
|
||||
# ---------------------------------------------
|
||||
# Determine image version and commit SHA
|
||||
# ---------------------------------------------
|
||||
- name: Determine version
|
||||
id: version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
SHORT_SHA="$(git rev-parse --short=7 HEAD)"
|
||||
echo "sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
|
||||
|
||||
if [ -f VERSION ]; then
|
||||
VERSION="$(tr -d '[:space:]' < VERSION)"
|
||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "version=" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------
|
||||
# Login to Gitea container registry
|
||||
# ---------------------------------------------
|
||||
- name: Docker login
|
||||
env:
|
||||
REGISTRY: ${{ vars.REGISTRY }}
|
||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||
REGISTRY_TOKEN: ${{ secrets.TEA_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" \
|
||||
-u "$REGISTRY_USER" \
|
||||
--password-stdin
|
||||
|
||||
# ---------------------------------------------
|
||||
# Build and export container image
|
||||
# ---------------------------------------------
|
||||
- name: Build RMManager image
|
||||
env:
|
||||
REGISTRY: ${{ vars.REGISTRY }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
SHORT_SHA: ${{ steps.version.outputs.sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
FULL_IMAGE="$REGISTRY/david/rmmanager"
|
||||
|
||||
docker build \
|
||||
-f Containerfile \
|
||||
-t "$FULL_IMAGE:latest" \
|
||||
-t "$FULL_IMAGE:sha-$SHORT_SHA" \
|
||||
--output "type=docker,dest=$RUNNER_TEMP/rmmanager-built.tar" \
|
||||
.
|
||||
|
||||
# ---------------------------------------------
|
||||
# Load exported image into Docker
|
||||
# ---------------------------------------------
|
||||
- name: Load RMManager image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
docker load \
|
||||
--input "$RUNNER_TEMP/rmmanager-built.tar"
|
||||
|
||||
# ---------------------------------------------
|
||||
# Add optional version tag
|
||||
# ---------------------------------------------
|
||||
- name: Tag RMManager image
|
||||
env:
|
||||
REGISTRY: ${{ vars.REGISTRY }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
FULL_IMAGE="$REGISTRY/david/rmmanager"
|
||||
|
||||
if [ -n "$VERSION" ]; then
|
||||
docker tag \
|
||||
"$FULL_IMAGE:latest" \
|
||||
"$FULL_IMAGE:v$VERSION"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------
|
||||
# Verify local image and tags
|
||||
# ---------------------------------------------
|
||||
- name: Verify RMManager image
|
||||
env:
|
||||
REGISTRY: ${{ vars.REGISTRY }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
SHORT_SHA: ${{ steps.version.outputs.sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
FULL_IMAGE="$REGISTRY/david/rmmanager"
|
||||
|
||||
docker version
|
||||
docker image ls
|
||||
|
||||
docker image inspect "$FULL_IMAGE:latest"
|
||||
docker image inspect "$FULL_IMAGE:sha-$SHORT_SHA"
|
||||
|
||||
if [ -n "$VERSION" ]; then
|
||||
docker image inspect "$FULL_IMAGE:v$VERSION"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------
|
||||
# Publish image to Gitea registry
|
||||
# ---------------------------------------------
|
||||
- name: Push RMManager image
|
||||
env:
|
||||
REGISTRY: ${{ vars.REGISTRY }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
SHORT_SHA: ${{ steps.version.outputs.sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
FULL_IMAGE="$REGISTRY/david/rmmanager"
|
||||
|
||||
docker push "$FULL_IMAGE:latest"
|
||||
docker push "$FULL_IMAGE:sha-$SHORT_SHA"
|
||||
|
||||
if [ -n "$VERSION" ]; then
|
||||
docker push "$FULL_IMAGE:v$VERSION"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------
|
||||
# Report successful build
|
||||
# ---------------------------------------------
|
||||
- name: Report build
|
||||
env:
|
||||
REGISTRY: ${{ vars.REGISTRY }}
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
SHORT_SHA: ${{ steps.version.outputs.sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
echo "RMManager build and publish completed"
|
||||
echo "Image: $REGISTRY/david/rmmanager"
|
||||
echo "Latest tag: latest"
|
||||
echo "Commit tag: sha-$SHORT_SHA"
|
||||
|
||||
if [ -n "$VERSION" ]; then
|
||||
echo "Version tag: v$VERSION"
|
||||
fi
|
||||
+7
-1
@@ -23,4 +23,10 @@ env/
|
||||
savedata/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
*.log
|
||||
|
||||
#Trash and unused files
|
||||
trash/
|
||||
|
||||
#Docker files
|
||||
.dockerignore
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
from plugins import rmass
|
||||
from core import buildOperation
|
||||
|
||||
outputs = buildOperation(rmass.operations.checkavailable)
|
||||
responses = buildOperation(rmass.operations.checkavailable)
|
||||
|
||||
|
||||
+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
|
||||
|
||||
+29
-44
@@ -1,8 +1,12 @@
|
||||
import requests
|
||||
import threading
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
|
||||
from .request import buildRequest
|
||||
|
||||
|
||||
#session = requests.Session()
|
||||
_thread_local = threading.local()
|
||||
|
||||
@@ -15,15 +19,17 @@ 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
|
||||
|
||||
|
||||
def executeRequest(action, outputs, resolved):
|
||||
from core.execution.lifecyclemanager.lifecyclemanager import lifecycles
|
||||
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(
|
||||
@@ -32,8 +38,15 @@ def executeRequest(action, outputs, resolved):
|
||||
)
|
||||
|
||||
for attempt in range(2):
|
||||
request, outputs = buildRequest(action, outputs, resolved)
|
||||
request = buildRequest(action, outputs, resolved)
|
||||
try:
|
||||
|
||||
if action.name in lifecycles:
|
||||
request_info = {"Started at": time.monotonic()}
|
||||
lifecycles[action.name]["Request Information"] = request_info
|
||||
|
||||
snapshot = lifecycles.copy()
|
||||
|
||||
response = session.request(
|
||||
method=request["method"],
|
||||
url=request["path"],
|
||||
@@ -43,51 +56,23 @@ def executeRequest(action, outputs, resolved):
|
||||
files=request.get("files"),
|
||||
timeout=(10, 30)
|
||||
)
|
||||
return response, outputs
|
||||
|
||||
logging.debug(snapshot)
|
||||
|
||||
return response
|
||||
|
||||
except (requests.Timeout, requests.ConnectionError) as error:
|
||||
print(f"{type(error).__name__} during {action.name}: {error}")
|
||||
#print(f"{type(error).__name__} during {action.name}: {error}")
|
||||
|
||||
logging.warning(f"{type(error).__name__} during {action.name}: {error}")
|
||||
logging.debug("LIFECYCLE STATE BEFORE REQUEST")
|
||||
logging.debug(snapshot)
|
||||
logging.debug("LIFECYCLE STATE AFTER REQUEST")
|
||||
logging.debug(lifecycles)
|
||||
|
||||
session = getSession(reset=True)
|
||||
|
||||
if attempt == 0:
|
||||
print(f"Retrying {action.name}")
|
||||
logging.warning(f"Retrying {action.name}")
|
||||
|
||||
return None, outputs
|
||||
|
||||
# try:
|
||||
# request, outputs = buildRequest(action, outputs, resolved)
|
||||
#
|
||||
# response = session.request(
|
||||
# method=request["method"],
|
||||
# url=request["path"],
|
||||
# json=request.get("object"),
|
||||
# headers=request.get("headers"),
|
||||
# data=request.get("data"),
|
||||
# files=request.get("files"),
|
||||
# timeout=(10, 30)
|
||||
# )
|
||||
#
|
||||
# except requests.ConnectionError as error:
|
||||
# print(f"Request failed due to {error} during {action.name}")
|
||||
#
|
||||
# session = getSession(reset=True)
|
||||
#
|
||||
# print(f"Retrying {action.name}")
|
||||
#
|
||||
# response = session.request(
|
||||
# method=request["method"],
|
||||
# url=request["path"],
|
||||
# json=request.get("object"),
|
||||
# headers=request.get("headers"),
|
||||
# data=request.get("data"),
|
||||
# files=request.get("files"),
|
||||
# timeout=(10, 30)
|
||||
# )
|
||||
#
|
||||
# return response, outputs
|
||||
#
|
||||
# except requests.Timeout as error:
|
||||
# print(f"Request timed out during {action.name}: {error}")
|
||||
# session = getSession(reset=True)
|
||||
#
|
||||
# return response, outputs
|
||||
return None
|
||||
|
||||
@@ -18,12 +18,15 @@ 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,
|
||||
resolved
|
||||
)
|
||||
)
|
||||
# resolveddata = definition.requestdata
|
||||
#
|
||||
# if isinstance(resolveddata, dict):
|
||||
@@ -43,4 +46,4 @@ def buildRequest(definition, outputs, resolved):
|
||||
"image/jpeg",
|
||||
),
|
||||
}
|
||||
return request, outputs
|
||||
return request
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from rich.console import Console
|
||||
|
||||
console = Console(stderr=True)
|
||||
@@ -1,24 +1,31 @@
|
||||
import logging
|
||||
|
||||
from core.apirequest import executeRequest
|
||||
from core.runtime.runtimecontract import buildRuntimeAttr, buildPreRuntimeAttr
|
||||
from core.runtime.stopsignals import addStopSignal
|
||||
|
||||
|
||||
def buildAction (action, outputs):
|
||||
action_log = True
|
||||
|
||||
outputs, resolved, match, filter = buildPreRuntimeAttr(action, outputs)
|
||||
resolved, match, filter = buildPreRuntimeAttr(action, outputs)
|
||||
|
||||
if hasattr(action, "allowaction"):
|
||||
if not action.allowaction:
|
||||
return outputs, None
|
||||
return None
|
||||
|
||||
if match:
|
||||
return outputs, None
|
||||
if filter.get("execute", False):
|
||||
response = executeRequest(filter["execute"], outputs, resolved)
|
||||
|
||||
return None
|
||||
|
||||
response, outputs = executeRequest(action, outputs, resolved)
|
||||
response = executeRequest(action, outputs, resolved)
|
||||
|
||||
if response is None:
|
||||
return outputs, None
|
||||
|
||||
outputs, response = buildRuntimeAttr(action, outputs, resolved, response)
|
||||
response = buildRuntimeAttr(action, outputs, resolved, response)
|
||||
|
||||
return outputs, response
|
||||
if action_log:
|
||||
logging.info(f"{action.name} completed")
|
||||
|
||||
return response
|
||||
|
||||
@@ -1,32 +1,18 @@
|
||||
import threading
|
||||
from .lifecyclemanager import registerLifecycle
|
||||
import logging
|
||||
|
||||
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
|
||||
logging.info(f"THREAD STARTED, {thread}")
|
||||
|
||||
lifecycles = registerLifecycle (module, lifecycles, registryname, registryvalue)
|
||||
|
||||
threadlist.append(thread)
|
||||
|
||||
#print(threadlist)
|
||||
#print(lifecycles)
|
||||
|
||||
return thread, lifecycles
|
||||
return thread
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
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
|
||||
from core.runtime.createruntime import outputs
|
||||
|
||||
def executeContract(module):
|
||||
|
||||
def executeContract(module, outputs):
|
||||
#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":
|
||||
response = buildAction(module, outputs)
|
||||
|
||||
outputs, response = buildAction(module, outputs)
|
||||
|
||||
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)
|
||||
@@ -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 = {}
|
||||
#outputs = {}
|
||||
|
||||
def manageLifecycle(module, lifecycles): #lifecycles, state):
|
||||
def manageLifecycle(module):
|
||||
from core.runtime.createruntime import outputs
|
||||
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)
|
||||
executeContract(module)
|
||||
|
||||
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")
|
||||
|
||||
time.sleep(module.sleeptime)
|
||||
print(lifecycles)
|
||||
|
||||
lifecycles[module.name]["state"] = "sleep"
|
||||
time.sleep(lifecycles[module.name]["refresh_rate"])
|
||||
lifecycles[module.name]["state"] = "stopped"
|
||||
|
||||
elif lifecycles[module.name]["mode"] == "oneshot":
|
||||
print(lifecycles)
|
||||
outputs, response = executeContract(module)
|
||||
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)
|
||||
|
||||
response = executeContract(module)
|
||||
|
||||
lifecycles[module.name]["state"] = "stopped"
|
||||
|
||||
#print(lifecycles)
|
||||
return
|
||||
|
||||
@@ -1,8 +1,42 @@
|
||||
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
|
||||
|
||||
lifecycles[module.name][registryname] = registryvalue
|
||||
session = getSession()
|
||||
|
||||
return lifecycles
|
||||
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]:
|
||||
if hasattr(module, "mode"):
|
||||
mode = getattr(module, "mode")
|
||||
lifecycles[module.name]["mode"] = mode
|
||||
else:
|
||||
lifecycles[module.name]["mode"] = "oneshot"
|
||||
|
||||
if lifecycles[module.name]["mode"] == "continuous":
|
||||
lifecycles[module.name]["refresh_rate"] = module.sleeptime
|
||||
|
||||
#if lifecycles[module.name]["mode"] == {}:
|
||||
# lifecycles[module.name]["mode"] = "oneshot"
|
||||
|
||||
#lifecycles[module.name][registryname] = registryvalue
|
||||
|
||||
|
||||
|
||||
return
|
||||
|
||||
+22
-15
@@ -1,10 +1,8 @@
|
||||
#from core.execution.executioncontract import executeContract
|
||||
from core.execution.action import buildAction
|
||||
from core.execution.operation import buildOperation
|
||||
import logging
|
||||
|
||||
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
|
||||
|
||||
@@ -12,9 +10,17 @@ outputs = {}
|
||||
resolved = {}
|
||||
|
||||
def buildMonitor(monitor, outputs):
|
||||
outputs = loadSave(monitor, outputs)
|
||||
loadSave(monitor, outputs)
|
||||
|
||||
response, outputs = executeRequest(monitor, outputs, resolved)
|
||||
response = executeRequest(monitor, outputs, resolved)
|
||||
|
||||
##Potentially replace response processing with responsePolicy
|
||||
if response is None:
|
||||
return None
|
||||
|
||||
if not response.ok:
|
||||
logging.warning(f"Response with status code {response.status_code} during {monitor.name}")
|
||||
return response
|
||||
|
||||
responsedata = response.json()
|
||||
|
||||
@@ -22,16 +28,17 @@ def buildMonitor(monitor, outputs):
|
||||
|
||||
match, filter = applyConditions(monitor, readitems, outputs)
|
||||
|
||||
outputs = buildOutput(response, monitor, outputs)
|
||||
|
||||
buildOutput(response, monitor, outputs)
|
||||
|
||||
if match:
|
||||
module = filter["execute"]
|
||||
from core.execution.createthread import buildThread
|
||||
#from core.execution.executioncontract import executeContract
|
||||
|
||||
if module.kind == "action":
|
||||
outputs, response = buildAction(module, outputs)
|
||||
if module.kind == "operation":
|
||||
outputs, responses = buildOperation(module, outputs)
|
||||
response = responses
|
||||
logging.info(filter.get("print"))
|
||||
#module = filter["execute"]
|
||||
|
||||
#response = executeContract(filter["execute"], outputs)
|
||||
|
||||
return outputs, response
|
||||
thread = buildThread(filter["execute"])
|
||||
|
||||
return response
|
||||
@@ -1,33 +1,73 @@
|
||||
import logging
|
||||
import pprint
|
||||
from rich.progress import track
|
||||
from rich.console import Console
|
||||
|
||||
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 import processregistry
|
||||
from core.console import console
|
||||
|
||||
#outputs = {}
|
||||
|
||||
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"])
|
||||
process_log = True
|
||||
|
||||
actions = definition.actions
|
||||
|
||||
responses = []
|
||||
|
||||
currentOp = processregistry.registerProcess(definition)
|
||||
|
||||
if getattr(definition, "track", False):
|
||||
actions = track(
|
||||
actions,
|
||||
description=f"[green]{definition.name}[/green]",
|
||||
console=console
|
||||
)
|
||||
|
||||
for action in actions:
|
||||
processregistry.registeredOp = currentOp
|
||||
|
||||
stop = checkDependency(action)
|
||||
|
||||
if stop:
|
||||
continue
|
||||
|
||||
outputs, response = executeContract(action, outputs)
|
||||
|
||||
#if hasattr(action, recursive)
|
||||
if action.kind == "action":
|
||||
currentOp[action.name] = {}
|
||||
|
||||
from core.execution.executioncontract import executeContract
|
||||
|
||||
response = executeContract(action)
|
||||
|
||||
responses.append(response)
|
||||
|
||||
if action.kind == "action":
|
||||
currentOp[action.name]["response"] = response
|
||||
|
||||
if action.alias in currentOp["stopsignals"]:
|
||||
continue
|
||||
currentOp["completed"].append(action.alias)
|
||||
|
||||
#Temporarily disabled manageFailure functions
|
||||
#except Exception as error:
|
||||
#outputs = manageFailure(error, action, outputs)
|
||||
|
||||
if process_log:
|
||||
completed_count = len(currentOp["completed"])
|
||||
|
||||
if completed_count == 0:
|
||||
logging.info(f"{definition.name} bypassed")
|
||||
else:
|
||||
logging.info(f"{definition.name} completed")
|
||||
|
||||
|
||||
process_registry_logs = False
|
||||
|
||||
if process_registry_logs:
|
||||
import pprint
|
||||
pprint.pprint(processregistry.processes)
|
||||
|
||||
return outputs, responses
|
||||
return responses
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
processes = {}
|
||||
registeredOp = {}
|
||||
|
||||
def registerProcess(module):
|
||||
#global registeredOp
|
||||
|
||||
processes[module.name] = {}
|
||||
|
||||
registeredOp = processes[module.name]
|
||||
|
||||
processes[module.name]["stopsignals"] = []
|
||||
processes[module.name]["completed"] = []
|
||||
|
||||
return registeredOp
|
||||
+53
-24
@@ -1,53 +1,76 @@
|
||||
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 import processregistry
|
||||
from rich.progress import track
|
||||
from core.console import console
|
||||
|
||||
def buildRecursive(definition, outputs):
|
||||
process_log = True
|
||||
recursive_log = os.environ.get("LOGS_RECURSIVE", "false").lower() == "true"
|
||||
|
||||
source = outputs.get(definition.recursiveset["source"])
|
||||
|
||||
if source is None or source == []:
|
||||
if recursive_log:
|
||||
logging.debug(f"No items available in {source} for {definition.name}")
|
||||
return outputs, []
|
||||
|
||||
currentOp = processregistry.registerProcess(definition)
|
||||
|
||||
responses = []
|
||||
from core.execution.executioncontract import executeContract
|
||||
|
||||
recursiveset = definition.recursiveset["actions"]
|
||||
|
||||
source = definition.recursiveset["source"]
|
||||
|
||||
items = outputs.get(source)
|
||||
#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
|
||||
|
||||
reverse = definition.recursiveset.get("reverse", False)
|
||||
|
||||
if reverse:
|
||||
#print("reversing")
|
||||
items = reversed(items)
|
||||
|
||||
for item in items:
|
||||
for item in track(
|
||||
items,
|
||||
description=f"[green]{definition.name}[/green]",
|
||||
console=console
|
||||
):
|
||||
|
||||
#for item in items:
|
||||
outputs[definition.recursiveset["outputlabel"]] = item
|
||||
|
||||
outputs["stopsignals"] = []
|
||||
for job in recursiveset:
|
||||
stop = checkDependency(job, outputs)
|
||||
processregistry.registeredOp = currentOp
|
||||
|
||||
#print(f"STOP SIGNAL DEBUGGING during {job.name}")
|
||||
#print(outputs["stopsignals"])
|
||||
#print(stop)
|
||||
stop = checkDependency(job)
|
||||
|
||||
if stop:
|
||||
#print("STOP SIGNAL DETECTED")
|
||||
#print(f"Stopping {job.name} due to stop signal")
|
||||
continue
|
||||
|
||||
#print(f"RECURSIVE DEBUG DURING {job.name}")
|
||||
#print(item)
|
||||
#outputs, response = buildAction(job, outputs)
|
||||
if job.kind == "action":
|
||||
currentOp[job.name] = {}
|
||||
|
||||
from core.execution.executioncontract import executeContract
|
||||
|
||||
outputs, response = executeContract(job, outputs)
|
||||
response = executeContract(job)
|
||||
responses.append(response)
|
||||
|
||||
if job.kind == "action":
|
||||
currentOp[job.name]["response"] = response
|
||||
|
||||
currentOp["completed"].append(job.alias)
|
||||
|
||||
if process_log:
|
||||
completed_count = len(currentOp["completed"])
|
||||
|
||||
if completed_count == 0:
|
||||
logging.info(f"{definition.name} bypassed")
|
||||
else:
|
||||
logging.info(f"{definition.name} completed")
|
||||
|
||||
retain = definition.recursiveset.get("retain", True)
|
||||
|
||||
if not retain:
|
||||
@@ -55,4 +78,10 @@ def buildRecursive(definition, outputs):
|
||||
|
||||
outputs.pop("stopsignals", None)
|
||||
|
||||
return outputs, responses
|
||||
process_registry_logs = False
|
||||
|
||||
if process_registry_logs:
|
||||
import pprint
|
||||
pprint.pprint(processregistry.processes)
|
||||
|
||||
return responses
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,58 +17,56 @@ def applyConditions(definition, dictionary, outputs):
|
||||
if filtervalue is None:
|
||||
continue
|
||||
|
||||
resolvedvalue = dictionary.get(filter["filterkey"])
|
||||
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"] == ">=":
|
||||
if int(resolvedvalue or 0) >= int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "<=":
|
||||
if int(resolvedvalue or 0) <= int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "==":
|
||||
if resolvedvalue == filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "!=":
|
||||
if resolvedvalue != filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == ">":
|
||||
if int(resolvedvalue or 0) > int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "<":
|
||||
if int(resolvedvalue or 0) < int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "in":
|
||||
if filtervalue in dictionary:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
if filter["filterkey"] == "called_dictionary":
|
||||
if filtervalue in dictionary:
|
||||
return True, filter
|
||||
else:
|
||||
if filtervalue in dictionary.get(filter["filterkey"], {}):
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "is":
|
||||
if resolvedvalue is filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "is not":
|
||||
if resolvedvalue is not filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
except KeyError:
|
||||
print(f"Value not present in runtime for filtering during {definition.name}")
|
||||
#print(filter)
|
||||
return True, filter
|
||||
#continue
|
||||
|
||||
#except TypeError:
|
||||
# print("TypeError")
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
outputs = {}
|
||||
|
||||
def getOuputs():
|
||||
return outputs
|
||||
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
from core.runtime.resolver import resolveItem
|
||||
|
||||
|
||||
def buildFirewall(listener, outputs):
|
||||
if hasattr(listener, "filters"):
|
||||
#firewall_log = os.environ.get("LOGS_FIREWALL", "false").lower() == "true"
|
||||
firewall_log = True
|
||||
|
||||
status_code = 200
|
||||
outputs["firewall_allowed"] = []
|
||||
for item in outputs[listener.recursive["source"]]:
|
||||
resolved = resolveItem(listener, item)
|
||||
|
||||
match, filter = applyConditions(listener, resolved, outputs)
|
||||
|
||||
if match:
|
||||
status_code = filter.get("status_code", 200)
|
||||
|
||||
if filter.get("execute", False):
|
||||
from core.execution.createthread import buildThread
|
||||
|
||||
thread = buildThread(filter["execute"])
|
||||
|
||||
if firewall_log:
|
||||
logging.info(filter.get("print"))
|
||||
logging.info(f"Returning status_code: {status_code}")
|
||||
continue
|
||||
|
||||
outputs["firewall_allowed"].append(item)
|
||||
|
||||
if outputs["firewall_allowed"] != []:
|
||||
return True, status_code
|
||||
|
||||
#Needs to be present to prevent TypeError
|
||||
return False, status_code
|
||||
@@ -12,4 +12,4 @@ def buildImage(response, action, outputs):
|
||||
else:
|
||||
print("No response received"),
|
||||
|
||||
return outputs
|
||||
return
|
||||
@@ -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,4 @@
|
||||
from core.runtime.outputs import buildOutput
|
||||
#from core.runtime.outputs import buildOutput
|
||||
from core.execution.action.action import buildAction
|
||||
#from core.runtime.outputs import buildOutput
|
||||
|
||||
@@ -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)
|
||||
response = buildAction(repair, outputs)
|
||||
|
||||
return outputs
|
||||
print(f"{error}")
|
||||
|
||||
@@ -53,6 +53,6 @@ def buildOutput(response, action, outputs):
|
||||
#else:
|
||||
# print("No response received"),
|
||||
|
||||
return outputs
|
||||
return
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
def resolveItem(action, item):
|
||||
#resolver_log = os.environ.get("LOGS_RESOLVER", "false").lower() == "true"
|
||||
resolver_log = True
|
||||
|
||||
resolved = {}
|
||||
if hasattr(action, "resolve"):
|
||||
for label, keys in action.resolve["get"].items():
|
||||
target = item
|
||||
try:
|
||||
for key in keys:
|
||||
target = target[key]
|
||||
for key in keys:
|
||||
if isinstance(target, dict):
|
||||
target = target.get(key)
|
||||
else:
|
||||
target = target[key]
|
||||
|
||||
except (KeyError, IndexError) as error:
|
||||
print(f"Resolver target key/index {error} not found during {action.name}")
|
||||
if resolver_log:
|
||||
logging.info(f"Resolver target key/index {error} not found during {action.name}")
|
||||
target = None
|
||||
|
||||
resolved[label] = target
|
||||
@@ -88,6 +98,7 @@ def resolveItem2(action, item):
|
||||
return resolved
|
||||
|
||||
def extractItem(action, item, resolved):
|
||||
#UNDER RUNTIME CONTRACT ITEM IS OUTPUTS
|
||||
if hasattr(action, "extract"):
|
||||
for label, keys in action.extract["get"].items():
|
||||
#resolved[label] = {}
|
||||
@@ -130,4 +141,4 @@ def extractItem(action, item, resolved):
|
||||
|
||||
resolved[source] = deconstructed
|
||||
|
||||
return resolved
|
||||
return
|
||||
@@ -1,17 +1,37 @@
|
||||
#from core.execution.action import buildAction
|
||||
import logging
|
||||
|
||||
from core.apirequest import executeRequest
|
||||
from core.execution import processregistry
|
||||
|
||||
def responsePolicy(response, action, outputs, resolved):
|
||||
if hasattr(action, "responsepolicy"):
|
||||
#if processregistry.registeredOp:
|
||||
#currentOp = processregistry.registeredOp
|
||||
#print(registeredOp[action.name]["response"])
|
||||
#print(currentOp)
|
||||
|
||||
if not response.ok:
|
||||
print(response)
|
||||
logging.warning(f"{response} during {action.name}")
|
||||
|
||||
for policy in action.responsepolicy:
|
||||
if policy["statuscode"] == response.status_code:
|
||||
print(policy["print"])
|
||||
logging.warning(policy["print"])
|
||||
|
||||
response, outputs = executeRequest(policy["execute"], outputs, resolved)
|
||||
from core.execution.executioncontract import executeContract
|
||||
executeContract(policy["execute"])
|
||||
|
||||
return outputs, resolved
|
||||
#newresponse = executeRequest(action, outputs, resolved)
|
||||
|
||||
if policy["response_update"]:
|
||||
logging.info("Updating response")
|
||||
newresponse = executeRequest(action, outputs, resolved)
|
||||
|
||||
#response = newresponse
|
||||
if processregistry.registeredOp:
|
||||
response = processregistry.registeredOp[action.name]["response"]
|
||||
else:
|
||||
response = newresponse
|
||||
|
||||
break
|
||||
|
||||
return outputs, resolved
|
||||
return response
|
||||
@@ -1,41 +1,46 @@
|
||||
from core.execution.action import action
|
||||
from core.runtime import buildSelect, buildOutput, buildSave, loadSave, saveRow, readRow, buildLog
|
||||
from core.runtime.image import buildImage
|
||||
#from core.runtime.select import buildSelect3
|
||||
from core.runtime.resolver import resolveItem, extractItem
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
from core.runtime.responsepolicy import responsePolicy
|
||||
import logging
|
||||
|
||||
from core.runtime.stopsignals import addStopSignal
|
||||
|
||||
def buildPreRuntimeAttr(action, outputs):
|
||||
outputs = loadSave(action, outputs)
|
||||
from core.runtime import loadSave, readRow
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
from core.runtime.resolver import resolveItem
|
||||
|
||||
loadSave(action, outputs)
|
||||
|
||||
resolved = resolveItem(action, outputs)
|
||||
|
||||
resolved, outputs = readRow(action, resolved, outputs)
|
||||
readRow(action, resolved, outputs)
|
||||
|
||||
match, filter = applyConditions(action, resolved, outputs)
|
||||
|
||||
if match:
|
||||
outputs = addStopSignal(action, outputs)
|
||||
logging.info(filter.get("print"))
|
||||
addStopSignal(action)
|
||||
|
||||
return outputs, resolved, match, filter
|
||||
return resolved, match, filter
|
||||
|
||||
|
||||
def buildRuntimeAttr(action, outputs, resolved, response):
|
||||
outputs, resolved = responsePolicy(response, action, outputs, resolved)
|
||||
from core.runtime.resolver import extractItem
|
||||
from core.runtime.responsepolicy import responsePolicy
|
||||
from core.runtime.image import buildImage
|
||||
from core.runtime import buildSelect, buildOutput, buildSave, saveRow, buildLog
|
||||
|
||||
outputs = buildOutput(response, action, outputs)
|
||||
response = responsePolicy(response, action, outputs, resolved)
|
||||
|
||||
buildOutput(response, action, outputs)
|
||||
|
||||
if not response.ok:
|
||||
outputs = addStopSignal(action, outputs)
|
||||
addStopSignal(action)
|
||||
return outputs, response
|
||||
|
||||
resolved = extractItem(action, outputs, resolved)
|
||||
extractItem(action, outputs, resolved)
|
||||
|
||||
outputs = buildImage(response, action, outputs)
|
||||
buildImage(response, action, outputs)
|
||||
|
||||
action, outputs = buildSelect(action, outputs)
|
||||
buildSelect(action, outputs)
|
||||
|
||||
buildSave(action, outputs)
|
||||
|
||||
@@ -43,4 +48,4 @@ def buildRuntimeAttr(action, outputs, resolved, response):
|
||||
|
||||
buildLog(action, outputs, response)
|
||||
|
||||
return outputs, response
|
||||
return response
|
||||
+25
-20
@@ -1,7 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
|
||||
def buildSave(action, outputs):
|
||||
savedata_log = os.environ.get("LOGS_SAVE_DATA_ACCESS", "false").lower() == "true"
|
||||
|
||||
import tempfile
|
||||
|
||||
if hasattr(action, "savedata"):
|
||||
@@ -36,10 +39,13 @@ def buildSave(action, outputs):
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
#print(f"Data saved by {action.name} to {action.savepath}")
|
||||
return outputs
|
||||
if savedata_log:
|
||||
logging.info(f"Data saved by {action.name} to {action.savepath}")
|
||||
return
|
||||
|
||||
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,8 +53,9 @@ 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}")
|
||||
return outputs
|
||||
if savedata_log:
|
||||
logging.info(f"Data loaded by {action.name} from {action.savepath}")
|
||||
return
|
||||
|
||||
def saveRow(action, outputs, resolved):
|
||||
import sqlite3
|
||||
@@ -81,8 +88,8 @@ def saveRow(action, outputs, resolved):
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
except KeyError as error:
|
||||
print(f"The save data for {error} was not located in its respective dictionary during {action.name}")
|
||||
print("Bypassing database save")
|
||||
logging.error(f"The save data for {error} was not located in its respective dictionary during {action.name}")
|
||||
logging.error("Bypassing database save")
|
||||
return False
|
||||
|
||||
values.append(value)
|
||||
@@ -131,7 +138,7 @@ def saveRow(action, outputs, resolved):
|
||||
database.execute(query, tuple(values))
|
||||
|
||||
except sqlite3.IntegrityError as error:
|
||||
print(f"Unable to complete database write during {action.name}: {error}")
|
||||
logging.error(f"Unable to complete database write during {action.name}: {error}")
|
||||
return False
|
||||
|
||||
#database.execute(
|
||||
@@ -142,9 +149,9 @@ def saveRow(action, outputs, resolved):
|
||||
#database.commit()
|
||||
#database.close()
|
||||
|
||||
print(f"Successfully saved data to {table} during {action.name}")
|
||||
logging.info(f"Successfully saved data to {table} during {action.name}")
|
||||
|
||||
return True
|
||||
return
|
||||
|
||||
|
||||
def readRow(action, resolved, outputs):
|
||||
@@ -200,8 +207,8 @@ def readRow(action, resolved, outputs):
|
||||
""",
|
||||
(value,)
|
||||
)
|
||||
#print("DEBUG READROW TARGET ITEM")
|
||||
#print(value)
|
||||
logging.debug("DEBUG READROW TARGET ITEM")
|
||||
logging.debug(value)
|
||||
|
||||
result = cursor.fetchone()
|
||||
|
||||
@@ -210,15 +217,13 @@ def readRow(action, resolved, outputs):
|
||||
for column_index, output_name in exports.items():
|
||||
dbtarget = result[column_index]
|
||||
outputs[output_name] = dbtarget# result[column_index]
|
||||
#print("DEBUGGING DATABASE LINE EXTRACTION IN READROW")
|
||||
#print(outputs[output_name])
|
||||
#print(dbtarget)
|
||||
logging.debug("DEBUGGING DATABASE LINE EXTRACTION IN READROW")
|
||||
logging.debug(outputs[output_name])
|
||||
logging.debug(dbtarget)
|
||||
|
||||
return resolved, outputs
|
||||
return
|
||||
else:
|
||||
print(f"Search target {value} not found in database table {table}")
|
||||
return resolved, outputs
|
||||
logging.info(f"Search target {value} not found in database table {table}")
|
||||
return
|
||||
|
||||
#print("READROW SEARCH RESULT")
|
||||
#print(target)
|
||||
return resolved, outputs
|
||||
return
|
||||
+13
-4
@@ -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,15 +33,18 @@ def buildSelect(action, outputs):
|
||||
#outputs[{action.select["source"]}] = select_data
|
||||
outputs[f"{action.alias}_select"] = select_data
|
||||
|
||||
if select_data is None:
|
||||
print(f"No data selected during {action.name}")
|
||||
#print(select_data)
|
||||
|
||||
return action, outputs
|
||||
if select_log:
|
||||
if select_data is None:
|
||||
print(f"No data selected during {action.name}")
|
||||
|
||||
return
|
||||
except KeyError as error:
|
||||
print(f"Error in selection of {error} during {action.name}")
|
||||
|
||||
except TypeError as error:
|
||||
print(f"TypeError during select: {error} during {action.name}")
|
||||
|
||||
return action, outputs
|
||||
return
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
def checkDependency(action, outputs):
|
||||
#from core.execution.processregistry import registeredOp
|
||||
|
||||
def checkDependency(action):
|
||||
from core.execution.processregistry import registeredOp
|
||||
if hasattr(action, "depends"):
|
||||
stop = any(
|
||||
dependency in outputs["stopsignals"]
|
||||
dependency in registeredOp["stopsignals"]
|
||||
for dependency in action.depends
|
||||
)
|
||||
|
||||
@@ -10,8 +13,10 @@ def checkDependency(action, outputs):
|
||||
|
||||
return False
|
||||
|
||||
def addStopSignal(action, outputs):
|
||||
if hasattr(action, "depends"):
|
||||
outputs["stopsignals"].append(action.alias)
|
||||
def addStopSignal(action):
|
||||
from core.execution.processregistry import registeredOp
|
||||
|
||||
return outputs
|
||||
if hasattr(action, "depends"):
|
||||
|
||||
registeredOp["stopsignals"].append(action.alias)
|
||||
return
|
||||
@@ -1,51 +1,53 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
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.runtime.createruntime import outputs
|
||||
from core.execution.processregistry import processes
|
||||
|
||||
|
||||
def buildListener(listener, self):
|
||||
|
||||
if self.path == "/_matrix/app/v1/ping":
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(b"{}")
|
||||
return
|
||||
|
||||
if self.path.startswith(listener.acceptpath):
|
||||
|
||||
#Prints can used buildlog for listener runtime
|
||||
print("Matrix transaction received")
|
||||
if hasattr(listener, "print"):
|
||||
logging.info(listener.print)
|
||||
|
||||
content_length = int(self.headers["Content-Length"])
|
||||
|
||||
data = self.rfile.read(content_length)
|
||||
request = json.loads(data)
|
||||
bytes = self.rfile.read(content_length)
|
||||
|
||||
outputs = {}
|
||||
#request = json.loads(data)
|
||||
|
||||
outputs = buildOutput(data, listener, outputs)
|
||||
buildOutput(bytes, listener, outputs)
|
||||
|
||||
for item in outputs[listener.recursive["source"]]:
|
||||
if hasattr(listener, "filters"):
|
||||
allow, status_code = buildFirewall(listener, outputs)
|
||||
|
||||
match, filter = applyConditions(listener, item, outputs)
|
||||
if allow:
|
||||
logging.info(outputs["firewall_allowed"])
|
||||
|
||||
if not match:
|
||||
if "com.loxthelion.rmass_message_id" in item.get("content", {}):
|
||||
print("Excluding previously imported items")
|
||||
#print(item)
|
||||
continue
|
||||
|
||||
print(item)
|
||||
#Process and forward to RMASS
|
||||
if hasattr(listener, "execute"):
|
||||
if listener.execute["engine"] == "thread":
|
||||
from core.execution.createthread import buildThread
|
||||
buildThread(listener.execute["module"])
|
||||
|
||||
outputs, responses = executeContract(listener.execute, outputs)
|
||||
elif listener.execute["engine"] == "contract":
|
||||
from core.execution.executioncontract import executeContract
|
||||
executeContract(listener.execute["module"])
|
||||
|
||||
continue
|
||||
|
||||
else:
|
||||
if hasattr(listener, "execute"):
|
||||
if listener.execute["engine"] == "thread":
|
||||
from core.execution.createthread import buildThread
|
||||
buildThread(listener.execute["module"])
|
||||
|
||||
self.send_response(200)
|
||||
elif listener.execute["engine"] == "contract":
|
||||
from core.execution.executioncontract import executeContract
|
||||
executeContract(listener.execute["module"])
|
||||
|
||||
status_code = listener.status_code["success"]
|
||||
|
||||
self.send_response(status_code)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", "2")
|
||||
self.end_headers()
|
||||
@@ -54,4 +56,4 @@ def buildListener(listener, self):
|
||||
else:
|
||||
self.send_error(404)
|
||||
|
||||
return outputs
|
||||
return
|
||||
+95
-75
@@ -1,111 +1,131 @@
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
|
||||
from .dispatcher import dispatchRequest
|
||||
from .createresponse import buildResponse
|
||||
from core.runtime.outputs import buildOutput
|
||||
from core.runtime.resolver import resolveItem
|
||||
from plugins.rmass.listeners import synapselistener
|
||||
from plugins.rmass.operations import rmassmessagepush
|
||||
from core.execution.action import buildAction
|
||||
|
||||
#from .dispatcher import dispatchRequest
|
||||
#from .createresponse import buildResponse
|
||||
from plugins.rmass.listeners import synapselistener, matrixpinglistener
|
||||
from core.server.createlistener import buildListener
|
||||
from plugins.rmass.actions import pingsynapse
|
||||
#from plugins.rmass.actions import synapsesetbridgeonline
|
||||
|
||||
port = int(os.environ.get("SERVER_PORT", 19001))
|
||||
|
||||
|
||||
class RequestHandler(BaseHTTPRequestHandler):
|
||||
def log_message(self, format, *args):
|
||||
logging.info(
|
||||
"%s - %s",
|
||||
self.address_string(),
|
||||
format % args
|
||||
)
|
||||
|
||||
def do_POST(self):
|
||||
lifecycles = {}
|
||||
print("POST request received")
|
||||
logging.debug("POST request received")
|
||||
|
||||
max_request_size = 1024
|
||||
buildListener(matrixpinglistener, self)
|
||||
|
||||
content_length = self.headers.get("Content-Length")
|
||||
# if self.path == "/_matrix/app/v1/ping":
|
||||
|
||||
# Check whether Content-Length exists
|
||||
if content_length is None:
|
||||
response = {
|
||||
"status": "error",
|
||||
"message": "Content length required"
|
||||
}
|
||||
status = 411
|
||||
# from core.execution.createthread import buildThread
|
||||
# thread = buildThread(synapsesetbridgeonline)
|
||||
|
||||
else:
|
||||
# Attempt to convert the header into an integer
|
||||
try:
|
||||
length = int(content_length)
|
||||
except ValueError:
|
||||
length = None
|
||||
# self.send_response(200)
|
||||
# self.send_header("Content-Type", "application/json")
|
||||
# self.send_header("Content-Length", "2")
|
||||
# self.end_headers()
|
||||
# self.wfile.write(b"{}")
|
||||
# return
|
||||
|
||||
# Validate the converted length
|
||||
if length is None:
|
||||
response = {
|
||||
"status": "error",
|
||||
"message": "Invalid Content-Length"
|
||||
}
|
||||
status = 400
|
||||
# else:
|
||||
# print("POST request received")
|
||||
|
||||
elif length < 0:
|
||||
response = {
|
||||
"status": "error",
|
||||
"message": "Bad Request"
|
||||
}
|
||||
status = 400
|
||||
# max_request_size = 1024
|
||||
|
||||
elif length > max_request_size:
|
||||
response = {
|
||||
"status": "error",
|
||||
"message": "Content exceeds maximum request size"
|
||||
}
|
||||
status = 413
|
||||
# content_length = self.headers.get("Content-Length")
|
||||
|
||||
else:
|
||||
# Content-Length is valid, so read the body
|
||||
data = self.rfile.read(length)
|
||||
# # Check whether Content-Length exists
|
||||
# if content_length is None:
|
||||
# response = {
|
||||
# "status": "error",
|
||||
# "message": "Content length required"
|
||||
# }
|
||||
# status = 411
|
||||
|
||||
try:
|
||||
request = json.loads(data)
|
||||
# else:
|
||||
# # Attempt to convert the header into an integer
|
||||
# try:
|
||||
# length = int(content_length)
|
||||
# except ValueError:
|
||||
# length = None
|
||||
|
||||
except json.JSONDecodeError:
|
||||
response = {
|
||||
"status": "error",
|
||||
"message": "Invalid JSON received"
|
||||
}
|
||||
status = 400
|
||||
# # Validate the converted length
|
||||
# if length is None:
|
||||
# response = {
|
||||
# "status": "error",
|
||||
# "message": "Invalid Content-Length"
|
||||
# }
|
||||
# status = 400
|
||||
|
||||
else:
|
||||
# Only valid JSON reaches the dispatcher
|
||||
thread, lifecycles, module, mode = dispatchRequest(
|
||||
request, lifecycles
|
||||
)
|
||||
# elif length < 0:
|
||||
# response = {
|
||||
# "status": "error",
|
||||
# "message": "Bad Request"
|
||||
# }
|
||||
# status = 400
|
||||
|
||||
response = buildResponse(module, thread, mode)
|
||||
status = 200
|
||||
# elif length > max_request_size:
|
||||
# response = {
|
||||
# "status": "error",
|
||||
# "message": "Content exceeds maximum request size"
|
||||
# }
|
||||
# status = 413
|
||||
|
||||
# Serialize the response
|
||||
responsebytes = json.dumps(response).encode("utf-8")
|
||||
# else:
|
||||
# # Content-Length is valid, so read the body
|
||||
# data = self.rfile.read(length)
|
||||
|
||||
# Send one HTTP response
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(responsebytes)))
|
||||
self.end_headers()
|
||||
# try:
|
||||
# request = json.loads(data)
|
||||
|
||||
self.wfile.write(responsebytes)
|
||||
# except json.JSONDecodeError:
|
||||
# response = {
|
||||
# "status": "error",
|
||||
# "message": "Invalid JSON received"
|
||||
# }
|
||||
# status = 400
|
||||
|
||||
# else:
|
||||
# # Only valid JSON reaches the dispatcher
|
||||
# thread, lifecycles, module, mode = dispatchRequest(
|
||||
# request, lifecycles
|
||||
# )
|
||||
|
||||
# response = buildResponse(module, thread, mode)
|
||||
# status = 200
|
||||
|
||||
# # Serialize the response
|
||||
# responsebytes = json.dumps(response).encode("utf-8")
|
||||
|
||||
# # Send one HTTP response
|
||||
# self.send_response(status)
|
||||
# self.send_header("Content-Type", "application/json")
|
||||
# self.send_header("Content-Length", str(len(responsebytes)))
|
||||
# self.end_headers()
|
||||
|
||||
# self.wfile.write(responsebytes)
|
||||
|
||||
|
||||
def do_PUT(self):
|
||||
print("PUT request received")
|
||||
logging.debug("PUT request received")
|
||||
|
||||
outputs = buildListener(synapselistener, self)
|
||||
buildListener(synapselistener, self)
|
||||
|
||||
def startServer():
|
||||
server = HTTPServer(("0.0.0.0", port), RequestHandler)
|
||||
|
||||
print(f"Server listening on port {port}")
|
||||
#outputs = {}
|
||||
#outputs, response = buildAction(pingsynapse, outputs)
|
||||
logging.info(f"Server listening on port {port}")
|
||||
|
||||
server.serve_forever()
|
||||
+35
-14
@@ -1,27 +1,48 @@
|
||||
import threading
|
||||
import logging
|
||||
import os
|
||||
|
||||
from core.server.server import startServer
|
||||
from core.execution.createthread import buildThread
|
||||
from plugins.rmass.monitors import rmassmonitor
|
||||
from plugins.rmass.actions import refresh_tokens
|
||||
from plugins.rmass.operations import token_update
|
||||
from plugins.rmass.actions import pingsynapse
|
||||
|
||||
from core.console import console
|
||||
from rich.logging import RichHandler
|
||||
|
||||
logging.basicConfig(
|
||||
level=os.environ.get("LOG_LEVEL", "WARNING").upper(),
|
||||
format="%(message)s",
|
||||
handlers=[
|
||||
RichHandler(
|
||||
console=console,
|
||||
show_time=False,
|
||||
show_path=False
|
||||
)
|
||||
|
||||
],
|
||||
force=True
|
||||
)
|
||||
|
||||
import login
|
||||
import synapsemessagepush
|
||||
|
||||
lifecycles ={}
|
||||
|
||||
|
||||
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 = threading.Thread(
|
||||
target=startServer,
|
||||
#args=(module, lifecycles)
|
||||
name="RMASS Bridge Server"
|
||||
)
|
||||
thread.start()
|
||||
thread.start()
|
||||
|
||||
pingsynapse.mode = "continuous"
|
||||
rmassmonitor.mode = "continuous"
|
||||
token_update.mode = "continuous"
|
||||
#refresh_tokens.mode = "continuous"
|
||||
|
||||
thread = buildThread(rmassmonitor)
|
||||
|
||||
#thread = buildThread(refresh_tokens)
|
||||
|
||||
thread = buildThread(token_update)
|
||||
|
||||
thread = buildThread(pingsynapse)
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
name = "Synapse Wake"
|
||||
name = "Synapse Ping"
|
||||
|
||||
kind = "action"
|
||||
|
||||
alias = "synapseping"
|
||||
alias = "pingsynapse"
|
||||
|
||||
showstatus = True
|
||||
|
||||
sleeptime = 15
|
||||
|
||||
isrequest = True
|
||||
|
||||
method = "POST"
|
||||
|
||||
@@ -5,6 +5,8 @@ name = "Token refresh"
|
||||
|
||||
kind = "action"
|
||||
|
||||
alias = "refresh_tokens"
|
||||
|
||||
showstatus = True
|
||||
|
||||
method = "GET"
|
||||
@@ -44,6 +46,15 @@ outputs = {
|
||||
"refresh_token": "refreshToken",
|
||||
}
|
||||
|
||||
responsepolicy = [
|
||||
{
|
||||
"statuscode": 403,
|
||||
"print": "Refreshing stale tokens...",
|
||||
"execute": login,
|
||||
"response_update": False,
|
||||
}
|
||||
]
|
||||
|
||||
recoverPolicy = {
|
||||
FileNotFoundError: [
|
||||
getcsrf,
|
||||
|
||||
@@ -77,6 +77,7 @@ responsepolicy = [
|
||||
"statuscode": 400,
|
||||
"print": "Message is too short. Notifying...",
|
||||
"execute": synapsenotify,
|
||||
"response_update": False,
|
||||
}
|
||||
]
|
||||
|
||||
@@ -87,6 +88,15 @@ outputs = {
|
||||
##Filter test against recursiveset
|
||||
|
||||
filters = [
|
||||
{
|
||||
"filterkey": "message_body",
|
||||
#"filterkey_lib": "resolved",
|
||||
"filterkey_format": "length",
|
||||
"execute": synapsenotify,
|
||||
"operator": "<",
|
||||
"filtervalue": 5,
|
||||
"print": f"Message body is less than 5 characters. Notifying with {synapsenotify.name}...",
|
||||
},
|
||||
{
|
||||
"filterkey": "msgtype",
|
||||
"operator": "==",
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -10,16 +10,9 @@ showstatus = True
|
||||
|
||||
resolve = {
|
||||
"get": {
|
||||
"sender": ["room_name"],
|
||||
"event_id": ["outmessageitem", "event_id"],
|
||||
"room_id": ["outmessageitem", "room_id"],
|
||||
"event_id": ["events", 0, "event_id"],
|
||||
"room_id": ["events", 0, "room_id"],
|
||||
},
|
||||
"deconstruct": {
|
||||
"sender" : [
|
||||
"#rmass_dm_",
|
||||
":loxthelion.com",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
keys = [
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from . import synapsenotify
|
||||
|
||||
name = "Synapse Message Push"
|
||||
|
||||
kind = "action"
|
||||
|
||||
alias = "synapsepushmessagesaction"
|
||||
|
||||
showstatus = True
|
||||
|
||||
resolve = {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
name = "Set RMASS Bridge Online"
|
||||
|
||||
kind = "action"
|
||||
|
||||
alias = "setrmassbridgeonline"
|
||||
|
||||
showstatus = True
|
||||
|
||||
#sleeptime = 15
|
||||
|
||||
isrequest = True
|
||||
|
||||
method = "PUT"
|
||||
|
||||
path = [
|
||||
"https://loxthelion.com/_matrix/client/v3/presence/@rmass_bridge:loxthelion.com/status",
|
||||
]
|
||||
|
||||
headers = {
|
||||
"Authorization": {
|
||||
"os": "AS_TOKEN",
|
||||
"prefix": "Bearer ",
|
||||
},
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
keys = [
|
||||
{
|
||||
"keytitle": "presence",
|
||||
"keyvalue": "online",
|
||||
},
|
||||
{
|
||||
"keytitle": "status_msg",
|
||||
"keyvalue": "RMASS Bridge Connected",
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
from plugins.rmass.actions import synapsesetbridgeonline
|
||||
|
||||
name = "Matrix Ping Listener"
|
||||
|
||||
kind = "listener"
|
||||
|
||||
acceptpath = "/_matrix/app/v1/ping"
|
||||
|
||||
execute = {
|
||||
"module": synapsesetbridgeonline,
|
||||
"engine": "thread",
|
||||
}
|
||||
|
||||
status_code = {
|
||||
"success": 200
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
from plugins.rmass.operations import rmassmessagepush
|
||||
from plugins.rmass.actions import synapsenotify
|
||||
|
||||
name = "Synapse Listener"
|
||||
|
||||
@@ -8,6 +9,19 @@ outputs = {
|
||||
"events": "events",
|
||||
}
|
||||
|
||||
resolve = {
|
||||
"get": {
|
||||
"sender": ["sender"],
|
||||
"event_id": ["event_id"],
|
||||
"message_body": ["content", "body"],
|
||||
"content": ["content"],
|
||||
"type": ["type"],
|
||||
"room_id": ["room_id"],
|
||||
"timestamp": ["origin_server_ts"],
|
||||
"filter_item": []
|
||||
}
|
||||
}
|
||||
|
||||
recursive = {
|
||||
"source": "events",
|
||||
"reverse": False,
|
||||
@@ -16,27 +30,51 @@ recursive = {
|
||||
|
||||
acceptpath = "/_matrix/app/v1/transactions/"
|
||||
|
||||
execute = rmassmessagepush
|
||||
execute = {
|
||||
"module": rmassmessagepush,
|
||||
"engine": "contract",
|
||||
}
|
||||
|
||||
filters = [
|
||||
{
|
||||
"filterkey": "event",
|
||||
"filterkey": "filter_item",
|
||||
"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,
|
||||
},
|
||||
{
|
||||
"filterkey": "content",
|
||||
"operator": "in",
|
||||
"filtervalue": "com.loxthelion.rmass_message_id",
|
||||
"print": "Excluding imported message loop item",
|
||||
"status_code": 200,
|
||||
},
|
||||
{
|
||||
"filterkey": "message_body",
|
||||
#"filterkey_lib": "resolved",
|
||||
"filterkey_format": "length",
|
||||
"execute": synapsenotify,
|
||||
"operator": "<",
|
||||
"filtervalue": 5,
|
||||
"print": f"Message body is less than 5 characters. Notifying with {synapsenotify.name}...",
|
||||
"status_code":200
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
print = "Matrix transaction received"
|
||||
@@ -59,7 +59,7 @@ filters = [
|
||||
},
|
||||
]
|
||||
|
||||
sleeptime = 30
|
||||
sleeptime = 15
|
||||
|
||||
#prints = {
|
||||
# "Status": "message",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from plugins.rmass.actions import getcsrf, login
|
||||
|
||||
name = "Login"
|
||||
name = "Login Operation"
|
||||
|
||||
kind = "operation"
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from plugins.rmass.actions import rmassmessagepush, savermassmessageid, synapsegetroomalias, synapsegetlastmessage
|
||||
from plugins.rmass.operations import rmassattachmentpushflow
|
||||
|
||||
name = "RMASS Message Push"
|
||||
name = "Message Forwarding to RMASS"
|
||||
|
||||
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,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
|
||||
from plugins.rmass.actions import refresh_tokens
|
||||
|
||||
name = "Token Refresh Operation"
|
||||
|
||||
kind = "operation"
|
||||
|
||||
actions = [
|
||||
refresh_tokens,
|
||||
]
|
||||
|
||||
sleeptime = os.environ.get("TOKEN_REFRESH_RATE", 105)
|
||||
@@ -1 +1,2 @@
|
||||
requests
|
||||
rich
|
||||
+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)
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTMwNTE5ODUsIm5iZiI6MTc5MzA1MTgwNSwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MzA1MTg2NX0.pMPPsvgYfsRhTj7NJFc0hj3N-8gP1Th3oX9NQce9e2-NJw7ANxFv-7sdmeDE71_B71He7cych-kW5RFuJpc2ZA", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTU2NDM4NjUsIm5iZiI6MTc5MzA1MTgwNSwianRpIjoiU1BJbnZpSXBmTE5WY1NVQ1ZOQ0VvRUdGUWEwOVIrN3dKOHJuNGZqYU5ZMD0iLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MzA1MTg2NSwic3ViIjoiMjM4MzAyIn0.2N1mzB9BYKgd5tMK10ZuBxW0zqNDDmhN8JtVoQAoeKHcm9JtNzdRa4LfsNPiJ1MOzkXBkTBuktmUI8AiDq78YQ"}
|
||||
@@ -1,5 +0,0 @@
|
||||
from plugins import rmass
|
||||
from core.operation.operation import buildOperation
|
||||
|
||||
outputs = buildOperation(rmass.checkavailableoperation)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import importlib
|
||||
from lifecyclemanager import manageLifecycle
|
||||
from dispatchstate import buildState
|
||||
|
||||
def buildDispatch(request):
|
||||
dispatch = []
|
||||
|
||||
for key in request["module"]:
|
||||
dispatch.append(request["module"][key])
|
||||
|
||||
resolveddispatch = "plugins."+ ".".join(dispatch)
|
||||
|
||||
module = importlib.import_module(resolveddispatch)
|
||||
|
||||
mode = request.get("mode", "oneshot")
|
||||
|
||||
return module, mode
|
||||
@@ -1,30 +0,0 @@
|
||||
import threading
|
||||
from lifecycleregistry import registerLifecycle
|
||||
from lifecyclemanager import manageLifecycle
|
||||
|
||||
threadlist = []
|
||||
threadnum = 0
|
||||
|
||||
def buildThread(module, lifecycles):
|
||||
global threadnum
|
||||
threadnum += 1
|
||||
|
||||
threadname = f"thread.{threadnum}"
|
||||
|
||||
thread = threading.Thread(
|
||||
target=manageLifecycle,
|
||||
args=(module, lifecycles)
|
||||
)
|
||||
thread.start()
|
||||
|
||||
registryname = threadname
|
||||
registryvalue = thread
|
||||
|
||||
lifecycles = registerLifecycle (module, lifecycles, registryname, registryvalue)
|
||||
|
||||
threadlist.append(thread)
|
||||
|
||||
print(threadlist)
|
||||
print(lifecycles)
|
||||
|
||||
return threadnum, threadname, lifecycles, threadlist
|
||||
@@ -1,22 +0,0 @@
|
||||
from createdispatch import buildDispatch
|
||||
from createthread import buildThread
|
||||
from dispatchstate import buildState
|
||||
|
||||
import threading
|
||||
|
||||
def dispatchRequest(request, lifecycles):
|
||||
|
||||
module, mode = buildDispatch(request)
|
||||
|
||||
mode, lifecycles = buildState(module, mode, lifecycles)
|
||||
|
||||
if mode == "stop":
|
||||
return lifecycles
|
||||
|
||||
else:
|
||||
threadnum, threadname, lifecycles, threadlist = buildThread(module, lifecycles)
|
||||
|
||||
#print("Active Threads")
|
||||
#print(threadlist)
|
||||
|
||||
return threadnum, threadname, lifecycles, threadlist
|
||||
@@ -1,41 +0,0 @@
|
||||
import requests
|
||||
|
||||
from lifecycleregistry import registerLifecycle
|
||||
|
||||
def filterMode(mode):
|
||||
if mode in ("continuous", "oneshot", "stop"):
|
||||
state = mode
|
||||
return state
|
||||
else: raise ValueError(f"Unsupported lifecycle mode: {mode}")
|
||||
|
||||
def buildState(module, mode, lifecycles):
|
||||
state = filterMode(mode)
|
||||
|
||||
registryvalue = state
|
||||
registryname = "mode"
|
||||
|
||||
if state != "stop":
|
||||
lifecycles = registerLifecycle(module, lifecycles, registryname, registryvalue)
|
||||
|
||||
elif state == "stop":
|
||||
if not module.name in lifecycles:
|
||||
|
||||
print(f"No registered lifecycle: {module.name}")
|
||||
|
||||
return None
|
||||
|
||||
elif "mode" in lifecycles[module.name] != "stop":
|
||||
lifecycles = registerLifecycle(module, lifecycles, registryname, registryvalue)
|
||||
|
||||
print(f"Stopping lifecycle: {module.name}")
|
||||
|
||||
#elif mode == "oneshot":
|
||||
#registryvalue = {"mode": "oneshot"}
|
||||
#lifecycles = registerLifecycle(module, lifecycles, registryname, registryvalue)
|
||||
|
||||
# else:
|
||||
#raise ValueError(f"Unsupported lifecycle mode: {mode}")
|
||||
|
||||
#state = registryvalue
|
||||
|
||||
return state, lifecycles
|
||||
@@ -1,25 +0,0 @@
|
||||
import time
|
||||
|
||||
from core.execution.operation import buildOperation
|
||||
from core.execution.action import buildAction
|
||||
from core import executeContract
|
||||
|
||||
def manageLifecycle(module, lifecycles): #lifecycles, state):
|
||||
#print(lifecycles[module.name]["mode"])
|
||||
|
||||
if lifecycles[module.name]["mode"] == "continuous":
|
||||
while lifecycles[module.name]["mode"] == "continuous":
|
||||
print(lifecycles)
|
||||
|
||||
outputs = executeContract(module)
|
||||
|
||||
#print(lifecycles)
|
||||
|
||||
time.sleep(module.sleeptime)
|
||||
|
||||
elif lifecycles[module.name]["mode"] == "oneshot":
|
||||
print(lifecycles)
|
||||
outputs = executeContract(module)
|
||||
|
||||
#print(lifecycles)
|
||||
return
|
||||
@@ -1,8 +0,0 @@
|
||||
def registerLifecycle(module, lifecycles, registryname, registryvalue):
|
||||
if module.name not in lifecycles:
|
||||
lifecycles[module.name] = {}
|
||||
|
||||
|
||||
lifecycles[module.name][registryname] = registryvalue
|
||||
|
||||
return lifecycles
|
||||
@@ -1,4 +0,0 @@
|
||||
from plugins import rmass
|
||||
from operation import buildOperation
|
||||
|
||||
outputs = buildOperation(rmass.checkavailableoperation)
|
||||
@@ -1,4 +0,0 @@
|
||||
from core.manager.manager import buildManager
|
||||
from plugins import rmass
|
||||
|
||||
outputs = buildManager(rmass.manager)
|
||||
@@ -1,29 +0,0 @@
|
||||
import socket
|
||||
import json
|
||||
from dispatcher import dispatchRequest
|
||||
#from createthread import buildThread
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
server.bind(("127.0.0.1", 19002))
|
||||
|
||||
lifecycles = {}
|
||||
|
||||
server.listen()
|
||||
|
||||
while True:
|
||||
connection, address = server.accept()
|
||||
|
||||
while True:
|
||||
data = connection.recv(4096)
|
||||
|
||||
request = json.loads(data)
|
||||
|
||||
# if not data:
|
||||
# break
|
||||
|
||||
dispatch = dispatchRequest(request, lifecycles)
|
||||
|
||||
connection.close()
|
||||
|
||||
# server.close()
|
||||
Reference in New Issue
Block a user