From 458fc6211627dd2acf1368560655bb2e2bae5b5a Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Tue, 16 Apr 2024 08:11:49 +1000 Subject: [PATCH] Remove mock server entry point --- pyproject.toml | 2 - src/dispatch/test/__main__.py | 96 ----------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 src/dispatch/test/__main__.py diff --git a/pyproject.toml b/pyproject.toml index 93e98636..16101a60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,8 +15,6 @@ dependencies = [ "grpc-stubs >= 1.53.0.5", "http-message-signatures >= 0.4.4", "tblib >= 3.0.0", - "docopt >= 0.6.2", - "types-docopt >= 0.6.11.4", "httpx >= 0.27.0", "typing_extensions >= 4.10" ] diff --git a/src/dispatch/test/__main__.py b/src/dispatch/test/__main__.py deleted file mode 100644 index 30eb1b75..00000000 --- a/src/dispatch/test/__main__.py +++ /dev/null @@ -1,96 +0,0 @@ -"""Mock Dispatch server for use in test environments. - -Usage: - dispatch.test [--api-key=] [--hostname=] [--port=] [-v | --verbose] - dispatch.test -h | --help - -Options: - --api-key= API key to require when clients connect to the server [default: test]. - - --hostname= Hostname to listen on [default: 127.0.0.1]. - --port= Port to listen on [default: 4450]. - - -v --verbose Show verbose details in the log. - -h --help Show this help information. -""" - -import base64 -import logging -import os -import sys - -from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey -from docopt import docopt - -from dispatch.test import DispatchServer, DispatchService, EndpointClient - - -def main(): - args = docopt(__doc__) - - if args["--help"]: - print(__doc__) - exit(0) - - endpoint = args[""] - api_key = args["--api-key"] - hostname = args["--hostname"] - port_str = args["--port"] - - try: - port = int(port_str) - except ValueError: - print(f"error: invalid port: {port_str}", file=sys.stderr) - exit(1) - - if not os.getenv("NO_COLOR"): - logging.addLevelName(logging.WARNING, f"\033[1;33mWARN\033[1;0m") - logging.addLevelName(logging.ERROR, "\033[1;31mERROR\033[1;0m") - - logger = logging.getLogger() - if args["--verbose"]: - logger.setLevel(logging.DEBUG) - fmt = "%(asctime)s [%(levelname)s] %(name)s - %(message)s" - else: - logger.setLevel(logging.INFO) - fmt = "%(asctime)s [%(levelname)s] %(message)s" - logging.getLogger("httpx").disabled = True - - log_formatter = logging.Formatter(fmt=fmt, datefmt="%Y-%m-%d %H:%M:%S") - log_handler = logging.StreamHandler(sys.stderr) - log_handler.setFormatter(log_formatter) - logger.addHandler(log_handler) - - # This private key was generated randomly. - signing_key = Ed25519PrivateKey.from_private_bytes( - b"\x0e\xca\xfb\xc9\xa9Gc'fR\xe4\x97y\xf0\xae\x90\x01\xe8\xd9\x94\xa6\xd4@\xf6\xa7!\x90b\\!z!" - ) - verification_key = base64.b64encode( - signing_key.public_key().public_bytes_raw() - ).decode() - - endpoint_client = EndpointClient.from_url(endpoint, signing_key=signing_key) - - with DispatchService(endpoint_client, api_key=api_key) as service: - with DispatchServer(service, hostname=hostname, port=port) as server: - print(f"Spawned a mock Dispatch server on {hostname}:{port}") - print() - print(f"Dispatching function calls to the endpoint at {endpoint}") - print() - print("The Dispatch SDK can be configured with:") - print() - print(f' export DISPATCH_API_URL="http://{hostname}:{port}"') - print(f' export DISPATCH_API_KEY="{api_key}"') - print(f' export DISPATCH_ENDPOINT_URL="{endpoint}"') - print(f' export DISPATCH_VERIFICATION_KEY="{verification_key}"') - print() - - try: - server.wait() - except KeyboardInterrupt: - print("closing down server after interrupt") - pass - - -if __name__ == "__main__": - main()