diff options
author | 2024-07-26 19:45:12 +0100 | |
---|---|---|
committer | 2024-07-26 19:45:12 +0100 | |
commit | ffa16cb9575cb6c39b3c957d26a7e4dd0decc838 (patch) | |
tree | 7c7d6987fb62318b1f00759f690515729f4a5edb | |
parent | Add new flag for enabling LDAP functionality (diff) |
Expose a BONSAI_AVAILABLE flag from modules that depend on Bonsai
-rw-r--r-- | arthur/apis/directory/freeipa.py | 8 | ||||
-rw-r--r-- | arthur/apis/directory/ldap.py | 9 |
2 files changed, 14 insertions, 3 deletions
diff --git a/arthur/apis/directory/freeipa.py b/arthur/apis/directory/freeipa.py index c534a6b..9da9d76 100644 --- a/arthur/apis/directory/freeipa.py +++ b/arthur/apis/directory/freeipa.py @@ -3,7 +3,13 @@ from functools import cache from secrets import token_urlsafe -from bonsai import LDAPDN +try: + from bonsai import LDAPDN + + BONSAI_AVAILABLE = True +except ImportError: + BONSAI_AVAILABLE = False + from python_freeipa import ClientMeta from arthur.config import CONFIG diff --git a/arthur/apis/directory/ldap.py b/arthur/apis/directory/ldap.py index a4941af..c919f55 100644 --- a/arthur/apis/directory/ldap.py +++ b/arthur/apis/directory/ldap.py @@ -3,7 +3,12 @@ from dataclasses import dataclass from functools import cache -from bonsai import LDAPClient, LDAPDN, LDAPSearchScope +try: + from bonsai import LDAPClient, LDAPDN, LDAPSearchScope + + BONSAI_AVAILABLE = True +except ImportError: + BONSAI_AVAILABLE = False from arthur.config import CONFIG from arthur.constants import LDAP_ROLE_MAPPING @@ -32,7 +37,7 @@ def get_cn(dn: str) -> str: @cache -def create_client() -> LDAPClient: +def create_client() -> "LDAPClient": """Create an LDAP client with the configured settings.""" client = LDAPClient(str(CONFIG.ldap_host), tls=True) |