This is an automated email from the ASF dual-hosted git repository. sebb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
commit 91ef3996ac4fa5a7b88a18cdc052a6560cb87bcb Author: Sebb <[email protected]> AuthorDate: Thu Jan 27 16:00:36 2022 +0000 Enable test endpoints --- server/main.py | 35 +++++++++++++++++++--------- server/{test => testendpoints}/testauth.py | 3 ++- server/{test => testendpoints}/testauth.yaml | 0 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/server/main.py b/server/main.py index 522756a..f21a684 100644 --- a/server/main.py +++ b/server/main.py @@ -53,6 +53,19 @@ if not sys.stdout.buffer.isatty(): class Server(plugins.server.BaseServer): """Main server class, responsible for handling requests and scheduling offloader threads """ + def _load_endpoint(self, subdir): + for endpoint_file in sorted(os.listdir(subdir)): + if endpoint_file.endswith(".py"): + endpoint = endpoint_file[:-3] + m = importlib.import_module(f"{subdir}.{endpoint}") + if hasattr(m, "register"): + self.handlers[endpoint] = m.__getattribute__("register")(self) + print(f"Registered endpoint /api/{endpoint}") + else: + print( + f"Could not find entry point 'register()' in {endpoint_file}, skipping!" + ) + def __init__(self, args: argparse.Namespace): print( "==== Apache Pony Mail (Foal v/%s ~%s) starting... ====" % (PONYMAIL_FOAL_VERSION, PONYMAIL_SERVER_VERSION) @@ -80,17 +93,12 @@ class Server(plugins.server.BaseServer): self.dbpool.put_nowait(plugins.database.Database(self.config.database)) # Load each URL endpoint - for endpoint_file in os.listdir("endpoints"): - if endpoint_file.endswith(".py"): - endpoint = endpoint_file[:-3] - m = importlib.import_module(f"endpoints.{endpoint}") - if hasattr(m, "register"): - self.handlers[endpoint] = m.__getattribute__("register")(self) - print(f"Registered endpoint /api/{endpoint}") - else: - print( - f"Could not find entry point 'register()' in {endpoint_file}, skipping!" - ) + if args.testendpoints: + print("** Loading additional testing endpoints **") + self._load_endpoint("testendpoints") + print() + self._load_endpoint("endpoints") + if args.logger: import logging es_logger = logging.getLogger('elasticsearch') @@ -262,5 +270,10 @@ if __name__ == "__main__": action='store_true', help="Allow remote refresh for testing", ) + parser.add_argument( + "--testendpoints", + action='store_true', + help="Enable test endpoints", + ) cliargs = parser.parse_args() Server(cliargs).run() diff --git a/server/test/testauth.py b/server/testendpoints/testauth.py similarity index 94% rename from server/test/testauth.py rename to server/testendpoints/testauth.py index 3443647..d03138e 100644 --- a/server/test/testauth.py +++ b/server/testendpoints/testauth.py @@ -19,7 +19,8 @@ Simple endpoint that does a local login To enable: -- copy the files server/test/testauth.[py|.yaml] to the server/endpoints directory +- Add the --testendpoints qualifier to the server startup command + Alternatively copy the files server/test/testauth.[py|.yaml] to the server/endpoints directory They can be renamed if necessary, so long as they have the same basename; adjust the URLs below to reflect the new name diff --git a/server/test/testauth.yaml b/server/testendpoints/testauth.yaml similarity index 100% rename from server/test/testauth.yaml rename to server/testendpoints/testauth.yaml
