Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ccd44937f | ||
|
|
53021d381e | ||
|
|
433c1e4b77 | ||
|
|
c230939b45 | ||
|
|
2c2a41fafb | ||
|
|
b3094f75a9 | ||
|
|
b5591ade62 | ||
|
|
fe2a54ca00 | ||
|
|
f2df751294 | ||
|
|
50cb0e0924 | ||
|
|
dafde0a805 | ||
|
|
f10ab522c9 | ||
|
|
476ef608f3 | ||
|
|
63330c9ecd | ||
|
|
b59401c64f | ||
|
|
4189812957 |
@@ -1,8 +0,0 @@
|
|||||||
.git
|
|
||||||
.gitignore
|
|
||||||
__pycache__/
|
|
||||||
*.pyc
|
|
||||||
*.pyo
|
|
||||||
*.pyd
|
|
||||||
.venv/
|
|
||||||
venv/
|
|
||||||
+7
-1
@@ -23,4 +23,10 @@ env/
|
|||||||
savedata/
|
savedata/
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
#Trash and unused files
|
||||||
|
trash/
|
||||||
|
|
||||||
|
#Docker files
|
||||||
|
.dockerignore
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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]:
|
||||||
mode = getattr(module, "mode")
|
if hasattr(module, "mode"):
|
||||||
lifecycles[module.name]["mode"] = mode
|
mode = getattr(module, "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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -8,17 +8,17 @@ 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
|
|
||||||
|
|
||||||
from core.execution.executioncontract import executeContract
|
process_log = True
|
||||||
|
|
||||||
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(
|
||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ processes = {}
|
|||||||
registeredOp = {}
|
registeredOp = {}
|
||||||
|
|
||||||
def registerProcess(module):
|
def registerProcess(module):
|
||||||
global registeredOp
|
#global registeredOp
|
||||||
|
|
||||||
processes[module.name] = {}
|
processes[module.name] = {}
|
||||||
|
|
||||||
|
|||||||
@@ -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"]
|
||||||
@@ -52,8 +52,10 @@ def buildRecursive(definition, outputs):
|
|||||||
|
|
||||||
if job.kind == "action":
|
if job.kind == "action":
|
||||||
currentOp[job.name] = {}
|
currentOp[job.name] = {}
|
||||||
|
|
||||||
|
from core.execution.executioncontract import executeContract
|
||||||
|
|
||||||
response = executeContract(job, outputs)
|
response = executeContract(job)
|
||||||
responses.append(response)
|
responses.append(response)
|
||||||
|
|
||||||
if job.kind == "action":
|
if job.kind == "action":
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
outputs = {}
|
||||||
|
|
||||||
|
def getOuputs():
|
||||||
|
return outputs
|
||||||
@@ -20,9 +20,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"))
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -3,17 +3,10 @@ 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
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
|
|
||||||
#Prints can used buildlog for listener runtime
|
#Prints can used buildlog for listener runtime
|
||||||
@@ -24,21 +17,20 @@ def buildListener(listener, self):
|
|||||||
data = self.rfile.read(content_length)
|
data = self.rfile.read(content_length)
|
||||||
request = json.loads(data)
|
request = json.loads(data)
|
||||||
|
|
||||||
outputs = {}
|
#outputs = {}
|
||||||
|
|
||||||
buildOutput(data, listener, outputs)
|
buildOutput(data, listener, outputs)
|
||||||
|
|
||||||
allow, status_code = buildFirewall(listener, outputs)
|
allow, status_code = buildFirewall(listener, outputs)
|
||||||
|
|
||||||
if allow:
|
if allow:
|
||||||
|
#from core.execution.createthread import buildThread
|
||||||
from core.execution.executioncontract import executeContract
|
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
|
#thread = buildThread(listener.execute)
|
||||||
responses = executeContract(listener.execute, outputs)
|
executeContract(listener.execute)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.send_response(status_code)
|
self.send_response(status_code)
|
||||||
|
|||||||
+69
-56
@@ -8,90 +8,103 @@ from .dispatcher import dispatchRequest
|
|||||||
from .createresponse import buildResponse
|
from .createresponse import buildResponse
|
||||||
from plugins.rmass.listeners import synapselistener
|
from plugins.rmass.listeners import synapselistener
|
||||||
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 = {}
|
if self.path == "/_matrix/app/v1/ping":
|
||||||
print("POST request received")
|
|
||||||
|
|
||||||
max_request_size = 1024
|
from core.execution.createthread import buildThread
|
||||||
|
thread = buildThread(synapsesetbridgeonline)
|
||||||
|
|
||||||
content_length = self.headers.get("Content-Length")
|
self.send_response(200)
|
||||||
|
self.send_header("Content-Type", "application/json")
|
||||||
# Check whether Content-Length exists
|
self.send_header("Content-Length", "2")
|
||||||
if content_length is None:
|
self.end_headers()
|
||||||
response = {
|
self.wfile.write(b"{}")
|
||||||
"status": "error",
|
return
|
||||||
"message": "Content length required"
|
|
||||||
}
|
|
||||||
status = 411
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Attempt to convert the header into an integer
|
#lifecycles = {}
|
||||||
try:
|
print("POST request received")
|
||||||
length = int(content_length)
|
|
||||||
except ValueError:
|
|
||||||
length = None
|
|
||||||
|
|
||||||
# Validate the converted length
|
max_request_size = 1024
|
||||||
if length is None:
|
|
||||||
|
content_length = self.headers.get("Content-Length")
|
||||||
|
|
||||||
|
# Check whether Content-Length exists
|
||||||
|
if content_length is None:
|
||||||
response = {
|
response = {
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"message": "Invalid Content-Length"
|
"message": "Content length required"
|
||||||
}
|
}
|
||||||
status = 400
|
status = 411
|
||||||
|
|
||||||
elif length < 0:
|
|
||||||
response = {
|
|
||||||
"status": "error",
|
|
||||||
"message": "Bad Request"
|
|
||||||
}
|
|
||||||
status = 400
|
|
||||||
|
|
||||||
elif length > max_request_size:
|
|
||||||
response = {
|
|
||||||
"status": "error",
|
|
||||||
"message": "Content exceeds maximum request size"
|
|
||||||
}
|
|
||||||
status = 413
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Content-Length is valid, so read the body
|
# Attempt to convert the header into an integer
|
||||||
data = self.rfile.read(length)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = json.loads(data)
|
length = int(content_length)
|
||||||
|
except ValueError:
|
||||||
|
length = None
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
# Validate the converted length
|
||||||
|
if length is None:
|
||||||
response = {
|
response = {
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"message": "Invalid JSON received"
|
"message": "Invalid Content-Length"
|
||||||
}
|
}
|
||||||
status = 400
|
status = 400
|
||||||
|
|
||||||
|
elif length < 0:
|
||||||
|
response = {
|
||||||
|
"status": "error",
|
||||||
|
"message": "Bad Request"
|
||||||
|
}
|
||||||
|
status = 400
|
||||||
|
|
||||||
|
elif length > max_request_size:
|
||||||
|
response = {
|
||||||
|
"status": "error",
|
||||||
|
"message": "Content exceeds maximum request size"
|
||||||
|
}
|
||||||
|
status = 413
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Only valid JSON reaches the dispatcher
|
# Content-Length is valid, so read the body
|
||||||
thread, lifecycles, module, mode = dispatchRequest(
|
data = self.rfile.read(length)
|
||||||
request, lifecycles
|
|
||||||
)
|
|
||||||
|
|
||||||
response = buildResponse(module, thread, mode)
|
try:
|
||||||
status = 200
|
request = json.loads(data)
|
||||||
|
|
||||||
# Serialize the response
|
except json.JSONDecodeError:
|
||||||
responsebytes = json.dumps(response).encode("utf-8")
|
response = {
|
||||||
|
"status": "error",
|
||||||
|
"message": "Invalid JSON received"
|
||||||
|
}
|
||||||
|
status = 400
|
||||||
|
|
||||||
# Send one HTTP response
|
else:
|
||||||
self.send_response(status)
|
# Only valid JSON reaches the dispatcher
|
||||||
self.send_header("Content-Type", "application/json")
|
thread, lifecycles, module, mode = dispatchRequest(
|
||||||
self.send_header("Content-Length", str(len(responsebytes)))
|
request, lifecycles
|
||||||
self.end_headers()
|
)
|
||||||
|
|
||||||
self.wfile.write(responsebytes)
|
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):
|
||||||
|
|||||||
+15
-9
@@ -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
|
||||||
|
|
||||||
|
thread = threading.Thread(
|
||||||
|
target=startServer,
|
||||||
|
name="RMASS Bridge Server"
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
pingsynapse.mode = "continuous"
|
||||||
rmassmonitor.mode = "continuous"
|
rmassmonitor.mode = "continuous"
|
||||||
refresh_tokens.mode = "continuous"
|
token_update.mode = "continuous"
|
||||||
|
#refresh_tokens.mode = "continuous"
|
||||||
|
|
||||||
thread = buildThread(rmassmonitor)
|
thread = buildThread(rmassmonitor)
|
||||||
|
|
||||||
thread = buildThread(refresh_tokens)
|
#thread = buildThread(refresh_tokens)
|
||||||
|
|
||||||
thread = threading.Thread(
|
thread = buildThread(token_update)
|
||||||
target=startServer,
|
|
||||||
#args=(module, lifecycles)
|
thread = buildThread(pingsynapse)
|
||||||
name="RMASS Bridge Server"
|
|
||||||
)
|
|
||||||
thread.start()
|
|
||||||
@@ -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,
|
||||||
|
|||||||
@@ -10,16 +10,9 @@ 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",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = [
|
keys = [
|
||||||
|
|||||||
@@ -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",
|
||||||
|
},
|
||||||
|
]
|
||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
@@ -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,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, None, None)
|
|
||||||
|
|
||||||
#print(lifecycles)
|
|
||||||
|
|
||||||
time.sleep(module.sleeptime)
|
|
||||||
|
|
||||||
elif lifecycles[module.name]["mode"] == "oneshot":
|
|
||||||
print(lifecycles)
|
|
||||||
outputs = executeContract(module, None, None)
|
|
||||||
|
|
||||||
#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