Skip to content

Commit

Permalink
add process wide cache for the LDAP base of each host (Bug #54232)
Browse files Browse the repository at this point in the history
  • Loading branch information
dansan committed Dec 9, 2021
1 parent b0e1d20 commit fcf9cdd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

1.0.5 (2021-12-09)
------------------

* Add process wide cache for the LDAP base of each host.

1.0.4 (2021-11-15)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
python_requires=">=3.6",
scripts=["update_openapi_client"],
url="https://github.com/univention/python-udm-rest-api-client",
version="1.0.4",
version="1.0.5",
zip_safe=False,
)
2 changes: 1 addition & 1 deletion udm_rest_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
]
__author__ = """Daniel Troeder"""
__email__ = "troeder@univention.de"
__version__ = "1.0.4"
__version__ = "1.0.5"
11 changes: 7 additions & 4 deletions udm_rest_client/base_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
}
MIN_FOLLOW_REDIRECT_SLEEP_TIME = 1.0
logger = logging.getLogger(__name__)
_ldap_base_cache: Dict[str, str] = {}

ApiModule = TypeVar("ApiModule") # openapi_client_udm.SharesShareApi etc
ApiModel = TypeVar("ApiModel") # openapi_client_udm.SharesShare etc
Expand Down Expand Up @@ -343,11 +344,13 @@ async def dn_regex(self) -> Pattern:
base_dn = await self.base_dn
return re.compile(r"^(\w+=.+)+,{}$".format(re.escape(base_dn)))

@async_cached_property
@async_property
async def base_dn(self) -> str:
url = urljoin(self.openapi_client_config.host + "/", "ldap/base/")
body = await self.get_json(url)
return body["dn"]
if self.openapi_client_config.host not in _ldap_base_cache:
url = urljoin(self.openapi_client_config.host + "/", "ldap/base/")
body = await self.get_json(url)
_ldap_base_cache[self.openapi_client_config.host] = body["dn"]
return _ldap_base_cache[self.openapi_client_config.host]

def openapi_class(self, udm_module_name: str) -> type:
camel_case_name = _camel_case_name(udm_module_name)
Expand Down

0 comments on commit fcf9cdd

Please sign in to comment.