From cd5525013171307a1054613e58d83a45ebd0c7e4 Mon Sep 17 00:00:00 2001 From: Piotr Slupski Date: Mon, 31 Mar 2025 16:39:57 +0200 Subject: [PATCH 1/5] Add getconfigsetting support --- filecloudapi/datastructures.py | 53 ++++++++++++++++++++++++++++++++++ filecloudapi/fcserver.py | 29 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/filecloudapi/datastructures.py b/filecloudapi/datastructures.py index daa20a4..8ca6e46 100644 --- a/filecloudapi/datastructures.py +++ b/filecloudapi/datastructures.py @@ -278,6 +278,59 @@ def _set_entries(self, response: Element): self.entries.append(an_entry) +class PolicyList: + """Convienience class represents policy list""" + + entries: list[PolicyEntry] = [] + + def first(self) -> PolicyEntry | None: + if len(self.entries) >= 1: + return self.entries[0] + return None + + def __iter__(self): + return iter(self.entries) + + def __init__(self, a_response: Element): + """""" + self._set_entries(response=a_response) + + def _set_entries(self, response: Element): + a_list = list(response) + + for elem in a_list: + if elem.tag != "policy": + continue + + an_entry = PolicyEntry( + policyid=list(elem)[0].text, # type:ignore + policyname=list(elem)[1].text, # type:ignore + ) + self.entries.append(an_entry) + + +class ServerSettings: + """Convienience class represents server settings""" + + entries: dict = {} + + def __iter__(self): + return iter(self.entries) + + def __init__(self, a_response: Element): + """""" + self._set_entries(response=a_response) + + def _set_entries(self, response: Element): + a_list = list(response) + + for elem in a_list: + if elem.tag != "setting": + continue + + self.entries[elem.get("param")] = elem.get("value") + + @dataclass class StorageRootDetails: type: str diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 4141454..7406a42 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -40,6 +40,7 @@ SyncFolder, TeamFolderInfo, UserStatus, + ServerSettings, ) from .exceptions import ServerError @@ -1566,6 +1567,34 @@ def admin_resetpolicyforuser(self, username: str) -> None: self._raise_exception_from_command(resp) + def get_config_settings(self, config: list[str]) -> None: + """ + Retrieve Filecloud configuration settings. The config list should + contain FC configuration keys. + Args: + config: Dictionary containing FC config keys and values + """ + try: + count = len(config) + except (ValueError, TypeError): + count = 0 + + config_opts = [] + for i in range(count): + param_key = f"param{i}" + config_opts[param_key] = config[i] + + resp = self._api_call( + "/admin/setconfigsetting", + { + "count": str(len(config_opts)), + **{f"param{i}": value for i, value in enumerate(config_opts)}, + }, + ) + + settings = ServerSettings(resp) + return settings + def set_config_setting(self, config_name: str, config_val: str) -> None: """ Sets a server config setting via admin From bb85621274d5d02857d79c7f2ce2d320182f0108 Mon Sep 17 00:00:00 2001 From: Piotr Slupski Date: Tue, 1 Apr 2025 15:19:29 +0200 Subject: [PATCH 2/5] Implement getconfigsettings admin endpoint --- filecloudapi/datastructures.py | 2 +- filecloudapi/fcserver.py | 18 +++++++----------- pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/filecloudapi/datastructures.py b/filecloudapi/datastructures.py index 8ca6e46..0dd9a88 100644 --- a/filecloudapi/datastructures.py +++ b/filecloudapi/datastructures.py @@ -328,7 +328,7 @@ def _set_entries(self, response: Element): if elem.tag != "setting": continue - self.entries[elem.get("param")] = elem.get("value") + self.entries[list(elem)[0].text] = list(elem)[1].text @dataclass diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 0212ee2..54c1a49 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -8,7 +8,7 @@ import xml.etree.ElementTree as ET from io import SEEK_CUR, SEEK_END, SEEK_SET, BufferedReader, BytesIO from pathlib import Path -from typing import Dict, Optional, Union +from typing import Dict, Optional, Union, List from urllib.parse import urlencode import requests @@ -1661,7 +1661,7 @@ def admin_resetpolicyforuser(self, username: str) -> None: self._raise_exception_from_command(resp) - def get_config_settings(self, config: list[str]) -> None: + def admin_get_config_settings(self, config: List[str]) -> ServerSettings: """ Retrieve Filecloud configuration settings. The config list should contain FC configuration keys. @@ -1673,18 +1673,14 @@ def get_config_settings(self, config: list[str]) -> None: except (ValueError, TypeError): count = 0 - config_opts = [] + config_opts = {} for i in range(count): param_key = f"param{i}" - config_opts[param_key] = config[i] + config_opts[param_key] = config[i] # type:ignore - resp = self._api_call( - "/admin/getconfigsetting", - { - "count": str(len(config_opts)), - **{f"param{i}": value for i, value in enumerate(config_opts)}, - }, - ) + config_opts["count"] = str(len(config_opts)) + + resp = self._api_call("/admin/getconfigsetting", config_opts) settings = ServerSettings(resp) return settings diff --git a/pyproject.toml b/pyproject.toml index e5173fa..a26ab60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "filecloudapi-python" -version = "0.4.1" +version = "0.4.2" description = "A Python library to connect to a Filecloud server" packages = [{ include = "filecloudapi" }] From 11e9882da78d6e2cfaa72326fd7fb353c1c1fee0 Mon Sep 17 00:00:00 2001 From: Piotr Slupski Date: Tue, 1 Apr 2025 15:22:16 +0200 Subject: [PATCH 3/5] Remove duplicate --- filecloudapi/datastructures.py | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/filecloudapi/datastructures.py b/filecloudapi/datastructures.py index 0dd9a88..ad041b1 100644 --- a/filecloudapi/datastructures.py +++ b/filecloudapi/datastructures.py @@ -278,37 +278,6 @@ def _set_entries(self, response: Element): self.entries.append(an_entry) -class PolicyList: - """Convienience class represents policy list""" - - entries: list[PolicyEntry] = [] - - def first(self) -> PolicyEntry | None: - if len(self.entries) >= 1: - return self.entries[0] - return None - - def __iter__(self): - return iter(self.entries) - - def __init__(self, a_response: Element): - """""" - self._set_entries(response=a_response) - - def _set_entries(self, response: Element): - a_list = list(response) - - for elem in a_list: - if elem.tag != "policy": - continue - - an_entry = PolicyEntry( - policyid=list(elem)[0].text, # type:ignore - policyname=list(elem)[1].text, # type:ignore - ) - self.entries.append(an_entry) - - class ServerSettings: """Convienience class represents server settings""" From 3658d88dd3839f53474ac2ef78cab7f730f97fa6 Mon Sep 17 00:00:00 2001 From: Piotr Slupski Date: Tue, 1 Apr 2025 15:34:26 +0200 Subject: [PATCH 4/5] Formatting --- filecloudapi/fcserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 54c1a49..4052a3b 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -8,7 +8,7 @@ import xml.etree.ElementTree as ET from io import SEEK_CUR, SEEK_END, SEEK_SET, BufferedReader, BytesIO from pathlib import Path -from typing import Dict, Optional, Union, List +from typing import Dict, List, Optional, Union from urllib.parse import urlencode import requests @@ -32,6 +32,7 @@ PolicyList, PolicyUser, RMCClient, + ServerSettings, ShareActivity, SharedType, SortBy, @@ -40,7 +41,6 @@ SyncFolder, TeamFolderInfo, UserStatus, - ServerSettings, ) from .exceptions import ServerError From 432af55c04ded44321fa6cf80e582c35ce10b4d3 Mon Sep 17 00:00:00 2001 From: Piotr Slupski Date: Tue, 1 Apr 2025 15:53:51 +0200 Subject: [PATCH 5/5] Clarifying comment --- filecloudapi/fcserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filecloudapi/fcserver.py b/filecloudapi/fcserver.py index 4052a3b..cb0345e 100644 --- a/filecloudapi/fcserver.py +++ b/filecloudapi/fcserver.py @@ -1666,7 +1666,7 @@ def admin_get_config_settings(self, config: List[str]) -> ServerSettings: Retrieve Filecloud configuration settings. The config list should contain FC configuration keys. Args: - config: Dictionary containing FC config keys and values + config: List containing FC config keys """ try: count = len(config)