Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate the use of the library without passing a certificate hash #30

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions outline_vpn/outline_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class OutlineServerErrorException(Exception):
pass


class OutlineLibraryException(Exception):
pass


class _FingerprintAdapter(requests.adapters.HTTPAdapter):
"""
This adapter injected into the requests session will check that the
Expand All @@ -52,15 +56,17 @@ class OutlineVPN:
An Outline VPN connection
"""

def __init__(self, api_url: str, cert_sha256: str = None):
def __init__(self, api_url: str, cert_sha256: str):
self.api_url = api_url

if cert_sha256:
session = requests.Session()
session.mount("https://", _FingerprintAdapter(cert_sha256))
self.session = session
else:
self.session = requests.Session()
raise OutlineLibraryException(
"No certificate SHA256 provided. Running without certificate is no longer supported."
)

def get_keys(self):
"""Get all keys in the outline server"""
Expand Down Expand Up @@ -96,7 +102,9 @@ def get_keys(self):
raise OutlineServerErrorException("Unable to retrieve keys")

def get_key(self, key_id: str) -> OutlineKey:
response = self.session.get(f"{self.api_url}/access-keys/{key_id}", verify=False)
response = self.session.get(
f"{self.api_url}/access-keys/{key_id}", verify=False
)
if response.status_code == 200:
key = response.json()

Expand Down Expand Up @@ -148,7 +156,9 @@ def create_key(self, key_name=None) -> OutlineKey:

def delete_key(self, key_id: str) -> bool:
"""Delete a key"""
response = self.session.delete(f"{self.api_url}/access-keys/{key_id}", verify=False)
response = self.session.delete(
f"{self.api_url}/access-keys/{key_id}", verify=False
)
return response.status_code == 204

def rename_key(self, key_id: str, name: str):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="outline-vpn-api",
version="4.1.0",
version="5.0.0",
packages=["outline_vpn"],
url="https://github.com/jadolg/outline-vpn-api/",
license="MIT",
Expand Down
8 changes: 7 additions & 1 deletion test_outline_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from outline_vpn.outline_vpn import OutlineVPN
from outline_vpn.outline_vpn import OutlineVPN, OutlineLibraryException


@pytest.fixture
Expand All @@ -24,6 +24,12 @@ def client() -> OutlineVPN:
return client


def test_no_cert_sha256_raises_exception():
"""Test that the client raises an exception if the cert sha256 is not provided"""
with pytest.raises(OutlineLibraryException):
OutlineVPN(api_url="https://aaa", cert_sha256="")


def test_get_keys(client: OutlineVPN): # pylint: disable=W0621
"""Test for the get keys method"""
assert len(client.get_keys()) >= 1
Expand Down