Skip to content

Commit

Permalink
Merge pull request #30 from jadolg/deprecate-empty-certificate
Browse files Browse the repository at this point in the history
Deprecate the use of the library without passing a certificate hash
  • Loading branch information
jadolg authored Feb 5, 2024
2 parents 07a89e1 + 35b1080 commit 87bdd3b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
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

0 comments on commit 87bdd3b

Please sign in to comment.