diff options
| author | 2024-07-26 15:08:33 +0100 | |
|---|---|---|
| committer | 2024-07-26 18:08:09 +0100 | |
| commit | 1d1ddd295134942321bb72a3308703a6197e642a (patch) | |
| tree | 8122821651666fd4d3b83d302da94ba59eb10003 /arthur | |
| parent | Update Grafana to sync with both GitHub and LDAP (diff) | |
Cache the creation of clients for directory APIs
Diffstat (limited to 'arthur')
| -rw-r--r-- | arthur/apis/directory/freeipa.py | 2 | ||||
| -rw-r--r-- | arthur/apis/directory/keycloak.py | 3 | ||||
| -rw-r--r-- | arthur/apis/directory/ldap.py | 2 | 
3 files changed, 7 insertions, 0 deletions
| diff --git a/arthur/apis/directory/freeipa.py b/arthur/apis/directory/freeipa.py index 4d8daf2..c534a6b 100644 --- a/arthur/apis/directory/freeipa.py +++ b/arthur/apis/directory/freeipa.py @@ -1,5 +1,6 @@  """API utilities for modifying data via FreeIPA.""" +from functools import cache  from secrets import token_urlsafe  from bonsai import LDAPDN @@ -11,6 +12,7 @@ from arthur.constants import LDAP_ROLE_MAPPING  PW_LENGTH = 20 +@cache  def create_client() -> ClientMeta:      """Create a new client and login to FreeIPA."""      username = LDAPDN(CONFIG.ldap_bind_user).rdns[0][0][1] diff --git a/arthur/apis/directory/keycloak.py b/arthur/apis/directory/keycloak.py index 60a76b3..836dfae 100644 --- a/arthur/apis/directory/keycloak.py +++ b/arthur/apis/directory/keycloak.py @@ -1,10 +1,13 @@  """Utilities for interacting with the Keycloak REST API.""" +from functools import cache +  from keycloak import KeycloakAdmin  from arthur.config import CONFIG +@cache  def create_client() -> KeycloakAdmin:      """Create a new client for the Keycloak API."""      return KeycloakAdmin( diff --git a/arthur/apis/directory/ldap.py b/arthur/apis/directory/ldap.py index efb7fb7..a4941af 100644 --- a/arthur/apis/directory/ldap.py +++ b/arthur/apis/directory/ldap.py @@ -1,6 +1,7 @@  """API utilities for fetching data from the LDAP directory."""  from dataclasses import dataclass +from functools import cache  from bonsai import LDAPClient, LDAPDN, LDAPSearchScope @@ -30,6 +31,7 @@ def get_cn(dn: str) -> str:      return parsed.rdns[0][0][1] +@cache  def create_client() -> LDAPClient:      """Create an LDAP client with the configured settings."""      client = LDAPClient(str(CONFIG.ldap_host), tls=True) | 
