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.
This commit is contained in:
parent
959db57391
commit
844d420439
1 changed files with 7 additions and 3 deletions
10
worker.py
10
worker.py
|
@ -311,7 +311,7 @@ PersistentKeepalive = {persistent_keepalive}
|
||||||
|
|
||||||
|
|
||||||
# Main function to create and configure the server
|
# 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":
|
if provider == "hetzner":
|
||||||
location = location or config["hetzner"]["location"]
|
location = location or config["hetzner"]["location"]
|
||||||
server_type = server_type or config["hetzner"]["server_type"]
|
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"]
|
listen_port = config["wireguard"]["listen_port"]
|
||||||
persistent_keepalive = config["wireguard"]["peer_persistent_keepalive"]
|
persistent_keepalive = config["wireguard"]["peer_persistent_keepalive"]
|
||||||
|
|
||||||
|
if endpoint_only:
|
||||||
|
print(f"[{server_ip}]:{listen_port}")
|
||||||
|
return
|
||||||
|
|
||||||
peer_config = f"""
|
peer_config = f"""
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = {public_key}
|
PublicKey = {public_key}
|
||||||
|
@ -383,7 +387,6 @@ Endpoint = [{server_ip}]:{listen_port}
|
||||||
PersistentKeepalive = {persistent_keepalive}
|
PersistentKeepalive = {persistent_keepalive}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print("Wireguard Configuration:")
|
|
||||||
print(peer_config)
|
print(peer_config)
|
||||||
|
|
||||||
|
|
||||||
|
@ -405,6 +408,7 @@ def main():
|
||||||
)
|
)
|
||||||
parser.add_argument("--location", type=str, help="Server location")
|
parser.add_argument("--location", type=str, help="Server location")
|
||||||
parser.add_argument("--server_type", type=str, help="Server type")
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Check if the configuration has all the required sections
|
# Check if the configuration has all the required sections
|
||||||
|
@ -415,7 +419,7 @@ def main():
|
||||||
raise ValueError(f"Missing section {section} in config.ini")
|
raise ValueError(f"Missing section {section} in config.ini")
|
||||||
|
|
||||||
# Run the main function with parsed arguments
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue