commit f4742f00e01e98461bf7ac269d7242a143ebdce6 Author: Lyncoln Date: Thu Oct 8 09:31:29 2026 -0400 v1 server and lifecycle manager working. execution contract added diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ed1cec4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +.gitignore +__pycache__/ +*.pyc +*.pyo +*.pyd +.venv/ +venv/ diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..9841970 --- /dev/null +++ b/Containerfile @@ -0,0 +1,9 @@ +FROM python:3.13-slim + +WORKDIR /rmmanager + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . diff --git a/__pycache__/auth.cpython-314.pyc b/__pycache__/auth.cpython-314.pyc new file mode 100644 index 0000000..c825214 Binary files /dev/null and b/__pycache__/auth.cpython-314.pyc differ diff --git a/__pycache__/dispatch.cpython-314.pyc b/__pycache__/dispatch.cpython-314.pyc new file mode 100644 index 0000000..23122db Binary files /dev/null and b/__pycache__/dispatch.cpython-314.pyc differ diff --git a/__pycache__/executerequest.cpython-314.pyc b/__pycache__/executerequest.cpython-314.pyc new file mode 100644 index 0000000..cb8e26c Binary files /dev/null and b/__pycache__/executerequest.cpython-314.pyc differ diff --git a/__pycache__/lifecyclemanager.cpython-314.pyc b/__pycache__/lifecyclemanager.cpython-314.pyc new file mode 100644 index 0000000..442eaa9 Binary files /dev/null and b/__pycache__/lifecyclemanager.cpython-314.pyc differ diff --git a/__pycache__/logs.cpython-314.pyc b/__pycache__/logs.cpython-314.pyc new file mode 100644 index 0000000..2111954 Binary files /dev/null and b/__pycache__/logs.cpython-314.pyc differ diff --git a/__pycache__/managefailure.cpython-314.pyc b/__pycache__/managefailure.cpython-314.pyc new file mode 100644 index 0000000..a55116c Binary files /dev/null and b/__pycache__/managefailure.cpython-314.pyc differ diff --git a/__pycache__/operation.cpython-314.pyc b/__pycache__/operation.cpython-314.pyc new file mode 100644 index 0000000..6be29d6 Binary files /dev/null and b/__pycache__/operation.cpython-314.pyc differ diff --git a/__pycache__/outputs.cpython-314.pyc b/__pycache__/outputs.cpython-314.pyc new file mode 100644 index 0000000..ab0b252 Binary files /dev/null and b/__pycache__/outputs.cpython-314.pyc differ diff --git a/__pycache__/savedata.cpython-314.pyc b/__pycache__/savedata.cpython-314.pyc new file mode 100644 index 0000000..7a2cbb0 Binary files /dev/null and b/__pycache__/savedata.cpython-314.pyc differ diff --git a/checkavailable.py b/checkavailable.py new file mode 100644 index 0000000..127fc02 --- /dev/null +++ b/checkavailable.py @@ -0,0 +1,5 @@ +from plugins import rmass +from core.operation.operation import buildOperation + +outputs = buildOperation(rmass.checkavailableoperation) + diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..8248335 --- /dev/null +++ b/core/__init__.py @@ -0,0 +1,5 @@ +from .apirequest import executeRequest +from .runtime import buildSave, loadSave, buildLog, manageFailure, buildOutput +#from .execution import buildOperation, buildAction +from .execution.action import buildAction +from .execution.operation import buildOperation diff --git a/core/__pycache__/__init__.cpython-314.pyc b/core/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..f0d3a3c Binary files /dev/null and b/core/__pycache__/__init__.cpython-314.pyc differ diff --git a/core/apirequest/__init__.py b/core/apirequest/__init__.py new file mode 100644 index 0000000..613d1c5 --- /dev/null +++ b/core/apirequest/__init__.py @@ -0,0 +1 @@ +from .execute import executeRequest diff --git a/core/apirequest/__pycache__/__init__.cpython-314.pyc b/core/apirequest/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..efc5454 Binary files /dev/null and b/core/apirequest/__pycache__/__init__.cpython-314.pyc differ diff --git a/core/apirequest/__pycache__/execute.cpython-314.pyc b/core/apirequest/__pycache__/execute.cpython-314.pyc new file mode 100644 index 0000000..8a23855 Binary files /dev/null and b/core/apirequest/__pycache__/execute.cpython-314.pyc differ diff --git a/core/apirequest/__pycache__/key.cpython-314.pyc b/core/apirequest/__pycache__/key.cpython-314.pyc new file mode 100644 index 0000000..b7c97d2 Binary files /dev/null and b/core/apirequest/__pycache__/key.cpython-314.pyc differ diff --git a/core/apirequest/__pycache__/object.cpython-314.pyc b/core/apirequest/__pycache__/object.cpython-314.pyc new file mode 100644 index 0000000..1dcc55d Binary files /dev/null and b/core/apirequest/__pycache__/object.cpython-314.pyc differ diff --git a/core/apirequest/__pycache__/request.cpython-314.pyc b/core/apirequest/__pycache__/request.cpython-314.pyc new file mode 100644 index 0000000..3ab67a8 Binary files /dev/null and b/core/apirequest/__pycache__/request.cpython-314.pyc differ diff --git a/core/apirequest/execute.py b/core/apirequest/execute.py new file mode 100644 index 0000000..b451791 --- /dev/null +++ b/core/apirequest/execute.py @@ -0,0 +1,26 @@ +import requests + +from .request import buildRequest + +session = requests.Session() + +def executeRequest(definition, outputs): + request = buildRequest(definition, outputs) + + response = session.request( + method=request["method"], + url=request["path"], + json=request.get("object"), + headers=request.get("headers") + ) + +# if definition hasattr(cookies): +# sessioncookies = {} + +# for cookie_name, cookie_key in cookies: + +# session.cookies.set( +# sessioncookies[cookie_name] = response[cookie_key], + + + return response diff --git a/core/apirequest/key.py b/core/apirequest/key.py new file mode 100644 index 0000000..ac076a4 --- /dev/null +++ b/core/apirequest/key.py @@ -0,0 +1,9 @@ +def buildKey(key, outputs): + value = key["keyvalue"] + + if isinstance(value, dict) and "output" in value: + value = outputs[value["output"]] + + return { + key["keytitle"]: value, + } diff --git a/core/apirequest/object.py b/core/apirequest/object.py new file mode 100644 index 0000000..79a1eb3 --- /dev/null +++ b/core/apirequest/object.py @@ -0,0 +1,11 @@ +from .key import buildKey + +def buildObject(keys, outputs): + object = {} + + for key in keys: + object.update( + buildKey(key, outputs), + ) + + return object diff --git a/core/apirequest/request.py b/core/apirequest/request.py new file mode 100644 index 0000000..ea1dc62 --- /dev/null +++ b/core/apirequest/request.py @@ -0,0 +1,28 @@ +from .object import buildObject + +def buildRequest(definition, outputs): + request = { + "method": definition.method, + "path": definition.path, + } + + if hasattr(definition, "keys"): + request["object"] = buildObject(definition.keys, outputs) + + if hasattr(definition, "headers"): + headers = {} + + for header_name, header_value in definition.headers.items(): + value = header_value + + if isinstance(value, dict) and "output" in header_value: + value = outputs[value["output"]] + + if isinstance(header_value, dict) and "prefix" in header_value: + value = header_value["prefix"] + value + + headers[header_name] = value + + request["headers"] = headers + + return request diff --git a/core/execution/__init__.py b/core/execution/__init__.py new file mode 100644 index 0000000..af15bc1 --- /dev/null +++ b/core/execution/__init__.py @@ -0,0 +1,2 @@ +#from . import action +#from . import operation diff --git a/core/execution/__pycache__/__init__.cpython-314.pyc b/core/execution/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..4c9c3a8 Binary files /dev/null and b/core/execution/__pycache__/__init__.cpython-314.pyc differ diff --git a/core/execution/action/__init__.py b/core/execution/action/__init__.py new file mode 100644 index 0000000..b1d3e8d --- /dev/null +++ b/core/execution/action/__init__.py @@ -0,0 +1,3 @@ +from .action import buildAction +#from .runtime import buildSave, loadSave, buildLog, manageFailure, buildOutput +#rom .orchestrator import buildOperation diff --git a/core/execution/action/__pycache__/__init__.cpython-314.pyc b/core/execution/action/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..d7d54a8 Binary files /dev/null and b/core/execution/action/__pycache__/__init__.cpython-314.pyc differ diff --git a/core/execution/action/__pycache__/action.cpython-314.pyc b/core/execution/action/__pycache__/action.cpython-314.pyc new file mode 100644 index 0000000..826ebdc Binary files /dev/null and b/core/execution/action/__pycache__/action.cpython-314.pyc differ diff --git a/core/execution/action/action.py b/core/execution/action/action.py new file mode 100644 index 0000000..20016d5 --- /dev/null +++ b/core/execution/action/action.py @@ -0,0 +1,25 @@ +from core.apirequest import executeRequest +from core.runtime.savedata import loadSave, buildSave +from core.runtime.outputs import buildOutput +from core.runtime.logs import buildLog + +def buildAction (action, outputs): + + if hasattr(action, "loaddata"): + outputs = loadSave(outputs, action) + + response = executeRequest(action, outputs) + + if hasattr(action, "outputs"): + outputs = buildOutput(response, action, outputs) + + if hasattr(action, "savedata"): + save_file = buildSave(outputs, action) + + if hasattr(action, "prints"): + logs = buildLog(action, outputs) + + if action.showstatus is True and response.status_code == 200: + print(f"{action.name} successful") + + return outputs, response diff --git a/core/execution/executioncontract.py b/core/execution/executioncontract.py new file mode 100644 index 0000000..eb6f080 --- /dev/null +++ b/core/execution/executioncontract.py @@ -0,0 +1,9 @@ +from core.execution.action import buildAction +from core.execution.operation import buildOperation + +def executeContract(module) + if module.kind == "operation": + outputs = buildOperation(module) + + elif module.kind == "action": + outputs = buildAction(module) diff --git a/core/execution/operation/__init__.py b/core/execution/operation/__init__.py new file mode 100644 index 0000000..8de464b --- /dev/null +++ b/core/execution/operation/__init__.py @@ -0,0 +1 @@ +from .operation import buildOperation diff --git a/core/execution/operation/__pycache__/__init__.cpython-314.pyc b/core/execution/operation/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..c487459 Binary files /dev/null and b/core/execution/operation/__pycache__/__init__.cpython-314.pyc differ diff --git a/core/execution/operation/__pycache__/logs.cpython-314.pyc b/core/execution/operation/__pycache__/logs.cpython-314.pyc new file mode 100644 index 0000000..5ff5942 Binary files /dev/null and b/core/execution/operation/__pycache__/logs.cpython-314.pyc differ diff --git a/core/execution/operation/__pycache__/managefailure.cpython-314.pyc b/core/execution/operation/__pycache__/managefailure.cpython-314.pyc new file mode 100644 index 0000000..85187af Binary files /dev/null and b/core/execution/operation/__pycache__/managefailure.cpython-314.pyc differ diff --git a/core/execution/operation/__pycache__/operation.cpython-314.pyc b/core/execution/operation/__pycache__/operation.cpython-314.pyc new file mode 100644 index 0000000..3fd4a50 Binary files /dev/null and b/core/execution/operation/__pycache__/operation.cpython-314.pyc differ diff --git a/core/execution/operation/__pycache__/outputs.cpython-314.pyc b/core/execution/operation/__pycache__/outputs.cpython-314.pyc new file mode 100644 index 0000000..8dac8d6 Binary files /dev/null and b/core/execution/operation/__pycache__/outputs.cpython-314.pyc differ diff --git a/core/execution/operation/__pycache__/savedata.cpython-314.pyc b/core/execution/operation/__pycache__/savedata.cpython-314.pyc new file mode 100644 index 0000000..bbee47d Binary files /dev/null and b/core/execution/operation/__pycache__/savedata.cpython-314.pyc differ diff --git a/core/execution/operation/__pycache__/skipstep.cpython-314.pyc b/core/execution/operation/__pycache__/skipstep.cpython-314.pyc new file mode 100644 index 0000000..e5f87e3 Binary files /dev/null and b/core/execution/operation/__pycache__/skipstep.cpython-314.pyc differ diff --git a/core/execution/operation/operation.py b/core/execution/operation/operation.py new file mode 100644 index 0000000..864a03e --- /dev/null +++ b/core/execution/operation/operation.py @@ -0,0 +1,41 @@ +import logging +#from core import buildAction +from core.runtime.savedata import buildSave, loadSave +from core.runtime.logs import buildLog +from core.runtime.outputs import buildOutput +from core.runtime.managefailure import manageFailure +from core.execution.action.action import buildAction +from .skipstep import skipStep + +def buildOperation(definition): + actions = definition.actions + +# responses = [] + outputs = {} + + for action in actions: + try: + if hasattr(definition, "skipstep"): + if skipStep(definition, action, outputs): + continue + + outputs, response = buildAction(action, outputs) +# responses.append(response) + + except Exception as error: + outputs = manageFailure(error, action, outputs) + +# if hasattr(action, "cookies"): +# for cookiename, cookie, in cookies: + +# session.cookies.set( +# cookiename, +# outputs[cookie], +# domain=domainname +# ) + +# print( +# {outputs[cookie]}, +# domain, +# cookiename, +# ) diff --git a/core/execution/operation/skipstep.py b/core/execution/operation/skipstep.py new file mode 100644 index 0000000..571da5a --- /dev/null +++ b/core/execution/operation/skipstep.py @@ -0,0 +1,14 @@ +def skipStep(definition, action, outputs): + try: + if action in definition.skipstep: + condition = definition.skipstep[action] + + current_value = outputs[condition["output"]] + + if condition["operator"] == ">=": + if current_value >= condition["value"]: + print(f"Skipping {action.name}") + return True + + except TypeError, KeyError: + return False diff --git a/core/manager/__init__.py b/core/manager/__init__.py new file mode 100644 index 0000000..5762ccb --- /dev/null +++ b/core/manager/__init__.py @@ -0,0 +1 @@ +from . import manager diff --git a/core/manager/__pycache__/__init__.cpython-314.pyc b/core/manager/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..24adde1 Binary files /dev/null and b/core/manager/__pycache__/__init__.cpython-314.pyc differ diff --git a/core/manager/__pycache__/manager.cpython-314.pyc b/core/manager/__pycache__/manager.cpython-314.pyc new file mode 100644 index 0000000..94c0514 Binary files /dev/null and b/core/manager/__pycache__/manager.cpython-314.pyc differ diff --git a/core/manager/manager.py b/core/manager/manager.py new file mode 100644 index 0000000..4b124f8 --- /dev/null +++ b/core/manager/manager.py @@ -0,0 +1,25 @@ +from datetime import datetime +from core.operation.operation import buildOperation + +def buildManager(definition): + operations = definition.operations + + current_time = datetime.now().time() + + for operation in operations: + if hasattr(operation, "role") and operation.role == "activate": + if definition.uptime <= current_time <= definition.downtime: + while True: + current_time = datetime.now().time() + outputs = buildOperation(operation) + + if hasattr(operation, "role") and operation.role == "deactivate": + if definition.downtime <= current_time <= definition.uptime: + while True: + current_time = datetime.now().time() + outputs = buildOperation(operation) + +# if hasattr(operation, "role") and role == offline: +# outputs = buildOperation(operation) + + diff --git a/core/runtime/__init__.py b/core/runtime/__init__.py new file mode 100644 index 0000000..9d915dd --- /dev/null +++ b/core/runtime/__init__.py @@ -0,0 +1,9 @@ +#from .managefailure import manageFailure +#from . import outputs +#from . import managefailure +#from . import savedata +from .outputs import buildOutput +from .savedata import buildSave, loadSave +from .logs import buildLog +#from . import managefailure +from .managefailure import manageFailure diff --git a/core/runtime/__pycache__/__init__.cpython-314.pyc b/core/runtime/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..9203522 Binary files /dev/null and b/core/runtime/__pycache__/__init__.cpython-314.pyc differ diff --git a/core/runtime/__pycache__/logs.cpython-314.pyc b/core/runtime/__pycache__/logs.cpython-314.pyc new file mode 100644 index 0000000..64fda39 Binary files /dev/null and b/core/runtime/__pycache__/logs.cpython-314.pyc differ diff --git a/core/runtime/__pycache__/managefailure.cpython-314.pyc b/core/runtime/__pycache__/managefailure.cpython-314.pyc new file mode 100644 index 0000000..b65f5eb Binary files /dev/null and b/core/runtime/__pycache__/managefailure.cpython-314.pyc differ diff --git a/core/runtime/__pycache__/outputs.cpython-314.pyc b/core/runtime/__pycache__/outputs.cpython-314.pyc new file mode 100644 index 0000000..fead9c2 Binary files /dev/null and b/core/runtime/__pycache__/outputs.cpython-314.pyc differ diff --git a/core/runtime/__pycache__/savedata.cpython-314.pyc b/core/runtime/__pycache__/savedata.cpython-314.pyc new file mode 100644 index 0000000..7c5945a Binary files /dev/null and b/core/runtime/__pycache__/savedata.cpython-314.pyc differ diff --git a/core/runtime/logs.py b/core/runtime/logs.py new file mode 100644 index 0000000..aca56c0 --- /dev/null +++ b/core/runtime/logs.py @@ -0,0 +1,11 @@ +def buildLog (action, outputs): +# try: + for print_name, print_key in action.prints.items(): + print( + f"{print_name}:", + f"{outputs[print_key]}", + ) + + # except KeyError: + #outputs[print_key] = "N/A" + # return diff --git a/core/runtime/managefailure.py b/core/runtime/managefailure.py new file mode 100644 index 0000000..ff94b43 --- /dev/null +++ b/core/runtime/managefailure.py @@ -0,0 +1,19 @@ +from core.runtime.outputs import buildOutput +from core.execution.action.action import buildAction +#from core.runtime.outputs import buildOutput + +def manageFailure(error, action, outputs): + if hasattr(action, "recoverPolicy"): + errors = action.recoverPolicy + error_type = type(error) + + print(f"{type(error).__name__} detected during {action.name}. Applying recovery policy.") + + if error_type in errors: + repairs = errors[error_type] + + for repair in repairs: + outputs, response = buildAction(repair, outputs) + + return outputs + print(f"{error}") diff --git a/core/runtime/outputs.py b/core/runtime/outputs.py new file mode 100644 index 0000000..a64740a --- /dev/null +++ b/core/runtime/outputs.py @@ -0,0 +1,21 @@ +def buildOutput(response, action, outputs): + + response_data = response.json() + response_objects = [response_data] + + while response_objects: + response_object = response_objects.pop() + + for key, value, in response_object.items(): + + if isinstance(value, dict): + response_objects.append(value) + + for output_name, response_key in action.outputs.items(): + if key == response_key: + outputs[output_name] = value + + + return outputs + + diff --git a/core/runtime/savedata.py b/core/runtime/savedata.py new file mode 100644 index 0000000..44998b6 --- /dev/null +++ b/core/runtime/savedata.py @@ -0,0 +1,24 @@ +import json + +def buildSave(outputs, action): + save_data = {} + + for save_name in action.savedata: + save_data[save_name] = outputs[save_name] + + with open(f"{action.savepath}", "w") as save_file: + json.dump(save_data, save_file) + + print(f"{save_name} saved by {action.name}") + + return save_file + +def loadSave(outputs, action): + with open(f"{action.savepath}", "r") as save_file: + load_data = json.load(save_file) + + for load_name in action.loaddata: + outputs[load_name] = load_data[load_name] + print(f"{load_name} loaded by {action.name}") + + return outputs diff --git a/dispatch.py b/dispatch.py new file mode 100644 index 0000000..0a4bee0 --- /dev/null +++ b/dispatch.py @@ -0,0 +1,55 @@ +from core.execution.action import buildAction +from core.execution.operation import buildOperation +import plugins +import importlib +import threading +from lifecyclemanager import manageLifecycle + +lifecycles = {} + +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") + + if mode == "continuous": + + state = { + "mode": "continuous" + } + + lifecycles[resolveddispatch] = state + + print(f"Dispatching: {module.name}") + + thread = threading.Thread( + target=manageLifecycle, + args=(module, state) + ) + + thread.start() + print(f"Started lifecycle: {module.name}") + + elif mode == "stop": + if resolveddispatch in lifecycles: + state = lifecycles[resolveddispatch] + state["mode"] = "stop" + print(f"Stopping lifecycle: {module.name}") + else: + print(f"No registered lifecycle: {module.name}") + + elif mode == "oneshot": + outputs = manageLifecycle(module, {"mode": "oneshot"}) + + else: + raise ValueError(f"Unsupported lifecycle mode {mode}") + + return + #outputs = manageLifecycle(module, state) diff --git a/lifecyclemanager.py b/lifecyclemanager.py new file mode 100644 index 0000000..1cf7388 --- /dev/null +++ b/lifecyclemanager.py @@ -0,0 +1,23 @@ +from core.execution.operation import buildOperation +from core.execution.action import buildAction +import time + +def executeContract(module): + if module.kind == "operation": + outputs = buildOperation(module) + + elif module.kind == "action": + outputs = buildAction(module) + + +def manageLifecycle(module, state): + if state["mode"] == "continuous": + while state["mode"] == "continuous": + outputs = executeContract(module) + + time.sleep(module.sleeptime) + + elif state["mode"] == "oneshot": + outputs = executeContract(module) + + return diff --git a/login.py b/login.py new file mode 100644 index 0000000..a39d8bd --- /dev/null +++ b/login.py @@ -0,0 +1,5 @@ +from plugins import rmass +from core.execution.operation import buildOperation + +outputs = buildOperation(rmass.operations.login) + diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..898b8d2 --- /dev/null +++ b/manage.py @@ -0,0 +1,4 @@ +from plugins import rmass +from operation import buildOperation + +outputs = buildOperation(rmass.checkavailableoperation) diff --git a/manager.py b/manager.py new file mode 100644 index 0000000..629aa24 --- /dev/null +++ b/manager.py @@ -0,0 +1,4 @@ +from core.manager.manager import buildManager +from plugins import rmass + +outputs = buildManager(rmass.manager) diff --git a/plugins/__init__.py b/plugins/__init__.py new file mode 100644 index 0000000..8abf564 --- /dev/null +++ b/plugins/__init__.py @@ -0,0 +1 @@ +from . import rmass diff --git a/plugins/__pycache__/__init__.cpython-314.pyc b/plugins/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..94fd148 Binary files /dev/null and b/plugins/__pycache__/__init__.cpython-314.pyc differ diff --git a/plugins/rmass/__init__.py b/plugins/rmass/__init__.py new file mode 100644 index 0000000..8142fd0 --- /dev/null +++ b/plugins/rmass/__init__.py @@ -0,0 +1 @@ +from . import actions, operations diff --git a/plugins/rmass/__pycache__/__init__.cpython-314.pyc b/plugins/rmass/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..b90fab0 Binary files /dev/null and b/plugins/rmass/__pycache__/__init__.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/checkavailable.cpython-314.pyc b/plugins/rmass/__pycache__/checkavailable.cpython-314.pyc new file mode 100644 index 0000000..9c6d9bd Binary files /dev/null and b/plugins/rmass/__pycache__/checkavailable.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/checkavailableoperation.cpython-314.pyc b/plugins/rmass/__pycache__/checkavailableoperation.cpython-314.pyc new file mode 100644 index 0000000..1d9b0dd Binary files /dev/null and b/plugins/rmass/__pycache__/checkavailableoperation.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/credentials.cpython-314.pyc b/plugins/rmass/__pycache__/credentials.cpython-314.pyc new file mode 100644 index 0000000..7e2c2f0 Binary files /dev/null and b/plugins/rmass/__pycache__/credentials.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/csrf.cpython-314.pyc b/plugins/rmass/__pycache__/csrf.cpython-314.pyc new file mode 100644 index 0000000..4c9025d Binary files /dev/null and b/plugins/rmass/__pycache__/csrf.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/getcsrf.cpython-314.pyc b/plugins/rmass/__pycache__/getcsrf.cpython-314.pyc new file mode 100644 index 0000000..be2d255 Binary files /dev/null and b/plugins/rmass/__pycache__/getcsrf.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/login.cpython-314.pyc b/plugins/rmass/__pycache__/login.cpython-314.pyc new file mode 100644 index 0000000..0f3da96 Binary files /dev/null and b/plugins/rmass/__pycache__/login.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/loginoperation.cpython-314.pyc b/plugins/rmass/__pycache__/loginoperation.cpython-314.pyc new file mode 100644 index 0000000..c4b921b Binary files /dev/null and b/plugins/rmass/__pycache__/loginoperation.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/manager.cpython-314.pyc b/plugins/rmass/__pycache__/manager.cpython-314.pyc new file mode 100644 index 0000000..0cdbad4 Binary files /dev/null and b/plugins/rmass/__pycache__/manager.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/refresh_tokens.cpython-314.pyc b/plugins/rmass/__pycache__/refresh_tokens.cpython-314.pyc new file mode 100644 index 0000000..8c2b11b Binary files /dev/null and b/plugins/rmass/__pycache__/refresh_tokens.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/refreshoperation.cpython-314.pyc b/plugins/rmass/__pycache__/refreshoperation.cpython-314.pyc new file mode 100644 index 0000000..9925929 Binary files /dev/null and b/plugins/rmass/__pycache__/refreshoperation.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/rmdefinition.cpython-314.pyc b/plugins/rmass/__pycache__/rmdefinition.cpython-314.pyc new file mode 100644 index 0000000..d121af5 Binary files /dev/null and b/plugins/rmass/__pycache__/rmdefinition.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/setavailable.cpython-314.pyc b/plugins/rmass/__pycache__/setavailable.cpython-314.pyc new file mode 100644 index 0000000..f0e318e Binary files /dev/null and b/plugins/rmass/__pycache__/setavailable.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/setavailableoperation.cpython-314.pyc b/plugins/rmass/__pycache__/setavailableoperation.cpython-314.pyc new file mode 100644 index 0000000..3ddddeb Binary files /dev/null and b/plugins/rmass/__pycache__/setavailableoperation.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/setnotset.cpython-314.pyc b/plugins/rmass/__pycache__/setnotset.cpython-314.pyc new file mode 100644 index 0000000..7e2a79c Binary files /dev/null and b/plugins/rmass/__pycache__/setnotset.cpython-314.pyc differ diff --git a/plugins/rmass/__pycache__/setunavailable.cpython-314.pyc b/plugins/rmass/__pycache__/setunavailable.cpython-314.pyc new file mode 100644 index 0000000..872c88a Binary files /dev/null and b/plugins/rmass/__pycache__/setunavailable.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__init__.py b/plugins/rmass/actions/__init__.py new file mode 100644 index 0000000..2d020a5 --- /dev/null +++ b/plugins/rmass/actions/__init__.py @@ -0,0 +1 @@ +from . import login, getcsrf, refresh_tokens, checkavailable, setavailable, setunavailable, setnotset diff --git a/plugins/rmass/actions/__pycache__/__init__.cpython-314.pyc b/plugins/rmass/actions/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..c382f1a Binary files /dev/null and b/plugins/rmass/actions/__pycache__/__init__.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/checkavailable.cpython-314.pyc b/plugins/rmass/actions/__pycache__/checkavailable.cpython-314.pyc new file mode 100644 index 0000000..b9b9da0 Binary files /dev/null and b/plugins/rmass/actions/__pycache__/checkavailable.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/getcsrf.cpython-314.pyc b/plugins/rmass/actions/__pycache__/getcsrf.cpython-314.pyc new file mode 100644 index 0000000..25b8669 Binary files /dev/null and b/plugins/rmass/actions/__pycache__/getcsrf.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/login.cpython-314.pyc b/plugins/rmass/actions/__pycache__/login.cpython-314.pyc new file mode 100644 index 0000000..5b290d2 Binary files /dev/null and b/plugins/rmass/actions/__pycache__/login.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/refresh_tokens.cpython-314.pyc b/plugins/rmass/actions/__pycache__/refresh_tokens.cpython-314.pyc new file mode 100644 index 0000000..c04658f Binary files /dev/null and b/plugins/rmass/actions/__pycache__/refresh_tokens.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/setavailable.cpython-314.pyc b/plugins/rmass/actions/__pycache__/setavailable.cpython-314.pyc new file mode 100644 index 0000000..4868c6c Binary files /dev/null and b/plugins/rmass/actions/__pycache__/setavailable.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/setnotset.cpython-314.pyc b/plugins/rmass/actions/__pycache__/setnotset.cpython-314.pyc new file mode 100644 index 0000000..1f046df Binary files /dev/null and b/plugins/rmass/actions/__pycache__/setnotset.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/setunavailable.cpython-314.pyc b/plugins/rmass/actions/__pycache__/setunavailable.cpython-314.pyc new file mode 100644 index 0000000..dbd8558 Binary files /dev/null and b/plugins/rmass/actions/__pycache__/setunavailable.cpython-314.pyc differ diff --git a/plugins/rmass/actions/checkavailable.py b/plugins/rmass/actions/checkavailable.py new file mode 100644 index 0000000..2b6e47f --- /dev/null +++ b/plugins/rmass/actions/checkavailable.py @@ -0,0 +1,30 @@ +name = "Availability check" + +kind = "action" + +showstatus = False + +method = "GET" + +path = "https://rentmasseur.com/api/v1/account/keeponline" + +outputs = { + "message": "message", + "validTo": "validTo", +} + +headers = { + "Authorization": { + "output": "access_token", + "prefix": "Bearer ", + }, +} + +prints = { + "Status": "message", + "Time Remaining": "validTo", + } + +recoverPolicy = { + KeyError: [] +} diff --git a/plugins/rmass/actions/getcsrf.py b/plugins/rmass/actions/getcsrf.py new file mode 100644 index 0000000..8b77546 --- /dev/null +++ b/plugins/rmass/actions/getcsrf.py @@ -0,0 +1,13 @@ +name = "Get CSRF token" + +kind = "action" + +showstatus = True + +method = "GET" + +path = "https://rentmasseur.com/api/v1/login" + +outputs = { + "csrf_token": "csrf" +} diff --git a/plugins/rmass/actions/login.py b/plugins/rmass/actions/login.py new file mode 100644 index 0000000..b27da35 --- /dev/null +++ b/plugins/rmass/actions/login.py @@ -0,0 +1,47 @@ +import os + +name = "Login" + +kind = "action" + +showstatus = True + +username = os.environ["RM_USER"] +password = os.environ["RM_PASS"] + +keys = [ + { + "keytitle": "email", + "keyvalue": username, + }, + { + "keytitle": "password", + "keyvalue": password, + }, + { + "keytitle": "csrf", + "keyvalue": { + "outputs": "csrf_token", + }, + }, + { + "keytitle": "remember", + "keyvalue": 1, + }, +] + +method = "POST" + +path = "https://rentmasseur.com/api/v1/login" + +outputs = { + "access_token": "accessToken", + "refresh_token": "refreshToken", +} + +savedata = [ + "access_token", + "refresh_token", +] + +savepath = "/home/david/tokens.json" diff --git a/plugins/rmass/actions/refresh_tokens.py b/plugins/rmass/actions/refresh_tokens.py new file mode 100644 index 0000000..fca4ce6 --- /dev/null +++ b/plugins/rmass/actions/refresh_tokens.py @@ -0,0 +1,51 @@ +from . import getcsrf, login + +name = "Token refresh" + +showstatus = True + +method = "GET" + +path = "https://rentmasseur.com/api/v1/refresh/tokens" + +headers = { + "Authorization": { + "output": "refresh_token", + "prefix": "Bearer ", + }, +} + +domainname="rentmasseur.com" + +cookies = { + "accessToken": { + "output": "access_token", + }, + "refeshToken": { + "output": "refresh_token", + }, +} + +loaddata = [ + "access_token", + "refresh_token", +] + +savedata = [ + "access_token", + "refresh_token", +] + +savepath = "/home/david/tokens.json" + +outputs = { + "access_token": "accessToken", + "refresh_token": "refreshToken", +} + +recoverPolicy = { + FileNotFoundError: [ + getcsrf, + login, + ], +} diff --git a/plugins/rmass/actions/setavailable.py b/plugins/rmass/actions/setavailable.py new file mode 100644 index 0000000..a081abe --- /dev/null +++ b/plugins/rmass/actions/setavailable.py @@ -0,0 +1,47 @@ +import os + +name = "Set availability" + +kind = "action" + +id = "setavailable" + +showstatus = True + +skipstep = { + "checkavailable": "validTo >= 3600" +} + +availabletime = int(os.environ.get("AVAILABLE_DURATION",3)) + +duration = availabletime - 1 + +keys = [ + { + "keytitle": "option", + "keyvalue": 1, + }, + { + "keytitle": "duration", + "keyvalue": duration, + }, +] + +method = "PUT" + +path = "https://rentmasseur.com/api/v1/account/dashboard/availability" + +headers = { + "Authorization": { + "output": "access_token", + "prefix": "Bearer ", + }, +} + +outputs = { + "available_until": "validTo" +} + +prints = { + "Available until": "available_until" +} diff --git a/plugins/rmass/actions/setnotset.py b/plugins/rmass/actions/setnotset.py new file mode 100644 index 0000000..6680f36 --- /dev/null +++ b/plugins/rmass/actions/setnotset.py @@ -0,0 +1,24 @@ +import os + +name = "Unset Availability" + +kind = "action" + +availabletime = int(os.environ.get("AVAILABLE_DURATION",3)) + +duration = availabletime - 5 + + + +keys = [ + { + "keytitle": "online", + "keyvalue": 0, + }, +] + +method = "PUT" + +path = "https://rentmasseur.com/api/v1/account/dashboard/availability" + +#headers = "Authorization:" f"Bearer {access_token}" diff --git a/plugins/rmass/actions/setunavailable.py b/plugins/rmass/actions/setunavailable.py new file mode 100644 index 0000000..60ca251 --- /dev/null +++ b/plugins/rmass/actions/setunavailable.py @@ -0,0 +1,26 @@ +import os + +unavailabletime = int(os.environ.get("AVAILABLE_DURATION",3)) + +duration = unavailabletime - 1 + +name = "Set Unavailable" + +kind = "action" + +keys = [ + { + "keytitle": "online", + "keyvalue": 2, + }, + { + "keytitle": "duration", + "keytitle": duration, + }, +] + +method = "PUT" + +path = "https://rentmasseur.com/api/v1/account/dashboard/availability" + +#headers = "Authorization:" f"Bearer {access_token}" diff --git a/plugins/rmass/manager.py b/plugins/rmass/manager.py new file mode 100644 index 0000000..34b8ba2 --- /dev/null +++ b/plugins/rmass/manager.py @@ -0,0 +1,24 @@ +import os +from datetime import datetime +from . import setavailableoperation + +operations = [ + setavailableoperation, + #setunavailableoperation + #setnotsetoperation +] + +uptime = datetime.strptime( + os.environ["TIME_UPTIME"], + "%H:%M" +).time + +downtime = datetime.strptime( + os.environ["TIME_UPTIME"], + "%H:%M" +).time + +offline = datetime.strptime( + os.environ["TIME_OFFLINE"], + "%H:%M" +).time diff --git a/plugins/rmass/operations/__init__.py b/plugins/rmass/operations/__init__.py new file mode 100644 index 0000000..c6042c6 --- /dev/null +++ b/plugins/rmass/operations/__init__.py @@ -0,0 +1,2 @@ +from . import login, checkavailable, setavailable + diff --git a/plugins/rmass/operations/__pycache__/__init__.cpython-314.pyc b/plugins/rmass/operations/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..1646f66 Binary files /dev/null and b/plugins/rmass/operations/__pycache__/__init__.cpython-314.pyc differ diff --git a/plugins/rmass/operations/__pycache__/checkavailable.cpython-314.pyc b/plugins/rmass/operations/__pycache__/checkavailable.cpython-314.pyc new file mode 100644 index 0000000..defe3f2 Binary files /dev/null and b/plugins/rmass/operations/__pycache__/checkavailable.cpython-314.pyc differ diff --git a/plugins/rmass/operations/__pycache__/login.cpython-314.pyc b/plugins/rmass/operations/__pycache__/login.cpython-314.pyc new file mode 100644 index 0000000..e3130a9 Binary files /dev/null and b/plugins/rmass/operations/__pycache__/login.cpython-314.pyc differ diff --git a/plugins/rmass/operations/__pycache__/setavailable.cpython-314.pyc b/plugins/rmass/operations/__pycache__/setavailable.cpython-314.pyc new file mode 100644 index 0000000..02a6f92 Binary files /dev/null and b/plugins/rmass/operations/__pycache__/setavailable.cpython-314.pyc differ diff --git a/plugins/rmass/operations/checkavailable.py b/plugins/rmass/operations/checkavailable.py new file mode 100644 index 0000000..20a81ec --- /dev/null +++ b/plugins/rmass/operations/checkavailable.py @@ -0,0 +1,11 @@ +from plugins.rmass.actions import login, getcsrf, refresh_tokens, checkavailable + +name = "Availability check" + +kind = "operation" + +actions = [ + refresh_tokens, + checkavailable, +] + diff --git a/plugins/rmass/operations/login.py b/plugins/rmass/operations/login.py new file mode 100644 index 0000000..7f96fa2 --- /dev/null +++ b/plugins/rmass/operations/login.py @@ -0,0 +1,10 @@ +from plugins.rmass.actions import getcsrf, login + +name = "Login" + +kind = "operation" + +actions = [ + getcsrf, + login, +] diff --git a/plugins/rmass/operations/manageoperation.py b/plugins/rmass/operations/manageoperation.py new file mode 100644 index 0000000..672afff --- /dev/null +++ b/plugins/rmass/operations/manageoperation.py @@ -0,0 +1,7 @@ +from . import getcsrf, login, checkavailability + +actions = [ + getcsrf, + login, + checkavailability, +] diff --git a/plugins/rmass/operations/setavailable.py b/plugins/rmass/operations/setavailable.py new file mode 100644 index 0000000..72f16fa --- /dev/null +++ b/plugins/rmass/operations/setavailable.py @@ -0,0 +1,23 @@ +from plugins.rmass.actions import login, getcsrf, setavailable, checkavailable, refresh_tokens + +name = "Set Available" + +kind = "operation" + +actions = [ + refresh_tokens, + checkavailable, + setavailable, +] + +sleeptime = 180 + +skipstep = { + setavailable: { + "output": "validTo", + "operator": ">=", + "value": 3600, + } +} + +role = "activate" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests diff --git a/server.py b/server.py new file mode 100644 index 0000000..4238e9e --- /dev/null +++ b/server.py @@ -0,0 +1,25 @@ +import socket +import json +from dispatch import buildDispatch + +server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +server.bind(("127.0.0.1", 19001)) + +server.listen() + +while True: + connection, address = server.accept() + while True: + data = connection.recv(4096) + + request = json.loads(data) + +# if not data: +# break + + dispatch = buildDispatch(request) + + connection.close() + +# server.close() diff --git a/setavailable.py b/setavailable.py new file mode 100644 index 0000000..ac0e310 --- /dev/null +++ b/setavailable.py @@ -0,0 +1,8 @@ +import time +from plugins import rmass +from core.execution.operation import buildOperation + +while True: + outputs = buildOperation(rmass.operations.setavailable) + + time.sleep(rmass.operations.setavailable.sleeptime)