Compare commits

...
19 Commits
Author SHA1 Message Date
Lyncoln 75b4cc92da Repaired build workflow
Build and Publish RMManager Image / build (push) Successful in 46s
2026-10-30 23:41:42 -04:00
Lyncoln f90c3b1424 Added gitea workflow build
Build and Publish RMManager Image / build (push) Failing after 1m31s
2026-10-30 23:37:45 -04:00
Lyncoln 12b28f037a Updated Server to used buildListener for pings and updated the listener and firewall to handle definitions accordingly 2026-10-30 22:50:36 -04:00
Lyncoln 4ccd44937f Added dockerignore to gitignore 2026-10-30 17:28:03 -04:00
Lyncoln 53021d381e Commented out global registeredOp 2026-10-30 17:26:27 -04:00
Lyncoln 433c1e4b77 Updated response policy to use registered op and redo the request where indicated 2026-10-30 17:26:08 -04:00
Lyncoln c230939b45 Updated prints and naming conventions 2026-10-30 17:23:08 -04:00
Lyncoln 2c2a41fafb Implemented Synapse Ping as heartbeat for connection between synapse and RMASS Bridge. Also implemented set online action to update RMASS presence 2026-10-30 17:19:03 -04:00
Lyncoln b3094f75a9 Moved token refresh into its worn operation for process registry compatibility 2026-10-30 10:29:32 -04:00
Lyncoln b5591ade62 Updated resolver to use logging 2026-10-30 02:52:06 -04:00
Lyncoln fe2a54ca00 General housekeeping 2026-10-30 02:51:47 -04:00
Lyncoln f2df751294 Stopped passing outputs into executeContract and treating it as the beginning of the execution boundary 2026-10-30 02:51:11 -04:00
Lyncoln 50cb0e0924 General housekeeping 2026-10-30 02:49:29 -04:00
Lyncoln dafde0a805 Shifted to importing executeContract after filter checks to prevent excessive importing 2026-10-30 02:48:18 -04:00
Lyncoln f10ab522c9 Updated to use logging 2026-10-30 02:46:34 -04:00
Lyncoln 476ef608f3 Updated firewall to use buildThread 2026-10-30 02:18:58 -04:00
Lyncoln 63330c9ecd Imported outputs from external module to facilitate thread building and consistent runtime operation from various entrypoints 2026-10-30 02:18:24 -04:00
Lyncoln b59401c64f Migrated Monitor to create a new thread for subroutines 2026-10-30 00:44:04 -04:00
Lyncoln 4189812957 Update tracked files to respect .gitignore 2026-10-29 15:48:08 -04:00
37 changed files with 487 additions and 359 deletions
-8
View File
@@ -1,8 +0,0 @@
.git
.gitignore
__pycache__/
*.pyc
*.pyo
*.pyd
.venv/
venv/
+182
View File
@@ -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
+6
View File
@@ -24,3 +24,9 @@ savedata/
# Logs # Logs
*.log *.log
#Trash and unused files
trash/
#Docker files
.dockerignore
-2
View File
@@ -2,8 +2,6 @@ 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 action_log = True
+3
View File
@@ -1,4 +1,5 @@
import threading import threading
import logging
from .lifecyclemanager import manageLifecycle from .lifecyclemanager import manageLifecycle
@@ -12,4 +13,6 @@ def buildThread(module):
thread.start() thread.start()
logging.info(f"THREAD STARTED, {thread}")
return thread return thread
+2 -3
View File
@@ -3,17 +3,16 @@ 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, outputs): def executeContract(module):
if module.kind == "operation": if module.kind == "operation":
responses = buildOperation(module, outputs) responses = buildOperation(module, outputs)
return responses return responses
elif module.kind == "action": elif module.kind == "action":
response = buildAction(module, outputs) response = buildAction(module, outputs)
return response return response
@@ -6,9 +6,10 @@ from core.apirequest.execute import getSession
from core.execution.lifecyclemanager.lifecycleregistry import registerLifecycle from core.execution.lifecyclemanager.lifecycleregistry import registerLifecycle
lifecycles = {} lifecycles = {}
outputs = {} #outputs = {}
def manageLifecycle(module): def manageLifecycle(module):
from core.runtime.createruntime import outputs
lifecycle_log = os.environ.get("LOGS_LIFECYCLE", "false").lower() == "true" lifecycle_log = os.environ.get("LOGS_LIFECYCLE", "false").lower() == "true"
registerLifecycle (module, lifecycles) registerLifecycle (module, lifecycles)
@@ -17,7 +18,7 @@ def manageLifecycle(module):
while lifecycles[module.name]["mode"] == "continuous": while lifecycles[module.name]["mode"] == "continuous":
lifecycles[module.name]["state"] = "active" lifecycles[module.name]["state"] = "active"
response = executeContract(module, outputs) executeContract(module)
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")
@@ -34,7 +35,7 @@ def manageLifecycle(module):
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) print(lifecycles)
response = executeContract(module, outputs) response = executeContract(module)
lifecycles[module.name]["state"] = "stopped" lifecycles[module.name]["state"] = "stopped"
@@ -23,14 +23,17 @@ def registerLifecycle(module, lifecycles):
#print(lifecycles) #print(lifecycles)
if "mode" not in lifecycles[module.name]: if "mode" not in lifecycles[module.name]:
if hasattr(module, "mode"):
mode = getattr(module, "mode") mode = getattr(module, "mode")
lifecycles[module.name]["mode"] = mode lifecycles[module.name]["mode"] = mode
else:
lifecycles[module.name]["mode"] = "oneshot"
if lifecycles[module.name]["mode"] == "continuous": if lifecycles[module.name]["mode"] == "continuous":
lifecycles[module.name]["refresh_rate"] = module.sleeptime lifecycles[module.name]["refresh_rate"] = module.sleeptime
if not lifecycles[module.name]["mode"]: #if lifecycles[module.name]["mode"] == {}:
lifecycles[module.name]["mode"] = "oneshot" # lifecycles[module.name]["mode"] = "oneshot"
#lifecycles[module.name][registryname] = registryvalue #lifecycles[module.name][registryname] = registryvalue
+6 -3
View File
@@ -31,11 +31,14 @@ def buildMonitor(monitor, outputs):
buildOutput(response, monitor, outputs) buildOutput(response, monitor, outputs)
if match: if match:
from core.execution.executioncontract import executeContract from core.execution.createthread import buildThread
#from core.execution.executioncontract import executeContract
logging.info(filter.get("print")) logging.info(filter.get("print"))
module = filter["execute"] #module = filter["execute"]
response = executeContract(filter["execute"], outputs) #response = executeContract(filter["execute"], outputs)
thread = buildThread(filter["execute"])
return response return response
+7 -5
View File
@@ -8,18 +8,18 @@ from core.runtime.stopsignals import checkDependency
from core.execution import processregistry from core.execution import processregistry
from core.console import console from core.console import console
outputs = {} #outputs = {}
def buildOperation(definition, outputs): def buildOperation(definition, outputs):
process_log = True process_log = True
from core.execution.executioncontract import executeContract
actions = definition.actions actions = definition.actions
currentOp = processregistry.registerProcess(definition)
responses = [] responses = []
currentOp = processregistry.registerProcess(definition)
if getattr(definition, "track", False): if getattr(definition, "track", False):
actions = track( actions = track(
actions, actions,
@@ -38,7 +38,9 @@ def buildOperation(definition, outputs):
if action.kind == "action": if action.kind == "action":
currentOp[action.name] = {} currentOp[action.name] = {}
response = executeContract(action, outputs) from core.execution.executioncontract import executeContract
response = executeContract(action)
responses.append(response) responses.append(response)
+1 -1
View File
@@ -2,7 +2,7 @@ processes = {}
registeredOp = {} registeredOp = {}
def registerProcess(module): def registerProcess(module):
global registeredOp #global registeredOp
processes[module.name] = {} processes[module.name] = {}
+4 -2
View File
@@ -20,7 +20,7 @@ def buildRecursive(definition, outputs):
currentOp = processregistry.registerProcess(definition) 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"]
@@ -53,7 +53,9 @@ def buildRecursive(definition, outputs):
if job.kind == "action": if job.kind == "action":
currentOp[job.name] = {} currentOp[job.name] = {}
response = executeContract(job, outputs) from core.execution.executioncontract import executeContract
response = executeContract(job)
responses.append(response) responses.append(response)
if job.kind == "action": if job.kind == "action":
+4
View File
@@ -0,0 +1,4 @@
outputs = {}
def getOuputs():
return outputs
+3 -2
View File
@@ -6,6 +6,7 @@ from core.runtime.resolver import resolveItem
def buildFirewall(listener, outputs): def buildFirewall(listener, outputs):
if hasattr(listener, "filters"):
#firewall_log = os.environ.get("LOGS_FIREWALL", "false").lower() == "true" #firewall_log = os.environ.get("LOGS_FIREWALL", "false").lower() == "true"
firewall_log = True firewall_log = True
@@ -20,9 +21,9 @@ def buildFirewall(listener, outputs):
status_code = filter.get("status_code", 200) status_code = filter.get("status_code", 200)
if filter.get("execute", False): if filter.get("execute", False):
from core.apirequest.execute import executeRequest from core.execution.createthread import buildThread
response = executeRequest(filter["execute"], outputs, resolved) thread = buildThread(filter["execute"])
if firewall_log: if firewall_log:
logging.info(filter.get("print")) logging.info(filter.get("print"))
+2 -1
View File
@@ -1,4 +1,5 @@
import os import os
import logging
def resolveItem(action, item): def resolveItem(action, item):
#resolver_log = os.environ.get("LOGS_RESOLVER", "false").lower() == "true" #resolver_log = os.environ.get("LOGS_RESOLVER", "false").lower() == "true"
@@ -17,7 +18,7 @@ def resolveItem(action, item):
except (KeyError, IndexError) as error: except (KeyError, IndexError) as error:
if resolver_log: if resolver_log:
print(f"Resolver target key/index {error} not found during {action.name}") logging.info(f"Resolver target key/index {error} not found during {action.name}")
target = None target = None
resolved[label] = target resolved[label] = target
+16 -2
View File
@@ -1,9 +1,15 @@
import logging 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:
logging.warning(f"{response} during {action.name}") logging.warning(f"{response} during {action.name}")
@@ -11,11 +17,19 @@ def responsePolicy(response, action, outputs, resolved):
if policy["statuscode"] == response.status_code: if policy["statuscode"] == response.status_code:
logging.warning(policy["print"]) logging.warning(policy["print"])
newresponse = executeRequest(policy["execute"], outputs, resolved) from core.execution.executioncontract import executeContract
executeContract(policy["execute"])
#newresponse = executeRequest(action, outputs, resolved)
if policy["response_update"]: if policy["response_update"]:
logging.info("Updating response") logging.info("Updating response")
print("Updating response") newresponse = executeRequest(action, outputs, resolved)
#response = newresponse
if processregistry.registeredOp:
response = processregistry.registeredOp[action.name]["response"]
else:
response = newresponse response = newresponse
break break
+27 -21
View File
@@ -3,43 +3,49 @@ import logging
from core.runtime.outputs import buildOutput from core.runtime.outputs import buildOutput
from core.runtime.firewall import buildFirewall from core.runtime.firewall import buildFirewall
from core.runtime.createruntime import outputs
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)
logging.info("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)
buildOutput(data, listener, outputs) buildOutput(bytes, listener, outputs)
if hasattr(listener, "filters"):
allow, status_code = buildFirewall(listener, outputs) allow, status_code = buildFirewall(listener, outputs)
if allow: if allow:
from core.execution.executioncontract import executeContract
#Print allowed items for logging purposes
logging.info(outputs["firewall_allowed"]) logging.info(outputs["firewall_allowed"])
#Process and forward to RMASS if hasattr(listener, "execute"):
responses = executeContract(listener.execute, outputs) if listener.execute["engine"] == "thread":
from core.execution.createthread import buildThread
buildThread(listener.execute["module"])
elif listener.execute["engine"] == "contract":
from core.execution.executioncontract import executeContract
executeContract(listener.execute["module"])
else:
if hasattr(listener, "execute"):
if listener.execute["engine"] == "thread":
from core.execution.createthread import buildThread
buildThread(listener.execute["module"])
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_response(status_code)
self.send_header("Content-Type", "application/json") self.send_header("Content-Type", "application/json")
@@ -50,4 +56,4 @@ def buildListener(listener, self):
else: else:
self.send_error(404) self.send_error(404)
return outputs return
+85 -70
View File
@@ -4,106 +4,121 @@ 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 plugins.rmass.listeners import synapselistener #from .createresponse import buildResponse
from plugins.rmass.listeners import synapselistener, matrixpinglistener
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)
logging.info(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()
+15 -9
View File
@@ -5,7 +5,8 @@ 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 core.console import console
from rich.logging import RichHandler from rich.logging import RichHandler
@@ -27,16 +28,21 @@ logging.basicConfig(
import login import login
import synapsemessagepush import synapsemessagepush
rmassmonitor.mode = "continuous"
refresh_tokens.mode = "continuous"
thread = buildThread(rmassmonitor)
thread = buildThread(refresh_tokens)
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)
+4 -2
View File
@@ -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"
+11
View File
@@ -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,
+2 -9
View File
@@ -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",
],
}, },
} }
@@ -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
}
+5 -1
View File
@@ -30,7 +30,10 @@ recursive = {
acceptpath = "/_matrix/app/v1/transactions/" acceptpath = "/_matrix/app/v1/transactions/"
execute = rmassmessagepush execute = {
"module": rmassmessagepush,
"engine": "contract",
}
filters = [ filters = [
{ {
@@ -74,3 +77,4 @@ filters = [
] ]
print = "Matrix transaction received"
+1 -1
View File
@@ -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"
+13
View File
@@ -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)
-5
View File
@@ -1,5 +0,0 @@
from plugins import rmass
from core.operation.operation import buildOperation
outputs = buildOperation(rmass.checkavailableoperation)
-17
View File
@@ -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
-30
View File
@@ -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
-22
View File
@@ -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
-41
View File
@@ -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
-25
View File
@@ -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, None, None)
#print(lifecycles)
time.sleep(module.sleeptime)
elif lifecycles[module.name]["mode"] == "oneshot":
print(lifecycles)
outputs = executeContract(module, None, None)
#print(lifecycles)
return
-8
View File
@@ -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
-4
View File
@@ -1,4 +0,0 @@
from plugins import rmass
from operation import buildOperation
outputs = buildOperation(rmass.checkavailableoperation)
-4
View File
@@ -1,4 +0,0 @@
from core.manager.manager import buildManager
from plugins import rmass
outputs = buildManager(rmass.manager)
-29
View File
@@ -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()