Skip to content

Commit

Permalink
feat: add endpoint for getting the Proxy settings
Browse files Browse the repository at this point in the history
relates-to: #69
  • Loading branch information
SplinterHead committed May 24, 2024
1 parent dbadc74 commit ac795c4
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ dist/

# Test Reports
.coverage
cov/
cov/

boinc_client.log
4 changes: 4 additions & 0 deletions src/boinc_client/boinc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .messages import get_all_notices, message_count, messages, public_notices
from .modes import set_cpu_run_mode, set_gpu_run_mode, set_network_mode
from .network import get_proxy_settings
from .preferences import (
get_global_prefs_file,
get_global_prefs_override,
Expand Down Expand Up @@ -177,3 +178,6 @@ def set_gpu_run_mode(self, run_mode: str, duration: int = 0) -> dict:

def set_network_mode(self, run_mode: str, duration: int = 0) -> dict:
return set_network_mode(self.rpc_client, run_mode, duration)

def get_proxy_settings(self) -> dict:
return get_proxy_settings(self.rpc_client)
1 change: 1 addition & 0 deletions src/boinc_client/messages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

import xmltodict

from boinc_client.clients.rpc_client import RpcClient
from boinc_client.models.message_count import MessageCount
from boinc_client.models.messages import Messages
Expand Down
25 changes: 25 additions & 0 deletions src/boinc_client/models/proxy_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from marshmallow import Schema, fields


class ProxySettings(Schema):
autodetect_port = fields.Str()
autodetect_protocol = fields.Str()
autodetect_server_name = fields.Str()
http_server_name = fields.Str(allow_none=True)
http_server_port = fields.Int(allow_none=True)
http_user_name = fields.Str(allow_none=True)
http_user_passwd = fields.Str(allow_none=True)
no_autodetect = fields.Str(allow_none=True)
no_proxy = fields.Str(allow_none=True)
socks5_remote_dns = fields.Str(allow_none=True)
socks5_user_name = fields.Str(allow_none=True)
socks5_user_passwd = fields.Str(allow_none=True)
socks_server_name = fields.Str(allow_none=True)
socks_server_port = fields.Int(allow_none=True)
use_http_auth = fields.Str()
use_http_proxy = fields.Str()
use_socks_proxy = fields.Str()


class ProxyInfo(Schema):
proxy_info = fields.Nested(ProxySettings())
10 changes: 10 additions & 0 deletions src/boinc_client/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import xmltodict

from boinc_client.clients.rpc_client import RpcClient
from boinc_client.models.proxy_settings import ProxyInfo


def get_proxy_settings(client: RpcClient) -> dict:
rpc_resp = client.make_request("<get_proxy_settings/>")
rpc_json = xmltodict.parse(rpc_resp)
return ProxyInfo().load(rpc_json)
2 changes: 1 addition & 1 deletion src/boinc_client/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from boinc_client.models.global_preferences import GlobalPreferences

logger = logging.getLogger(__name__)
logging.basicConfig(filename='boinc_client.log', encoding='utf-8', level=logging.DEBUG)
logging.basicConfig(filename="boinc_client.log", encoding="utf-8", level=logging.DEBUG)


def get_global_prefs_file(client: RpcClient) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_boinc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_can_sequentially_set_global_overrides(boinc_test_client, project_weak_k


@mark.authenticated
def test_can_set_compute_modes(boinc_test_client, project_weak_key):
def test_can_set_compute_modes(boinc_test_client):
assert boinc_test_client.set_cpu_run_mode("always", 60) == {"success": True}
assert boinc_test_client.set_gpu_run_mode("auto", 0) == {"success": True}
assert boinc_test_client.set_network_mode("never") == {"success": True}
Empty file added tests/network/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions tests/network/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pytest import fixture


@fixture
def proxy_settings_xml() -> str:
return """<proxy_info>
<socks_server_name>foo</socks_server_name>
<socks_server_port>foo</socks_server_port>
<http_server_name>foo</http_server_name>
<http_server_port>foo</http_server_port>
<socks5_user_name>foo</socks5_user_name>
<socks5_user_passwd>foo</socks5_user_passwd>
<socks5_remote_dns>foo</socks5_remote_dns>
<http_user_name>foo</http_user_name>
<http_user_passwd>foo</http_user_passwd>
<no_autodetect>foo</no_autodetect>
<no_proxy>foo</no_proxy>
</proxy_info>"""


@fixture
def proxy_settings_dict() -> dict:
return {
"proxy_info": {
"socks_server_name": "foo",
"socks_server_port": "foo",
"http_server_name": "foo",
"http_server_port": "foo",
"socks5_user_name": "foo",
"socks5_user_passwd": "foo",
"socks5_remote_dns": "foo",
"http_user_name": "foo",
"http_user_passwd": "foo",
"no_autodetect": "foo",
"no_proxy": "foo",
}
}
12 changes: 12 additions & 0 deletions tests/network/test_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from boinc_client.network import get_proxy_settings


def test_can_get_proxy_settings(
mocker, mock_rpc_client, proxy_settings_xml, proxy_settings_dict
):
mocker.patch(
"boinc_client.clients.rpc_client.RpcClient.make_request",
return_value=proxy_settings_xml,
)
assert get_proxy_settings(client=mock_rpc_client) == proxy_settings_dict
assert True

0 comments on commit ac795c4

Please sign in to comment.