Compare commits
81
Commits
3db6a5ae17
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||||
@@ -24,3 +24,9 @@ savedata/
|
|||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
#Trash and unused files
|
||||||
|
trash/
|
||||||
|
|
||||||
|
#Docker files
|
||||||
|
.dockerignore
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
from plugins import rmass
|
from plugins import rmass
|
||||||
from core import buildOperation
|
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 .server import server
|
||||||
from .apirequest import executeRequest
|
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 import buildOperation, buildAction
|
||||||
from .execution.action import buildAction
|
from .execution.action import buildAction
|
||||||
from .execution.operation import buildOperation
|
from .execution.operation import buildOperation
|
||||||
|
|||||||
+29
-44
@@ -1,8 +1,12 @@
|
|||||||
import requests
|
import requests
|
||||||
import threading
|
import threading
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
from .request import buildRequest
|
from .request import buildRequest
|
||||||
|
|
||||||
|
|
||||||
#session = requests.Session()
|
#session = requests.Session()
|
||||||
_thread_local = threading.local()
|
_thread_local = threading.local()
|
||||||
|
|
||||||
@@ -15,15 +19,17 @@ def getSession(reset=False):
|
|||||||
if not hasattr(_thread_local, "session"):
|
if not hasattr(_thread_local, "session"):
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.name = threading.current_thread().name
|
session.name = threading.current_thread().name
|
||||||
|
session.created_at = time.monotonic()
|
||||||
_thread_local.session = session
|
_thread_local.session = session
|
||||||
|
|
||||||
return _thread_local.session
|
return _thread_local.session
|
||||||
|
|
||||||
|
|
||||||
def executeRequest(action, outputs, resolved):
|
def executeRequest(action, outputs, resolved):
|
||||||
|
from core.execution.lifecyclemanager.lifecyclemanager import lifecycles
|
||||||
session = getSession()
|
session = getSession()
|
||||||
|
|
||||||
session_log = bool(os.environ.get("LOGS_SESSION", False))
|
session_log = os.environ.get("LOGS_SESSION", "false").lower() == "true"
|
||||||
|
|
||||||
if session_log:
|
if session_log:
|
||||||
print(
|
print(
|
||||||
@@ -32,8 +38,15 @@ def executeRequest(action, outputs, resolved):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for attempt in range(2):
|
for attempt in range(2):
|
||||||
request, outputs = buildRequest(action, outputs, resolved)
|
request = buildRequest(action, outputs, resolved)
|
||||||
try:
|
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(
|
response = session.request(
|
||||||
method=request["method"],
|
method=request["method"],
|
||||||
url=request["path"],
|
url=request["path"],
|
||||||
@@ -43,51 +56,23 @@ def executeRequest(action, outputs, resolved):
|
|||||||
files=request.get("files"),
|
files=request.get("files"),
|
||||||
timeout=(10, 30)
|
timeout=(10, 30)
|
||||||
)
|
)
|
||||||
return response, outputs
|
|
||||||
|
logging.debug(snapshot)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
except (requests.Timeout, requests.ConnectionError) as error:
|
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)
|
session = getSession(reset=True)
|
||||||
|
|
||||||
if attempt == 0:
|
if attempt == 0:
|
||||||
print(f"Retrying {action.name}")
|
logging.warning(f"Retrying {action.name}")
|
||||||
|
|
||||||
return None, outputs
|
return None
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|||||||
@@ -18,12 +18,15 @@ def buildRequest(definition, outputs, resolved):
|
|||||||
request["headers"] = buildHeaders(definition, request, outputs, resolved)
|
request["headers"] = buildHeaders(definition, request, outputs, resolved)
|
||||||
|
|
||||||
if hasattr(definition, "requestdata"):
|
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(
|
request["data"] = buildObject2(
|
||||||
definition.requestdata,
|
definition.requestdata,
|
||||||
outputs,
|
outputs,
|
||||||
resolved
|
resolved
|
||||||
)
|
)
|
||||||
# resolveddata = definition.requestdata
|
# resolveddata = definition.requestdata
|
||||||
#
|
#
|
||||||
# if isinstance(resolveddata, dict):
|
# if isinstance(resolveddata, dict):
|
||||||
@@ -43,4 +46,4 @@ def buildRequest(definition, outputs, resolved):
|
|||||||
"image/jpeg",
|
"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.apirequest import executeRequest
|
||||||
from core.runtime.runtimecontract import buildRuntimeAttr, buildPreRuntimeAttr
|
from core.runtime.runtimecontract import buildRuntimeAttr, buildPreRuntimeAttr
|
||||||
from core.runtime.stopsignals import addStopSignal
|
|
||||||
|
|
||||||
|
|
||||||
def buildAction (action, outputs):
|
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 hasattr(action, "allowaction"):
|
||||||
if not action.allowaction:
|
if not action.allowaction:
|
||||||
return outputs, None
|
return None
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
return outputs, None
|
if filter.get("execute", False):
|
||||||
|
response = executeRequest(filter["execute"], outputs, resolved)
|
||||||
|
|
||||||
response, outputs = executeRequest(action, outputs, resolved)
|
return None
|
||||||
|
|
||||||
|
response = executeRequest(action, outputs, resolved)
|
||||||
|
|
||||||
if response is None:
|
if response is None:
|
||||||
return outputs, 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
|
import threading
|
||||||
from .lifecyclemanager import registerLifecycle
|
import logging
|
||||||
|
|
||||||
from .lifecyclemanager import manageLifecycle
|
from .lifecyclemanager import manageLifecycle
|
||||||
|
|
||||||
threadlist = []
|
def buildThread(module):
|
||||||
#threadnum = 0
|
|
||||||
|
|
||||||
def buildThread(module, lifecycles):
|
|
||||||
#global threadnum
|
|
||||||
#threadnum += 1
|
|
||||||
|
|
||||||
#threadname = f"thread.{threadnum}"
|
|
||||||
|
|
||||||
thread = threading.Thread(
|
thread = threading.Thread(
|
||||||
target=manageLifecycle,
|
target=manageLifecycle,
|
||||||
args=(module, lifecycles),
|
args=(module,),
|
||||||
name=module.name
|
name=module.name
|
||||||
)
|
)
|
||||||
|
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
registryname = thread.name
|
logging.info(f"THREAD STARTED, {thread}")
|
||||||
registryvalue = thread
|
|
||||||
|
|
||||||
lifecycles = registerLifecycle (module, lifecycles, registryname, registryvalue)
|
return thread
|
||||||
|
|
||||||
threadlist.append(thread)
|
|
||||||
|
|
||||||
#print(threadlist)
|
|
||||||
#print(lifecycles)
|
|
||||||
|
|
||||||
return thread, lifecycles
|
|
||||||
|
|||||||
@@ -1,33 +1,31 @@
|
|||||||
from core.execution.action import buildAction
|
from core.execution.action import buildAction
|
||||||
from core.execution.operation import buildOperation
|
from core.execution.operation import buildOperation
|
||||||
from core.execution.monitor import buildMonitor
|
from core.execution.monitor import buildMonitor
|
||||||
from core.runtime import manageFailure
|
#from core.runtime import manageFailure
|
||||||
from core.execution.recursive import buildRecursive
|
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":
|
if module.kind == "operation":
|
||||||
|
responses = buildOperation(module, outputs)
|
||||||
|
|
||||||
outputs, responses = buildOperation(module, outputs)
|
return responses
|
||||||
|
|
||||||
return outputs, responses
|
|
||||||
|
|
||||||
elif module.kind == "action":
|
elif module.kind == "action":
|
||||||
|
response = buildAction(module, outputs)
|
||||||
|
|
||||||
outputs, response = buildAction(module, outputs)
|
return response
|
||||||
|
|
||||||
return outputs, response
|
|
||||||
|
|
||||||
elif module.kind == "monitor":
|
elif module.kind == "monitor":
|
||||||
outputs, response= buildMonitor(module, outputs)
|
response = buildMonitor(module, outputs)
|
||||||
|
|
||||||
return outputs, response
|
return response
|
||||||
|
|
||||||
elif module.kind == "recursiveset":
|
elif module.kind == "recursiveset":
|
||||||
outputs, response = buildRecursive(module, outputs)
|
response = buildRecursive(module, outputs)
|
||||||
|
|
||||||
return outputs, response
|
return response
|
||||||
|
|
||||||
#except Exception as error:
|
#except Exception as error:
|
||||||
#outputs = manageFailure(error, module)
|
#outputs = manageFailure(error, module)
|
||||||
@@ -1,30 +1,42 @@
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from core.execution.operation import buildOperation
|
|
||||||
from core.execution.action import buildAction
|
|
||||||
from core.execution.executioncontract import executeContract
|
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":
|
if lifecycles[module.name]["mode"] == "continuous":
|
||||||
while 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:
|
if lifecycle_log:
|
||||||
print(f"{module.name} thread {lifecycles[module.name][module.name]} running in {lifecycles[module.name]['mode']} mode")
|
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":
|
elif lifecycles[module.name]["mode"] == "oneshot":
|
||||||
print(lifecycles)
|
lifecycles[module.name]["state"] = "active"
|
||||||
outputs, response = executeContract(module)
|
|
||||||
|
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
|
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:
|
if module.name not in lifecycles:
|
||||||
lifecycles[module.name] = {}
|
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
|
import logging
|
||||||
from core.execution.action import buildAction
|
|
||||||
from core.execution.operation import buildOperation
|
|
||||||
from core.apirequest import executeRequest
|
from core.apirequest import executeRequest
|
||||||
from core.runtime.resolver import resolveItem
|
from core.runtime.resolver import resolveItem
|
||||||
from core.runtime.applyconditions import applyConditions
|
from core.runtime.applyconditions import applyConditions
|
||||||
#from plugins.rmass.actions import login, refresh_tokens
|
|
||||||
from core.runtime import buildOutput
|
from core.runtime import buildOutput
|
||||||
from core.runtime.savedata import loadSave
|
from core.runtime.savedata import loadSave
|
||||||
|
|
||||||
@@ -12,9 +10,17 @@ outputs = {}
|
|||||||
resolved = {}
|
resolved = {}
|
||||||
|
|
||||||
def buildMonitor(monitor, outputs):
|
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()
|
responsedata = response.json()
|
||||||
|
|
||||||
@@ -22,16 +28,17 @@ def buildMonitor(monitor, outputs):
|
|||||||
|
|
||||||
match, filter = applyConditions(monitor, readitems, outputs)
|
match, filter = applyConditions(monitor, readitems, outputs)
|
||||||
|
|
||||||
outputs = buildOutput(response, monitor, outputs)
|
buildOutput(response, monitor, outputs)
|
||||||
|
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
module = filter["execute"]
|
from core.execution.createthread import buildThread
|
||||||
|
#from core.execution.executioncontract import executeContract
|
||||||
|
|
||||||
if module.kind == "action":
|
logging.info(filter.get("print"))
|
||||||
outputs, response = buildAction(module, outputs)
|
#module = filter["execute"]
|
||||||
if module.kind == "operation":
|
|
||||||
outputs, responses = buildOperation(module, outputs)
|
|
||||||
response = responses
|
|
||||||
|
|
||||||
return outputs, response
|
#response = executeContract(filter["execute"], outputs)
|
||||||
|
|
||||||
|
thread = buildThread(filter["execute"])
|
||||||
|
|
||||||
|
return response
|
||||||
@@ -1,33 +1,73 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import pprint
|
||||||
|
from rich.progress import track
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
from core.runtime.managefailure import manageFailure
|
from core.runtime.managefailure import manageFailure
|
||||||
from core.execution.action.action import buildAction
|
|
||||||
from core.runtime.stopsignals import checkDependency
|
from core.runtime.stopsignals import checkDependency
|
||||||
#from core.runtime.skipstep import skipStep
|
from core.execution import processregistry
|
||||||
#from core.runtime.recursive import recursiveSet
|
from core.console import console
|
||||||
|
|
||||||
|
#outputs = {}
|
||||||
|
|
||||||
outputs = {}
|
|
||||||
def buildOperation(definition, 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}")
|
process_log = True
|
||||||
#print(outputs["stopsignals"])
|
|
||||||
|
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:
|
if stop:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
outputs, response = executeContract(action, outputs)
|
if action.kind == "action":
|
||||||
|
currentOp[action.name] = {}
|
||||||
|
|
||||||
#if hasattr(action, recursive)
|
from core.execution.executioncontract import executeContract
|
||||||
|
|
||||||
|
response = executeContract(action)
|
||||||
|
|
||||||
responses.append(response)
|
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:
|
#except Exception as error:
|
||||||
#outputs = manageFailure(error, action, outputs)
|
#outputs = manageFailure(error, action, outputs)
|
||||||
|
|
||||||
return outputs, responses
|
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 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
|
import logging
|
||||||
from core.execution.action.action import buildAction
|
import os
|
||||||
from core.runtime.runtimecontract import buildPreRuntimeAttr, buildRuntimeAttr
|
|
||||||
from core.apirequest import executeRequest
|
|
||||||
from core.runtime.stopsignals import checkDependency
|
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):
|
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 = []
|
responses = []
|
||||||
from core.execution.executioncontract import executeContract
|
|
||||||
recursiveset = definition.recursiveset["actions"]
|
recursiveset = definition.recursiveset["actions"]
|
||||||
|
|
||||||
source = definition.recursiveset["source"]
|
source = definition.recursiveset["source"]
|
||||||
|
|
||||||
items = outputs.get(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)
|
reverse = definition.recursiveset.get("reverse", False)
|
||||||
|
|
||||||
if reverse:
|
if reverse:
|
||||||
#print("reversing")
|
|
||||||
items = reversed(items)
|
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[definition.recursiveset["outputlabel"]] = item
|
||||||
|
|
||||||
outputs["stopsignals"] = []
|
outputs["stopsignals"] = []
|
||||||
for job in recursiveset:
|
for job in recursiveset:
|
||||||
stop = checkDependency(job, outputs)
|
processregistry.registeredOp = currentOp
|
||||||
|
|
||||||
#print(f"STOP SIGNAL DEBUGGING during {job.name}")
|
stop = checkDependency(job)
|
||||||
#print(outputs["stopsignals"])
|
|
||||||
#print(stop)
|
|
||||||
|
|
||||||
if stop:
|
if stop:
|
||||||
#print("STOP SIGNAL DETECTED")
|
|
||||||
#print(f"Stopping {job.name} due to stop signal")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#print(f"RECURSIVE DEBUG DURING {job.name}")
|
if job.kind == "action":
|
||||||
#print(item)
|
currentOp[job.name] = {}
|
||||||
#outputs, response = buildAction(job, outputs)
|
|
||||||
|
|
||||||
outputs, response = executeContract(job, outputs)
|
from core.execution.executioncontract import executeContract
|
||||||
|
|
||||||
|
response = executeContract(job)
|
||||||
responses.append(response)
|
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)
|
retain = definition.recursiveset.get("retain", True)
|
||||||
|
|
||||||
if not retain:
|
if not retain:
|
||||||
@@ -55,4 +78,10 @@ def buildRecursive(definition, outputs):
|
|||||||
|
|
||||||
outputs.pop("stopsignals", None)
|
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 .savedata import buildSave, loadSave, saveRow, readRow
|
||||||
from .logs import buildLog
|
from .logs import buildLog
|
||||||
#from . import managefailure
|
#from . import managefailure
|
||||||
from .managefailure import manageFailure
|
#from .managefailure import manageFailure
|
||||||
from .image import buildImage
|
from .image import buildImage
|
||||||
|
|||||||
@@ -17,58 +17,56 @@ def applyConditions(definition, dictionary, outputs):
|
|||||||
if filtervalue is None:
|
if filtervalue is None:
|
||||||
continue
|
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 filter["operator"] == ">=":
|
||||||
if int(resolvedvalue or 0) >= int(filtervalue):
|
if int(resolvedvalue or 0) >= int(filtervalue):
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == "<=":
|
if filter["operator"] == "<=":
|
||||||
if int(resolvedvalue or 0) <= int(filtervalue):
|
if int(resolvedvalue or 0) <= int(filtervalue):
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == "==":
|
if filter["operator"] == "==":
|
||||||
if resolvedvalue == filtervalue:
|
if resolvedvalue == filtervalue:
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == "!=":
|
if filter["operator"] == "!=":
|
||||||
if resolvedvalue != filtervalue:
|
if resolvedvalue != filtervalue:
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == ">":
|
if filter["operator"] == ">":
|
||||||
if int(resolvedvalue or 0) > int(filtervalue):
|
if int(resolvedvalue or 0) > int(filtervalue):
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == "<":
|
if filter["operator"] == "<":
|
||||||
if int(resolvedvalue or 0) < int(filtervalue):
|
if int(resolvedvalue or 0) < int(filtervalue):
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == "in":
|
if filter["operator"] == "in":
|
||||||
if filtervalue in dictionary:
|
if filter["filterkey"] == "called_dictionary":
|
||||||
print(filter["print"])
|
if filtervalue in dictionary:
|
||||||
return True, filter
|
return True, filter
|
||||||
|
else:
|
||||||
|
if filtervalue in dictionary.get(filter["filterkey"], {}):
|
||||||
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == "is":
|
if filter["operator"] == "is":
|
||||||
if resolvedvalue is filtervalue:
|
if resolvedvalue is filtervalue:
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
if filter["operator"] == "is not":
|
if filter["operator"] == "is not":
|
||||||
if resolvedvalue is not filtervalue:
|
if resolvedvalue is not filtervalue:
|
||||||
print(filter["print"])
|
|
||||||
return True, filter
|
return True, filter
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(f"Value not present in runtime for filtering during {definition.name}")
|
print(f"Value not present in runtime for filtering during {definition.name}")
|
||||||
#print(filter)
|
|
||||||
return True, filter
|
return True, filter
|
||||||
#continue
|
|
||||||
|
|
||||||
#except TypeError:
|
#except TypeError:
|
||||||
# print("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:
|
else:
|
||||||
print("No response received"),
|
print("No response received"),
|
||||||
|
|
||||||
return outputs
|
return
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
def buildLog (action, outputs, response):
|
def buildLog (action, outputs, response):
|
||||||
if hasattr(action, "prints"):
|
if hasattr(action, "prints"):
|
||||||
@@ -12,8 +13,11 @@ def buildLog (action, outputs, response):
|
|||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
response_log = os.environ.get("LOGS_SUCCESS_RESPONSE", "false").lower() == "true"
|
||||||
|
|
||||||
if action.showstatus is True and response.ok:
|
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:
|
elif action.showstatus is True and not response.ok:
|
||||||
print(f"{action.name} failed with status code {response.status_code}")
|
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.execution.action.action import buildAction
|
||||||
#from core.runtime.outputs import buildOutput
|
#from core.runtime.outputs import buildOutput
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ def manageFailure(error, action, outputs):
|
|||||||
else:
|
else:
|
||||||
print(f"{type(error).__name__} detected during {action.name}. Applying recovery policy.")
|
print(f"{type(error).__name__} detected during {action.name}. Applying recovery policy.")
|
||||||
|
|
||||||
outputs, response = buildAction(repair, outputs)
|
response = buildAction(repair, outputs)
|
||||||
|
|
||||||
return outputs
|
return outputs
|
||||||
print(f"{error}")
|
print(f"{error}")
|
||||||
|
|||||||
@@ -53,6 +53,6 @@ def buildOutput(response, action, outputs):
|
|||||||
#else:
|
#else:
|
||||||
# print("No response received"),
|
# print("No response received"),
|
||||||
|
|
||||||
return outputs
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
def resolveItem(action, item):
|
def resolveItem(action, item):
|
||||||
|
#resolver_log = os.environ.get("LOGS_RESOLVER", "false").lower() == "true"
|
||||||
|
resolver_log = True
|
||||||
|
|
||||||
resolved = {}
|
resolved = {}
|
||||||
if hasattr(action, "resolve"):
|
if hasattr(action, "resolve"):
|
||||||
for label, keys in action.resolve["get"].items():
|
for label, keys in action.resolve["get"].items():
|
||||||
target = item
|
target = item
|
||||||
try:
|
try:
|
||||||
for key in keys:
|
for key in keys:
|
||||||
target = target[key]
|
if isinstance(target, dict):
|
||||||
|
target = target.get(key)
|
||||||
|
else:
|
||||||
|
target = target[key]
|
||||||
|
|
||||||
except (KeyError, IndexError) as error:
|
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
|
target = None
|
||||||
|
|
||||||
resolved[label] = target
|
resolved[label] = target
|
||||||
@@ -88,6 +98,7 @@ def resolveItem2(action, item):
|
|||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
def extractItem(action, item, resolved):
|
def extractItem(action, item, resolved):
|
||||||
|
#UNDER RUNTIME CONTRACT ITEM IS OUTPUTS
|
||||||
if hasattr(action, "extract"):
|
if hasattr(action, "extract"):
|
||||||
for label, keys in action.extract["get"].items():
|
for label, keys in action.extract["get"].items():
|
||||||
#resolved[label] = {}
|
#resolved[label] = {}
|
||||||
@@ -130,4 +141,4 @@ def extractItem(action, item, resolved):
|
|||||||
|
|
||||||
resolved[source] = deconstructed
|
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.apirequest import executeRequest
|
||||||
|
from core.execution import processregistry
|
||||||
|
|
||||||
def responsePolicy(response, action, outputs, resolved):
|
def responsePolicy(response, action, outputs, resolved):
|
||||||
if hasattr(action, "responsepolicy"):
|
if hasattr(action, "responsepolicy"):
|
||||||
|
#if processregistry.registeredOp:
|
||||||
|
#currentOp = processregistry.registeredOp
|
||||||
|
#print(registeredOp[action.name]["response"])
|
||||||
|
#print(currentOp)
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
print(response)
|
logging.warning(f"{response} during {action.name}")
|
||||||
|
|
||||||
for policy in action.responsepolicy:
|
for policy in action.responsepolicy:
|
||||||
if policy["statuscode"] == response.status_code:
|
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)
|
||||||
|
|
||||||
return 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 response
|
||||||
@@ -1,41 +1,46 @@
|
|||||||
from core.execution.action import action
|
import logging
|
||||||
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
|
|
||||||
from core.runtime.stopsignals import addStopSignal
|
from core.runtime.stopsignals import addStopSignal
|
||||||
|
|
||||||
def buildPreRuntimeAttr(action, outputs):
|
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 = resolveItem(action, outputs)
|
||||||
|
|
||||||
resolved, outputs = readRow(action, resolved, outputs)
|
readRow(action, resolved, outputs)
|
||||||
|
|
||||||
match, filter = applyConditions(action, resolved, outputs)
|
match, filter = applyConditions(action, resolved, outputs)
|
||||||
|
|
||||||
if match:
|
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):
|
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:
|
if not response.ok:
|
||||||
outputs = addStopSignal(action, outputs)
|
addStopSignal(action)
|
||||||
return outputs, response
|
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)
|
buildSave(action, outputs)
|
||||||
|
|
||||||
@@ -43,4 +48,4 @@ def buildRuntimeAttr(action, outputs, resolved, response):
|
|||||||
|
|
||||||
buildLog(action, outputs, response)
|
buildLog(action, outputs, response)
|
||||||
|
|
||||||
return outputs, response
|
return response
|
||||||
+25
-20
@@ -1,7 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
def buildSave(action, outputs):
|
def buildSave(action, outputs):
|
||||||
|
savedata_log = os.environ.get("LOGS_SAVE_DATA_ACCESS", "false").lower() == "true"
|
||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
if hasattr(action, "savedata"):
|
if hasattr(action, "savedata"):
|
||||||
@@ -36,10 +39,13 @@ def buildSave(action, outputs):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#print(f"Data saved by {action.name} to {action.savepath}")
|
if savedata_log:
|
||||||
return outputs
|
logging.info(f"Data saved by {action.name} to {action.savepath}")
|
||||||
|
return
|
||||||
|
|
||||||
def loadSave(action, outputs):
|
def loadSave(action, outputs):
|
||||||
|
savedata_log = os.environ.get("LOGS_SAVE_DATA_ACCESS", "false").lower() == "true"
|
||||||
|
|
||||||
if hasattr(action, "loaddata"):
|
if hasattr(action, "loaddata"):
|
||||||
with open(f"{action.savepath}", "r") as save_file:
|
with open(f"{action.savepath}", "r") as save_file:
|
||||||
load_data = json.load(save_file)
|
load_data = json.load(save_file)
|
||||||
@@ -47,8 +53,9 @@ def loadSave(action, outputs):
|
|||||||
for load_name in action.loaddata:
|
for load_name in action.loaddata:
|
||||||
outputs[load_name] = load_data[load_name]
|
outputs[load_name] = load_data[load_name]
|
||||||
|
|
||||||
#print(f"Data loaded by {action.name} from {action.savepath}")
|
if savedata_log:
|
||||||
return outputs
|
logging.info(f"Data loaded by {action.name} from {action.savepath}")
|
||||||
|
return
|
||||||
|
|
||||||
def saveRow(action, outputs, resolved):
|
def saveRow(action, outputs, resolved):
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -81,8 +88,8 @@ def saveRow(action, outputs, resolved):
|
|||||||
elif "resolved" in item:
|
elif "resolved" in item:
|
||||||
value = resolved[item["resolved"]]
|
value = resolved[item["resolved"]]
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
print(f"The save data for {error} was not located in its respective dictionary during {action.name}")
|
logging.error(f"The save data for {error} was not located in its respective dictionary during {action.name}")
|
||||||
print("Bypassing database save")
|
logging.error("Bypassing database save")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
values.append(value)
|
values.append(value)
|
||||||
@@ -131,7 +138,7 @@ def saveRow(action, outputs, resolved):
|
|||||||
database.execute(query, tuple(values))
|
database.execute(query, tuple(values))
|
||||||
|
|
||||||
except sqlite3.IntegrityError as error:
|
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
|
return False
|
||||||
|
|
||||||
#database.execute(
|
#database.execute(
|
||||||
@@ -142,9 +149,9 @@ def saveRow(action, outputs, resolved):
|
|||||||
#database.commit()
|
#database.commit()
|
||||||
#database.close()
|
#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):
|
def readRow(action, resolved, outputs):
|
||||||
@@ -200,8 +207,8 @@ def readRow(action, resolved, outputs):
|
|||||||
""",
|
""",
|
||||||
(value,)
|
(value,)
|
||||||
)
|
)
|
||||||
#print("DEBUG READROW TARGET ITEM")
|
logging.debug("DEBUG READROW TARGET ITEM")
|
||||||
#print(value)
|
logging.debug(value)
|
||||||
|
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
|
|
||||||
@@ -210,15 +217,13 @@ def readRow(action, resolved, outputs):
|
|||||||
for column_index, output_name in exports.items():
|
for column_index, output_name in exports.items():
|
||||||
dbtarget = result[column_index]
|
dbtarget = result[column_index]
|
||||||
outputs[output_name] = dbtarget# result[column_index]
|
outputs[output_name] = dbtarget# result[column_index]
|
||||||
#print("DEBUGGING DATABASE LINE EXTRACTION IN READROW")
|
logging.debug("DEBUGGING DATABASE LINE EXTRACTION IN READROW")
|
||||||
#print(outputs[output_name])
|
logging.debug(outputs[output_name])
|
||||||
#print(dbtarget)
|
logging.debug(dbtarget)
|
||||||
|
|
||||||
return resolved, outputs
|
return
|
||||||
else:
|
else:
|
||||||
print(f"Search target {value} not found in database table {table}")
|
logging.info(f"Search target {value} not found in database table {table}")
|
||||||
return resolved, outputs
|
return
|
||||||
|
|
||||||
#print("READROW SEARCH RESULT")
|
return
|
||||||
#print(target)
|
|
||||||
return resolved, outputs
|
|
||||||
+13
-4
@@ -1,8 +1,14 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
def buildSelect(action, outputs):
|
def buildSelect(action, outputs):
|
||||||
#***THIS IS THE CANONICAL BUILD***
|
#***THIS IS THE CANONICAL BUILD***
|
||||||
|
|
||||||
|
select_log = savedata_log = os.environ.get("LOGS_SELECT", "false").lower() == "true"
|
||||||
|
|
||||||
select_data = []
|
select_data = []
|
||||||
|
|
||||||
if hasattr(action, "select"):
|
if hasattr(action, "select"):
|
||||||
|
#outputs[f"{action.alias}_select"] = []
|
||||||
try:
|
try:
|
||||||
target = outputs[action.select["source"]]
|
target = outputs[action.select["source"]]
|
||||||
includekey = action.select["include"]["key"]
|
includekey = action.select["include"]["key"]
|
||||||
@@ -27,15 +33,18 @@ def buildSelect(action, outputs):
|
|||||||
#outputs[{action.select["source"]}] = select_data
|
#outputs[{action.select["source"]}] = select_data
|
||||||
outputs[f"{action.alias}_select"] = select_data
|
outputs[f"{action.alias}_select"] = select_data
|
||||||
|
|
||||||
if select_data is None:
|
#print(select_data)
|
||||||
print(f"No data selected during {action.name}")
|
|
||||||
|
|
||||||
return action, outputs
|
if select_log:
|
||||||
|
if select_data is None:
|
||||||
|
print(f"No data selected during {action.name}")
|
||||||
|
|
||||||
|
return
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
print(f"Error in selection of {error} during {action.name}")
|
print(f"Error in selection of {error} during {action.name}")
|
||||||
|
|
||||||
except TypeError as error:
|
except TypeError as error:
|
||||||
print(f"TypeError during select: {error} during {action.name}")
|
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"):
|
if hasattr(action, "depends"):
|
||||||
stop = any(
|
stop = any(
|
||||||
dependency in outputs["stopsignals"]
|
dependency in registeredOp["stopsignals"]
|
||||||
for dependency in action.depends
|
for dependency in action.depends
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,8 +13,10 @@ def checkDependency(action, outputs):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def addStopSignal(action, outputs):
|
def addStopSignal(action):
|
||||||
if hasattr(action, "depends"):
|
from core.execution.processregistry import registeredOp
|
||||||
outputs["stopsignals"].append(action.alias)
|
|
||||||
|
|
||||||
return outputs
|
if hasattr(action, "depends"):
|
||||||
|
|
||||||
|
registeredOp["stopsignals"].append(action.alias)
|
||||||
|
return
|
||||||
@@ -1,51 +1,53 @@
|
|||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
from core.runtime.outputs import buildOutput
|
from core.runtime.outputs import buildOutput
|
||||||
from core.runtime.applyconditions import applyConditions
|
from core.runtime.firewall import buildFirewall
|
||||||
from core.execution.operation import buildOperation
|
from core.runtime.createruntime import outputs
|
||||||
from core.execution.executioncontract import executeContract
|
from core.execution.processregistry import processes
|
||||||
|
|
||||||
|
|
||||||
def buildListener(listener, self):
|
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):
|
if self.path.startswith(listener.acceptpath):
|
||||||
|
if hasattr(listener, "print"):
|
||||||
#Prints can used buildlog for listener runtime
|
logging.info(listener.print)
|
||||||
print("Matrix transaction received")
|
|
||||||
|
|
||||||
content_length = int(self.headers["Content-Length"])
|
content_length = int(self.headers["Content-Length"])
|
||||||
|
|
||||||
data = self.rfile.read(content_length)
|
bytes = self.rfile.read(content_length)
|
||||||
request = json.loads(data)
|
|
||||||
|
|
||||||
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 hasattr(listener, "execute"):
|
||||||
if "com.loxthelion.rmass_message_id" in item.get("content", {}):
|
if listener.execute["engine"] == "thread":
|
||||||
print("Excluding previously imported items")
|
from core.execution.createthread import buildThread
|
||||||
#print(item)
|
buildThread(listener.execute["module"])
|
||||||
continue
|
|
||||||
|
|
||||||
print(item)
|
elif listener.execute["engine"] == "contract":
|
||||||
#Process and forward to RMASS
|
from core.execution.executioncontract import executeContract
|
||||||
|
executeContract(listener.execute["module"])
|
||||||
|
|
||||||
outputs, responses = executeContract(listener.execute, outputs)
|
else:
|
||||||
|
if hasattr(listener, "execute"):
|
||||||
|
if listener.execute["engine"] == "thread":
|
||||||
|
from core.execution.createthread import buildThread
|
||||||
|
buildThread(listener.execute["module"])
|
||||||
|
|
||||||
continue
|
elif listener.execute["engine"] == "contract":
|
||||||
|
from core.execution.executioncontract import executeContract
|
||||||
|
executeContract(listener.execute["module"])
|
||||||
|
|
||||||
|
status_code = listener.status_code["success"]
|
||||||
|
|
||||||
self.send_response(200)
|
self.send_response(status_code)
|
||||||
self.send_header("Content-Type", "application/json")
|
self.send_header("Content-Type", "application/json")
|
||||||
self.send_header("Content-Length", "2")
|
self.send_header("Content-Length", "2")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
@@ -54,4 +56,4 @@ def buildListener(listener, self):
|
|||||||
else:
|
else:
|
||||||
self.send_error(404)
|
self.send_error(404)
|
||||||
|
|
||||||
return outputs
|
return
|
||||||
+88
-75
@@ -1,111 +1,124 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
|
|
||||||
from .dispatcher import dispatchRequest
|
|
||||||
from .createresponse import buildResponse
|
#from .dispatcher import dispatchRequest
|
||||||
from core.runtime.outputs import buildOutput
|
#from .createresponse import buildResponse
|
||||||
from core.runtime.resolver import resolveItem
|
from plugins.rmass.listeners import synapselistener, matrixpinglistener
|
||||||
from plugins.rmass.listeners import synapselistener
|
|
||||||
from plugins.rmass.operations import rmassmessagepush
|
|
||||||
from core.execution.action import buildAction
|
|
||||||
from core.server.createlistener import buildListener
|
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))
|
port = int(os.environ.get("SERVER_PORT", 19001))
|
||||||
|
|
||||||
|
|
||||||
class RequestHandler(BaseHTTPRequestHandler):
|
class RequestHandler(BaseHTTPRequestHandler):
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
lifecycles = {}
|
logging.debug("POST request received")
|
||||||
print("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
|
# from core.execution.createthread import buildThread
|
||||||
if content_length is None:
|
# thread = buildThread(synapsesetbridgeonline)
|
||||||
response = {
|
|
||||||
"status": "error",
|
|
||||||
"message": "Content length required"
|
|
||||||
}
|
|
||||||
status = 411
|
|
||||||
|
|
||||||
else:
|
# self.send_response(200)
|
||||||
# Attempt to convert the header into an integer
|
# self.send_header("Content-Type", "application/json")
|
||||||
try:
|
# self.send_header("Content-Length", "2")
|
||||||
length = int(content_length)
|
# self.end_headers()
|
||||||
except ValueError:
|
# self.wfile.write(b"{}")
|
||||||
length = None
|
# return
|
||||||
|
|
||||||
# Validate the converted length
|
# else:
|
||||||
if length is None:
|
# print("POST request received")
|
||||||
response = {
|
|
||||||
"status": "error",
|
|
||||||
"message": "Invalid Content-Length"
|
|
||||||
}
|
|
||||||
status = 400
|
|
||||||
|
|
||||||
elif length < 0:
|
# max_request_size = 1024
|
||||||
response = {
|
|
||||||
"status": "error",
|
|
||||||
"message": "Bad Request"
|
|
||||||
}
|
|
||||||
status = 400
|
|
||||||
|
|
||||||
elif length > max_request_size:
|
# content_length = self.headers.get("Content-Length")
|
||||||
response = {
|
|
||||||
"status": "error",
|
|
||||||
"message": "Content exceeds maximum request size"
|
|
||||||
}
|
|
||||||
status = 413
|
|
||||||
|
|
||||||
else:
|
# # Check whether Content-Length exists
|
||||||
# Content-Length is valid, so read the body
|
# if content_length is None:
|
||||||
data = self.rfile.read(length)
|
# response = {
|
||||||
|
# "status": "error",
|
||||||
|
# "message": "Content length required"
|
||||||
|
# }
|
||||||
|
# status = 411
|
||||||
|
|
||||||
try:
|
# else:
|
||||||
request = json.loads(data)
|
# # Attempt to convert the header into an integer
|
||||||
|
# try:
|
||||||
|
# length = int(content_length)
|
||||||
|
# except ValueError:
|
||||||
|
# length = None
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
# # Validate the converted length
|
||||||
response = {
|
# if length is None:
|
||||||
"status": "error",
|
# response = {
|
||||||
"message": "Invalid JSON received"
|
# "status": "error",
|
||||||
}
|
# "message": "Invalid Content-Length"
|
||||||
status = 400
|
# }
|
||||||
|
# status = 400
|
||||||
|
|
||||||
else:
|
# elif length < 0:
|
||||||
# Only valid JSON reaches the dispatcher
|
# response = {
|
||||||
thread, lifecycles, module, mode = dispatchRequest(
|
# "status": "error",
|
||||||
request, lifecycles
|
# "message": "Bad Request"
|
||||||
)
|
# }
|
||||||
|
# status = 400
|
||||||
|
|
||||||
response = buildResponse(module, thread, mode)
|
# elif length > max_request_size:
|
||||||
status = 200
|
# response = {
|
||||||
|
# "status": "error",
|
||||||
|
# "message": "Content exceeds maximum request size"
|
||||||
|
# }
|
||||||
|
# status = 413
|
||||||
|
|
||||||
# Serialize the response
|
# else:
|
||||||
responsebytes = json.dumps(response).encode("utf-8")
|
# # Content-Length is valid, so read the body
|
||||||
|
# data = self.rfile.read(length)
|
||||||
|
|
||||||
# Send one HTTP response
|
# try:
|
||||||
self.send_response(status)
|
# request = json.loads(data)
|
||||||
self.send_header("Content-Type", "application/json")
|
|
||||||
self.send_header("Content-Length", str(len(responsebytes)))
|
|
||||||
self.end_headers()
|
|
||||||
|
|
||||||
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):
|
def do_PUT(self):
|
||||||
print("PUT request received")
|
logging.debug("PUT request received")
|
||||||
|
|
||||||
outputs = buildListener(synapselistener, self)
|
buildListener(synapselistener, self)
|
||||||
|
|
||||||
def startServer():
|
def startServer():
|
||||||
server = HTTPServer(("0.0.0.0", port), RequestHandler)
|
server = HTTPServer(("0.0.0.0", port), RequestHandler)
|
||||||
|
|
||||||
print(f"Server listening on port {port}")
|
logging.info(f"Server listening on port {port}")
|
||||||
#outputs = {}
|
|
||||||
#outputs, response = buildAction(pingsynapse, outputs)
|
|
||||||
|
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
+34
-13
@@ -1,27 +1,48 @@
|
|||||||
import threading
|
import threading
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from core.server.server import startServer
|
from core.server.server import startServer
|
||||||
from core.execution.createthread import buildThread
|
from core.execution.createthread import buildThread
|
||||||
from plugins.rmass.monitors import rmassmonitor
|
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 login
|
||||||
import synapsemessagepush
|
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(
|
thread = threading.Thread(
|
||||||
target=startServer,
|
target=startServer,
|
||||||
#args=(module, lifecycles)
|
|
||||||
name="RMASS Bridge Server"
|
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 = {}
|
||||||
|
|
||||||
outputs = buildOperation(rmass.operations.login, outputs)
|
responses = buildOperation(rmass.operations.login, outputs)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,6 +7,6 @@ definition = rmassmonitor
|
|||||||
outputs = {}
|
outputs = {}
|
||||||
resolved = {}
|
resolved = {}
|
||||||
while True:
|
while True:
|
||||||
outputs = buildMonitor(definition, outputs)
|
response = buildMonitor(definition, outputs)
|
||||||
|
|
||||||
time.sleep(definition.refreshrate)
|
time.sleep(definition.refreshrate)
|
||||||
+1
-1
@@ -2,5 +2,5 @@ from plugins import rmass
|
|||||||
from core import buildAction
|
from core import buildAction
|
||||||
|
|
||||||
outputs = {}
|
outputs = {}
|
||||||
outputs = buildAction(rmass.actions.pingsynapse, outputs)
|
response = buildAction(rmass.actions.pingsynapse, outputs)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ name = "Get CSRF token"
|
|||||||
|
|
||||||
kind = "action"
|
kind = "action"
|
||||||
|
|
||||||
showstatus = True
|
alias = "getcsrf"
|
||||||
|
|
||||||
|
showstatus = False
|
||||||
|
|
||||||
method = "GET"
|
method = "GET"
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import os
|
|||||||
|
|
||||||
name = "Login"
|
name = "Login"
|
||||||
|
|
||||||
|
alias = "login"
|
||||||
|
|
||||||
kind = "action"
|
kind = "action"
|
||||||
|
|
||||||
showstatus = True
|
showstatus = True
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
name = "Synapse Wake"
|
name = "Synapse Ping"
|
||||||
|
|
||||||
kind = "action"
|
kind = "action"
|
||||||
|
|
||||||
alias = "synapseping"
|
alias = "pingsynapse"
|
||||||
|
|
||||||
showstatus = True
|
showstatus = True
|
||||||
|
|
||||||
|
sleeptime = 15
|
||||||
|
|
||||||
isrequest = True
|
isrequest = True
|
||||||
|
|
||||||
method = "POST"
|
method = "POST"
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ name = "Token refresh"
|
|||||||
|
|
||||||
kind = "action"
|
kind = "action"
|
||||||
|
|
||||||
|
alias = "refresh_tokens"
|
||||||
|
|
||||||
showstatus = True
|
showstatus = True
|
||||||
|
|
||||||
method = "GET"
|
method = "GET"
|
||||||
@@ -44,6 +46,15 @@ outputs = {
|
|||||||
"refresh_token": "refreshToken",
|
"refresh_token": "refreshToken",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
responsepolicy = [
|
||||||
|
{
|
||||||
|
"statuscode": 403,
|
||||||
|
"print": "Refreshing stale tokens...",
|
||||||
|
"execute": login,
|
||||||
|
"response_update": False,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
recoverPolicy = {
|
recoverPolicy = {
|
||||||
FileNotFoundError: [
|
FileNotFoundError: [
|
||||||
getcsrf,
|
getcsrf,
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ responsepolicy = [
|
|||||||
"statuscode": 400,
|
"statuscode": 400,
|
||||||
"print": "Message is too short. Notifying...",
|
"print": "Message is too short. Notifying...",
|
||||||
"execute": synapsenotify,
|
"execute": synapsenotify,
|
||||||
|
"response_update": False,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -87,6 +88,15 @@ outputs = {
|
|||||||
##Filter test against recursiveset
|
##Filter test against recursiveset
|
||||||
|
|
||||||
filters = [
|
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",
|
"filterkey": "msgtype",
|
||||||
"operator": "==",
|
"operator": "==",
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ alias = "synapseassigndmavatar"
|
|||||||
depends = [
|
depends = [
|
||||||
"getrmassuseravatar",
|
"getrmassuseravatar",
|
||||||
"rmassavatartosynapse",
|
"rmassavatartosynapse",
|
||||||
"synapsegetroomid",
|
#"synapsegetroomid",
|
||||||
"synapsecreatedmroom",
|
#"synapsecreatedmroom",
|
||||||
]
|
]
|
||||||
|
|
||||||
kind = "action"
|
kind = "action"
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ showstatus = True
|
|||||||
|
|
||||||
alias = "synapsegetroomalias"
|
alias = "synapsegetroomalias"
|
||||||
|
|
||||||
|
depends = []
|
||||||
|
|
||||||
## PRE-RUNTIME ACTIONS
|
## PRE-RUNTIME ACTIONS
|
||||||
|
|
||||||
resolve = {
|
resolve = {
|
||||||
|
|||||||
@@ -10,15 +10,8 @@ showstatus = True
|
|||||||
|
|
||||||
resolve = {
|
resolve = {
|
||||||
"get": {
|
"get": {
|
||||||
"sender": ["room_name"],
|
"event_id": ["events", 0, "event_id"],
|
||||||
"event_id": ["outmessageitem", "event_id"],
|
"room_id": ["events", 0, "room_id"],
|
||||||
"room_id": ["outmessageitem", "room_id"],
|
|
||||||
},
|
|
||||||
"deconstruct": {
|
|
||||||
"sender" : [
|
|
||||||
"#rmass_dm_",
|
|
||||||
":loxthelion.com",
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
from . import synapsenotify
|
|
||||||
|
|
||||||
name = "Synapse Message Push"
|
name = "Synapse Message Push"
|
||||||
|
|
||||||
kind = "action"
|
kind = "action"
|
||||||
|
|
||||||
|
alias = "synapsepushmessagesaction"
|
||||||
|
|
||||||
showstatus = True
|
showstatus = True
|
||||||
|
|
||||||
resolve = {
|
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.operations import rmassmessagepush
|
||||||
|
from plugins.rmass.actions import synapsenotify
|
||||||
|
|
||||||
name = "Synapse Listener"
|
name = "Synapse Listener"
|
||||||
|
|
||||||
@@ -8,6 +9,19 @@ outputs = {
|
|||||||
"events": "events",
|
"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 = {
|
recursive = {
|
||||||
"source": "events",
|
"source": "events",
|
||||||
"reverse": False,
|
"reverse": False,
|
||||||
@@ -16,27 +30,51 @@ recursive = {
|
|||||||
|
|
||||||
acceptpath = "/_matrix/app/v1/transactions/"
|
acceptpath = "/_matrix/app/v1/transactions/"
|
||||||
|
|
||||||
execute = rmassmessagepush
|
execute = {
|
||||||
|
"module": rmassmessagepush,
|
||||||
|
"engine": "contract",
|
||||||
|
}
|
||||||
|
|
||||||
filters = [
|
filters = [
|
||||||
{
|
{
|
||||||
"filterkey": "event",
|
"filterkey": "filter_item",
|
||||||
"operator": "in",
|
"operator": "in",
|
||||||
"filtervalue": "state_key",
|
"filtervalue": "state_key",
|
||||||
"print": "Excluding state.key event",
|
"print": "Excluding state.key event",
|
||||||
|
"status_code": 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filterkey": "sender",
|
"filterkey": "sender",
|
||||||
"operator": "!=",
|
"operator": "!=",
|
||||||
"filtervalue": "@lyncoln:loxthelion.com",
|
"filtervalue": "@lyncoln:loxthelion.com",
|
||||||
"print": "Excluding message loop item",
|
"print": "Excluding message loop item",
|
||||||
|
"status_code": 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filterkey": "type",
|
"filterkey": "type",
|
||||||
"operator": "!=",
|
"operator": "!=",
|
||||||
"filtervalue": "m.room.message",
|
"filtervalue": "m.room.message",
|
||||||
"print": "Excluding non-room message event",
|
"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 = {
|
#prints = {
|
||||||
# "Status": "message",
|
# "Status": "message",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from plugins.rmass.actions import getcsrf, login
|
from plugins.rmass.actions import getcsrf, login
|
||||||
|
|
||||||
name = "Login"
|
name = "Login Operation"
|
||||||
|
|
||||||
kind = "operation"
|
kind = "operation"
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
from plugins.rmass.actions import rmassmessagepush, savermassmessageid, synapsegetroomalias, synapsegetlastmessage
|
from plugins.rmass.actions import rmassmessagepush, savermassmessageid, synapsegetroomalias, synapsegetlastmessage
|
||||||
from plugins.rmass.operations import rmassattachmentpushflow
|
from plugins.rmass.operations import rmassattachmentpushflow
|
||||||
|
|
||||||
name = "RMASS Message Push"
|
name = "Message Forwarding to RMASS"
|
||||||
|
|
||||||
kind = "recursiveset"
|
kind = "recursiveset"
|
||||||
|
|
||||||
recursiveset = {
|
recursiveset = {
|
||||||
"source": "events",
|
"source": "firewall_allowed",
|
||||||
#"retain": False,
|
#"retain": False,
|
||||||
"outputlabel": "outmessageitem",
|
"outputlabel": "outmessageitem",
|
||||||
"actions": [
|
"actions": [
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ from plugins.rmass.actions import pullmessagelist, refresh_tokens, getmessage, s
|
|||||||
from plugins.rmass.operations import getrmassconversations, synapsepushmessageitems
|
from plugins.rmass.operations import getrmassconversations, synapsepushmessageitems
|
||||||
|
|
||||||
|
|
||||||
name = "Get Message List"
|
name = "Retrieve and Forward RMASS Messages"
|
||||||
|
|
||||||
kind = "operation"
|
kind = "operation"
|
||||||
|
|
||||||
|
alias = "synapsemessagepushoperation"
|
||||||
|
|
||||||
|
track = True
|
||||||
|
|
||||||
actions = [
|
actions = [
|
||||||
#refresh_tokens,
|
#refresh_tokens,
|
||||||
pullmessagelist,
|
pullmessagelist,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ kind = "recursiveset"
|
|||||||
|
|
||||||
name = "Synapse Attachment Push Recursive Set"
|
name = "Synapse Attachment Push Recursive Set"
|
||||||
|
|
||||||
|
alias = "synapsepushmessageattachments"
|
||||||
|
|
||||||
recursiveset = {
|
recursiveset = {
|
||||||
"source": "attachment_list",
|
"source": "attachment_list",
|
||||||
"reverse": False,
|
"reverse": False,
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ kind = "recursiveset"
|
|||||||
|
|
||||||
name = "Synapse Message Push Recursive Set"
|
name = "Synapse Message Push Recursive Set"
|
||||||
|
|
||||||
|
alias = "synapserecursivemessagepush"
|
||||||
|
|
||||||
recursiveset = {
|
recursiveset = {
|
||||||
"source": "getmessage_select",
|
"source": "getmessage_select",
|
||||||
"reverse": True,
|
"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
|
requests
|
||||||
|
rich
|
||||||
+1
-1
@@ -5,6 +5,6 @@ from core.execution.operation import buildOperation
|
|||||||
outputs ={}
|
outputs ={}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
outputs = buildOperation(rmass.operations.setavailable, outputs)
|
responses = buildOperation(rmass.operations.setavailable, outputs)
|
||||||
|
|
||||||
time.sleep(rmass.operations.setavailable.sleeptime)
|
time.sleep(rmass.operations.setavailable.sleeptime)
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ from core.execution.operation import buildOperation
|
|||||||
|
|
||||||
|
|
||||||
outputs = {}
|
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