From 844d420439e0a5c3b9cfcd9890cc365654ab4048 Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 18 Jul 2024 18:05:42 +0200 Subject: [PATCH] feat(worker): add endpoint-only option for server config Introduced a new `--endpoint-only` argument to the `run` function and CLI, which prints only the Wireguard endpoint (host:port) instead of the full peer configuration. This can be useful for quick access to the endpoint without needing the rest of the configuration details. --- worker.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/worker.py b/worker.py index a1f7564..14fd853 100644 --- a/worker.py +++ b/worker.py @@ -311,7 +311,7 @@ PersistentKeepalive = {persistent_keepalive} # Main function to create and configure the server -def run(config, provider, location, server_type): +def run(config, provider, location, server_type, endpoint_only): if provider == "hetzner": location = location or config["hetzner"]["location"] server_type = server_type or config["hetzner"]["server_type"] @@ -374,6 +374,10 @@ def run(config, provider, location, server_type): listen_port = config["wireguard"]["listen_port"] persistent_keepalive = config["wireguard"]["peer_persistent_keepalive"] + if endpoint_only: + print(f"[{server_ip}]:{listen_port}") + return + peer_config = f""" [Peer] PublicKey = {public_key} @@ -383,7 +387,6 @@ Endpoint = [{server_ip}]:{listen_port} PersistentKeepalive = {persistent_keepalive} """ - print("Wireguard Configuration:") print(peer_config) @@ -405,6 +408,7 @@ def main(): ) parser.add_argument("--location", type=str, help="Server location") parser.add_argument("--server_type", type=str, help="Server type") + parser.add_argument("--endpoint-only", action="store_true", help="Return Wireguard endpoint (host:port) instead of full configuration") args = parser.parse_args() # Check if the configuration has all the required sections @@ -415,7 +419,7 @@ def main(): raise ValueError(f"Missing section {section} in config.ini") # Run the main function with parsed arguments - run(config, args.provider, args.location, args.server_type) + run(config, args.provider, args.location, args.server_type, args.endpoint_only) if __name__ == "__main__":