Skip to content

Commit

Permalink
Cache the creation of clients for directory APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Jul 26, 2024
1 parent d0b5891 commit 26d151d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arthur/apis/directory/freeipa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""API utilities for modifying data via FreeIPA."""

from functools import cache
from secrets import token_urlsafe

from bonsai import LDAPDN
Expand All @@ -11,6 +12,7 @@
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]
Expand Down
3 changes: 3 additions & 0 deletions arthur/apis/directory/keycloak.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 2 additions & 0 deletions arthur/apis/directory/ldap.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -23,6 +24,7 @@ def prepare_dn(dn: str) -> str:
return f"{dn},{CONFIG.ldap_base_dn}"


@cache
def create_client() -> LDAPClient:
"""Create an LDAP client with the configured settings."""
client = LDAPClient(str(CONFIG.ldap_host), tls=True)
Expand Down

0 comments on commit 26d151d

Please sign in to comment.