diff --git a/tests/test_app.py b/tests/test_app.py index 725f245..b089239 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,3 +1,6 @@ -def test_true(): - assert True - \ No newline at end of file +from vpn_manager import * + +def test_format_static_peer(): + sp = StaticPeer('sample-public-key', '127.0.0.1', '12345') + peer_section = format_static_peer(sp, '0.0.0.0/0') + assert peer_section == '[Peer]\nPublicKey = sample-public-key\nAllowedIPs = 0.0.0.0/0\nEndpoint = 127.0.0.1:12345\nPersistentKeepAlive = 30' diff --git a/vpn_manager/__init__.py b/vpn_manager/__init__.py index e69de29..737754e 100644 --- a/vpn_manager/__init__.py +++ b/vpn_manager/__init__.py @@ -0,0 +1,2 @@ +from .__main__ import * + diff --git a/vpn_manager/__main__.py b/vpn_manager/__main__.py index 31564bb..46b7f94 100644 --- a/vpn_manager/__main__.py +++ b/vpn_manager/__main__.py @@ -1,3 +1,21 @@ +from dataclasses import dataclass + +@dataclass +class StaticPeer: + public_key: str + endpoint: str + port: str + + +def format_static_peer(static_peer, routes, keepalive=30): + return f'''[Peer] +PublicKey = {static_peer.public_key} +AllowedIPs = {routes} +Endpoint = {static_peer.endpoint}:{static_peer.port} +PersistentKeepAlive = {keepalive}''' + + + def main(): print("run")