From 56de2852c9fa5ed72c4b24efaced8152f07bcd05 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 17 Dec 2024 00:54:38 -0500 Subject: [PATCH] idk, this has kind of stagnated --- .../examples/{server.yaml => Mochafile} | 0 mocha-python/src/mocha-python/mocha-web.py | 18 ++++++++++++++++-- .../src/mocha-python/mocha/web/WebRequest.py | 6 ++++++ .../mocha/web/WebRequestHandler.py | 7 ++++++- .../src/mocha-python/mocha/web/WebServer.py | 6 +++++- .../mocha/web/manager/ServerManager.py | 6 ++++++ .../mocha/web/ui/pages/BaseWebPage.py | 17 +++++++++++------ 7 files changed, 50 insertions(+), 10 deletions(-) rename mocha-python/src/mocha-python/examples/{server.yaml => Mochafile} (100%) create mode 100644 mocha-python/src/mocha-python/mocha/web/WebRequest.py diff --git a/mocha-python/src/mocha-python/examples/server.yaml b/mocha-python/src/mocha-python/examples/Mochafile similarity index 100% rename from mocha-python/src/mocha-python/examples/server.yaml rename to mocha-python/src/mocha-python/examples/Mochafile diff --git a/mocha-python/src/mocha-python/mocha-web.py b/mocha-python/src/mocha-python/mocha-web.py index 47cadaf..6f6e103 100644 --- a/mocha-python/src/mocha-python/mocha-web.py +++ b/mocha-python/src/mocha-python/mocha-web.py @@ -3,9 +3,17 @@ from mocha.web.WebServer import WebServer from mocha.oms import Oms from mocha.oms.memory import MemoryOms -import sys +import os, sys from getopt import getopt +import signal + +def keyi(signum, frame): + print("stopping all servers") + svrmgr.stop() + + print("mocha-cup done") + if __name__ == "__main__": port = 8081 @@ -22,11 +30,17 @@ if __name__ == "__main__": svrmgr = ServerManager() if len(remaining) == 0: - print("error: no server configurations specified") + if os.path.isfile("Mochafile"): + print("[ INFO ]: percolating from Mochafile") + svrmgr.add_server_config("Mochafile") + else: + print("error: no server configurations specified, or Mochafile not present") for library in remaining: svrmgr.add_server_config(library) + signal.signal(signal.SIGINT, keyi) + svrmgr.start() # from mocha.lib.LibraryManager import MochaLibraryManager diff --git a/mocha-python/src/mocha-python/mocha/web/WebRequest.py b/mocha-python/src/mocha-python/mocha/web/WebRequest.py new file mode 100644 index 0000000..b3f7d5b --- /dev/null +++ b/mocha-python/src/mocha-python/mocha/web/WebRequest.py @@ -0,0 +1,6 @@ +class WebRequest: + + def __init__(self, path : list): + self._path = path + + \ No newline at end of file diff --git a/mocha-python/src/mocha-python/mocha/web/WebRequestHandler.py b/mocha-python/src/mocha-python/mocha/web/WebRequestHandler.py index 2e78855..e114c36 100644 --- a/mocha-python/src/mocha-python/mocha/web/WebRequestHandler.py +++ b/mocha-python/src/mocha-python/mocha/web/WebRequestHandler.py @@ -6,12 +6,16 @@ import json from ..oms import Oms from ..web.AssetLocation import LocalAssetLocation, RemoteAssetLocation +from ..web.WebRequest import WebRequest class WebRequestHandler(BaseHTTPRequestHandler): def __init__(self, request, client_address, server): BaseHTTPRequestHandler.__init__(self, request, client_address, server) self.__oms = server._oms + def version_string(self) -> str: + return "Mocha User Interface Service" + @cached_property def url(self): return urlparse(self.path) @@ -166,8 +170,9 @@ Disallow: / if path[1] == "d": if len(path) > 2: if path[2] == "home.htmld": - from .pages import HomeWebPage + from .ui.pages import HomeWebPage page = HomeWebPage() + page.request = WebRequest(path) self.respond_with_content(200, "OK", "application/xhtml+xml", page.render_html()) jj = self.get_json_response() diff --git a/mocha-python/src/mocha-python/mocha/web/WebServer.py b/mocha-python/src/mocha-python/mocha/web/WebServer.py index db5255f..709dbba 100644 --- a/mocha-python/src/mocha-python/mocha/web/WebServer.py +++ b/mocha-python/src/mocha-python/mocha/web/WebServer.py @@ -37,6 +37,10 @@ class WebServer(): from http.server import HTTPServer server = HTTPServer(self.__tup, WebRequestHandler) + self._server = server server._oms = self._oms server._server = self - server.serve_forever() \ No newline at end of file + server.serve_forever() + + def shutdown(self): + self._server.shutdown() \ No newline at end of file diff --git a/mocha-python/src/mocha-python/mocha/web/manager/ServerManager.py b/mocha-python/src/mocha-python/mocha/web/manager/ServerManager.py index be8b07f..c6da94c 100644 --- a/mocha-python/src/mocha-python/mocha/web/manager/ServerManager.py +++ b/mocha-python/src/mocha-python/mocha/web/manager/ServerManager.py @@ -8,6 +8,7 @@ class ServerManager: def __init__(self): self._servers = [ ] + self._threads = [ ] def add_server_config(self, filename): import yaml @@ -72,6 +73,11 @@ class ServerManager: for server in self._servers: t = threading.Thread(target = self._serve, args = [ server ]) t.start() + self._threads.append(t) + + def stop(self): + for server in self._servers: + server.shutdown() def _serve(self, server): server.serve_forever() \ No newline at end of file diff --git a/mocha-python/src/mocha-python/mocha/web/ui/pages/BaseWebPage.py b/mocha-python/src/mocha-python/mocha/web/ui/pages/BaseWebPage.py index dd44267..3089c57 100644 --- a/mocha-python/src/mocha-python/mocha/web/ui/pages/BaseWebPage.py +++ b/mocha-python/src/mocha-python/mocha/web/ui/pages/BaseWebPage.py @@ -22,17 +22,22 @@ class BaseWebPage (WebPage): self._oms = oms def get_client_config_script(self): + tenant_name = "" + if not self.get_oms() is None: + tenant_name = self.get_oms().get_tenant_name() + + return WebScript("text/javascript", content=""" // Add properties to mocha window.mocha = window.mocha || {}; - mocha.tenant = '""" + self.get_oms().get_tenant_name() + """'; + mocha.tenant = '""" + tenant_name + """'; mocha.clientOrigin = 'https://wd5-impl.workday.com'; mocha.language = 'en_US'; mocha.clientVersion = '0'; mocha.systemConfidenceLevel = 'PROD'; mocha.oauthAuthorizationPending = false; mocha.proxyLoginEnabled = false; - mocha.maintenancePageUrl = 'https://wd5-impl.workday.com/wday/drs/outage?t=cityoforlando3'; + mocha.maintenancePageUrl = 'https://wd5-impl.workday.com/madi/drs/outage?t=""" + tenant_name + """'; mocha.deviceTrustDetailsUrl = ''; mocha.pendingAuthDetailsUrl = ''; mocha.webAuthnDetailsUrl = ''; @@ -40,8 +45,8 @@ class BaseWebPage (WebPage): // Construct init params for GWT app mocha.initParams = { - authGatewayPath: '/wday/authgwy', - baseDir: '/wday/asset/ui-html/', + authGatewayPath: '/madi/authgwy', + baseDir: '/madi/asset/ui-html/', systemConfidenceLevel: 'PROD', cdn: { endpoint: 'wd5-impl.workdaycdn.com', @@ -51,8 +56,8 @@ class BaseWebPage (WebPage): proxyEnabled: false, currentVersion: '20.0.04.045', serviceType: 'authgwy', - loginAuthURL: '/cityoforlando3/login-auth.xml', - environment: 'Implementation - cityoforlando3', + loginAuthURL: '/""" + tenant_name + """/login-auth.xml', + environment: 'Implementation - """ + tenant_name + """', environmentType: 'IMPL' }; """) \ No newline at end of file