Compare commits
2 commits
41988fc491
...
8c8892bbd4
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c8892bbd4 | |||
| 06769eac62 |
6 changed files with 30 additions and 10 deletions
|
|
@ -29,7 +29,7 @@ class ApplicationVersionController:
|
||||||
if not application_version.is_supported():
|
if not application_version.is_supported():
|
||||||
raise UnsupportedApplicationVersionError('The application version in question is not supported.')
|
raise UnsupportedApplicationVersionError('The application version in question is not supported.')
|
||||||
|
|
||||||
if reinstall is True:
|
if reinstall:
|
||||||
ApplicationVersionController.uninstall(application_version)
|
ApplicationVersionController.uninstall(application_version)
|
||||||
|
|
||||||
if application_version.is_installed():
|
if application_version.is_installed():
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from core.controllers.ClientVersionController import ClientVersionController
|
||||||
from core.controllers.ConfigurationController import ConfigurationController
|
from core.controllers.ConfigurationController import ConfigurationController
|
||||||
from core.controllers.LocationController import LocationController
|
from core.controllers.LocationController import LocationController
|
||||||
from core.controllers.SubscriptionPlanController import SubscriptionPlanController
|
from core.controllers.SubscriptionPlanController import SubscriptionPlanController
|
||||||
from core.observers import ClientObserver
|
from core.observers.ClientObserver import ClientObserver
|
||||||
from core.observers.ConnectionObserver import ConnectionObserver
|
from core.observers.ConnectionObserver import ConnectionObserver
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from collections.abc import Callable
|
||||||
from core.Constants import Constants
|
from core.Constants import Constants
|
||||||
from core.Errors import InvalidSubscriptionError, MissingSubscriptionError, ConnectionUnprotectedError, ConnectionTerminationError, CommandNotFoundError
|
from core.Errors import InvalidSubscriptionError, MissingSubscriptionError, ConnectionUnprotectedError, ConnectionTerminationError, CommandNotFoundError
|
||||||
from core.controllers.ConfigurationController import ConfigurationController
|
from core.controllers.ConfigurationController import ConfigurationController
|
||||||
|
|
@ -10,7 +11,7 @@ from core.models.system.SystemState import SystemState
|
||||||
from core.observers import ConnectionObserver
|
from core.observers import ConnectionObserver
|
||||||
from core.services.WebServiceApiService import WebServiceApiService
|
from core.services.WebServiceApiService import WebServiceApiService
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional, Any
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
|
@ -24,7 +25,7 @@ import time
|
||||||
class ConnectionController:
|
class ConnectionController:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def with_preferred_connection(*args, task: callable, connection_observer: Optional[ConnectionObserver] = None, **kwargs):
|
def with_preferred_connection(*args, task: Callable[..., Any], connection_observer: Optional[ConnectionObserver] = None, **kwargs):
|
||||||
|
|
||||||
connection = ConfigurationController.get_connection()
|
connection = ConfigurationController.get_connection()
|
||||||
|
|
||||||
|
|
@ -34,6 +35,9 @@ class ConnectionController:
|
||||||
elif connection == 'tor':
|
elif connection == 'tor':
|
||||||
return ConnectionController.__with_tor_connection(*args, task=task, connection_observer=connection_observer, **kwargs)
|
return ConnectionController.__with_tor_connection(*args, task=task, connection_observer=connection_observer, **kwargs)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def establish_connection(profile: Union[SessionProfile, SystemProfile], force: bool = False, connection_observer: Optional[ConnectionObserver] = None):
|
def establish_connection(profile: Union[SessionProfile, SystemProfile], force: bool = False, connection_observer: Optional[ConnectionObserver] = None):
|
||||||
|
|
||||||
|
|
@ -110,6 +114,8 @@ class ConnectionController:
|
||||||
else:
|
else:
|
||||||
raise ConnectionError('The connection could not be established.')
|
raise ConnectionError('The connection could not be established.')
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def establish_session_connection(profile: SessionProfile, force: Optional[bool] = False, connection_observer: Optional[ConnectionObserver] = None):
|
def establish_session_connection(profile: SessionProfile, force: Optional[bool] = False, connection_observer: Optional[ConnectionObserver] = None):
|
||||||
|
|
||||||
|
|
@ -360,7 +366,7 @@ class ConnectionController:
|
||||||
network_interface_is_activated = ConnectionController.system_uses_wireguard_interface()
|
network_interface_is_activated = ConnectionController.system_uses_wireguard_interface()
|
||||||
attempt += 1
|
attempt += 1
|
||||||
|
|
||||||
if network_interface_is_activated is False:
|
if not network_interface_is_activated:
|
||||||
raise ConnectionError('The network interface could not be activated.')
|
raise ConnectionError('The network interface could not be activated.')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -375,7 +381,7 @@ class ConnectionController:
|
||||||
return bool(re.search('dev wg', str(process_output)))
|
return bool(re.search('dev wg', str(process_output)))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __with_tor_connection(*args, task: callable, connection_observer: Optional[ConnectionObserver] = None, **kwargs):
|
def __with_tor_connection(*args, task: Callable[..., Any], connection_observer: Optional[ConnectionObserver] = None, **kwargs):
|
||||||
|
|
||||||
session_directory = tempfile.mkdtemp(prefix='hv-')
|
session_directory = tempfile.mkdtemp(prefix='hv-')
|
||||||
port_number = ConnectionController.get_random_available_port_number()
|
port_number = ConnectionController.get_random_available_port_number()
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ _table_definition: str = """
|
||||||
'code' varchar,
|
'code' varchar,
|
||||||
'name' varchar,
|
'name' varchar,
|
||||||
'time_zone' varchar,
|
'time_zone' varchar,
|
||||||
|
'provider_name' varchar,
|
||||||
UNIQUE(code, country_code)
|
UNIQUE(code, country_code)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -33,6 +34,10 @@ class Location(Model):
|
||||||
metadata=config(exclude=Exclude.ALWAYS)
|
metadata=config(exclude=Exclude.ALWAYS)
|
||||||
)
|
)
|
||||||
time_zone: Optional[str] = None
|
time_zone: Optional[str] = None
|
||||||
|
provider_name: Optional[str] = field(
|
||||||
|
default=None,
|
||||||
|
metadata=config(exclude=Exclude.ALWAYS)
|
||||||
|
)
|
||||||
available: Optional[bool] = field(
|
available: Optional[bool] = field(
|
||||||
default=False,
|
default=False,
|
||||||
metadata=config(exclude=Exclude.ALWAYS)
|
metadata=config(exclude=Exclude.ALWAYS)
|
||||||
|
|
@ -71,7 +76,7 @@ class Location(Model):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def save_many(locations):
|
def save_many(locations):
|
||||||
Model._create_table_if_not_exists(table_name=_table_name, table_definition=_table_definition)
|
Model._create_table_if_not_exists(table_name=_table_name, table_definition=_table_definition)
|
||||||
Model._insert_many('INSERT INTO locations VALUES(?, ?, ?, ?, ?, ?)', Location.tuple_factory, locations)
|
Model._insert_many('INSERT INTO locations VALUES(?, ?, ?, ?, ?, ?, ?)', Location.tuple_factory, locations)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def factory(cursor, row):
|
def factory(cursor, row):
|
||||||
|
|
@ -80,4 +85,4 @@ class Location(Model):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def tuple_factory(location):
|
def tuple_factory(location):
|
||||||
return location.id, location.country_code, location.country_name, location.code, location.name, location.time_zone
|
return location.id, location.country_code, location.country_name, location.code, location.name, location.time_zone, location.provider_name
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from core.models.invoice import PaymentMethod
|
from core.models.invoice.PaymentMethod import PaymentMethod
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class WebServiceApiService:
|
||||||
|
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
for location in response.json()['data']:
|
for location in response.json()['data']:
|
||||||
locations.append(Location(location['country']['code'], location['code'], location['id'], location['country']['name'], location['name'], location['time_zone']['code']))
|
locations.append(Location(location['country']['code'], location['code'], location['id'], location['country']['name'], location['name'], location['time_zone']['code'], location['provider']['name']))
|
||||||
|
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
|
|
@ -86,6 +86,9 @@ class WebServiceApiService:
|
||||||
if response.status_code == requests.codes.created:
|
if response.status_code == requests.codes.created:
|
||||||
return Subscription(response.headers['X-Billing-Code'])
|
return Subscription(response.headers['X-Billing-Code'])
|
||||||
|
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_subscription(billing_code: str, proxies: Optional[dict] = None):
|
def get_subscription(billing_code: str, proxies: Optional[dict] = None):
|
||||||
|
|
||||||
|
|
@ -100,6 +103,9 @@ class WebServiceApiService:
|
||||||
subscription = response.json()['data']
|
subscription = response.json()['data']
|
||||||
return Subscription(billing_code, Subscription.from_iso_format(subscription['expires_at']))
|
return Subscription(billing_code, Subscription.from_iso_format(subscription['expires_at']))
|
||||||
|
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_invoice(billing_code: str, proxies: Optional[dict] = None):
|
def get_invoice(billing_code: str, proxies: Optional[dict] = None):
|
||||||
|
|
||||||
|
|
@ -121,6 +127,9 @@ class WebServiceApiService:
|
||||||
|
|
||||||
return Invoice(billing_code, invoice['status'], invoice['expires_at'], tuple[PaymentMethod](payment_methods))
|
return Invoice(billing_code, invoice['status'], invoice['expires_at'], tuple[PaymentMethod](payment_methods))
|
||||||
|
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_proxy_configuration(billing_code: str, proxies: Optional[dict] = None):
|
def get_proxy_configuration(billing_code: str, proxies: Optional[dict] = None):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue