From 45b4e65a12a0454ed23ffa67474c0434dc501b1b Mon Sep 17 00:00:00 2001 From: Uchechukwu Orji Date: Mon, 2 Sep 2024 16:23:25 +0100 Subject: [PATCH] improve documentation and comments --- protonvpn-wireguard-config-downloader/Dockerfile | 1 + protonvpn-wireguard-config-downloader/README.md | 4 ++-- .../pyproject.toml | 15 ++++++++------- .../__about__.py | 2 +- .../protonvpn.py | 7 ++----- .../settings.py | 12 +++--------- 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/protonvpn-wireguard-config-downloader/Dockerfile b/protonvpn-wireguard-config-downloader/Dockerfile index 22636c7..dabd290 100644 --- a/protonvpn-wireguard-config-downloader/Dockerfile +++ b/protonvpn-wireguard-config-downloader/Dockerfile @@ -1,6 +1,7 @@ FROM python:3.11-slim-bookworm LABEL org.opencontainers.image.source=https://github.com/kiwix/mirrors-qa +# We need gnupg2 for python-gnupg used in Proton libraries to work properly. RUN apt-get update && apt-get install -y gnupg2 COPY src /src/src diff --git a/protonvpn-wireguard-config-downloader/README.md b/protonvpn-wireguard-config-downloader/README.md index 718b9e4..7d8bee4 100644 --- a/protonvpn-wireguard-config-downloader/README.md +++ b/protonvpn-wireguard-config-downloader/README.md @@ -10,7 +10,7 @@ This script is intended to be used in Linux environments only. - `USERNAME`: username for connnecting to ProtonVPN account - `PASSWORD` - `WORKDIR`: location to store configuration files. (default: /data) -- `WIREGUARD_PORT`: Port of the wireguard configuration files (default: 51820) +- `WIREGUARD_PORT`: Port of the wireguard configuration files (default: 51820).This allows to choose the wireguard port for the configuration files rather than leaving it to the ProtonVPN library which often defaults to the first available port in the session object. ## Usage - Build the image @@ -19,5 +19,5 @@ This script is intended to be used in Linux environments only. ``` - Download the configuration files ```sh - docker run --rm -e USERNAME=abcd@efg -e PASSWORD=pa55word -v ./:/data protonvpn-wireguard-config-downloader protonvpn-wireguard-configs + docker run --rm -e USERNAME=abcd@efg -e PASSWORD=pa55word -v ./proton:/data protonvpn-wireguard-config-downloader protonvpn-wireguard-configs ``` diff --git a/protonvpn-wireguard-config-downloader/pyproject.toml b/protonvpn-wireguard-config-downloader/pyproject.toml index 2b62d11..3cd18fe 100644 --- a/protonvpn-wireguard-config-downloader/pyproject.toml +++ b/protonvpn-wireguard-config-downloader/pyproject.toml @@ -21,6 +21,7 @@ license = {text = "GPL-3.0-or-later"} classifiers = [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", ] @@ -34,19 +35,19 @@ scripts = [ "invoke==2.2.0", ] lint = [ - "black==24.1.1", - "ruff==0.2.0", + "black==24.4.2", + "ruff==0.5.1", ] check = [ - "pyright==1.1.349", + "pyright==1.1.370", ] test = [ - "pytest==8.0.0", - "coverage==7.4.1", + "pytest==8.2.2", + "coverage==7.5.4", ] dev = [ - "pre-commit==3.6.0", - "debugpy==1.8.0", + "pre-commit==3.7.1", + "debugpy==1.8.2", "protonvpn_wireguard_config_downloader[scripts]", "protonvpn_wireguard_config_downloader[lint]", "protonvpn_wireguard_config_downloader[test]", diff --git a/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/__about__.py b/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/__about__.py index a237a3e..5becc17 100644 --- a/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/__about__.py +++ b/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/__about__.py @@ -1 +1 @@ -__version__ = "0.0.1-dev0" +__version__ = "1.0.0" diff --git a/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/protonvpn.py b/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/protonvpn.py index ecca919..9cf0d7d 100644 --- a/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/protonvpn.py +++ b/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/protonvpn.py @@ -33,11 +33,6 @@ async def logout(session: VPNSession) -> None: await session.async_logout() -def wireguard_port_is_available(session: VPNSession, port: int) -> bool: - """Check that the wireguard port is available in the client config.""" - return port in session.client_config.wireguard_ports.udp - - def vpn_servers( session: VPNSession, wireguard_port: int, @@ -51,6 +46,8 @@ def vpn_servers( if wireguard_port not in client_config.wireguard_ports.udp: raise ValueError(f"Port {wireguard_port} is not available in client config.") + # Build up the list of servers, filtering out disabled servers and + # servers that are above the client's tier. logical_servers = ( server for server in session.server_list.logicals diff --git a/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/settings.py b/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/settings.py index caa6a8c..26ceb5f 100644 --- a/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/settings.py +++ b/protonvpn-wireguard-config-downloader/src/protonvpn_wireguard_config_downloader/settings.py @@ -22,14 +22,8 @@ class Settings: DEBUG = bool(getenv("DEBUG", default=False)) WORKDIR = Path(getenv("WORKDIR", default="/data")).resolve() PROTONVPN_VERSION = getenv("PROTONVPN_APP_VERSION", default="4.4.4") - PROTONVPN_APP_VERSION = getenv( - "PROTONVPN_APP_VERSION", default=f"LinuxVPN_{PROTONVPN_VERSION}" - ) - USER_AGENT = getenv( - "USER_AGENT", - default=( - f"ProtonVPN/{PROTONVPN_VERSION} " - f"(Linux; {distro.name()}/{distro.version()})" - ), + PROTONVPN_APP_VERSION = f"LinuxVPN_{PROTONVPN_VERSION}" + USER_AGENT = ( + f"ProtonVPN/{PROTONVPN_VERSION} (Linux; {distro.name()}/{distro.version()})" ) WIREGUARD_PORT = int(getenv("WIREGUARD_PORT", default=51820))