aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arthur/config.py10
-rw-r--r--arthur/exts/directory/ldap.py19
2 files changed, 21 insertions, 8 deletions
diff --git a/arthur/config.py b/arthur/config.py
index 4d31103..bed026c 100644
--- a/arthur/config.py
+++ b/arthur/config.py
@@ -36,18 +36,18 @@ class Config(
enable_ldap: bool = False
- ldap_host: pydantic.AnyUrl
+ ldap_host: pydantic.AnyUrl | None = None
ldap_bind_user: str = "uid=kingarthur,cn=users,cn=accounts,dc=box,dc=pydis,dc=wtf"
- ldap_bind_password: pydantic.SecretStr
+ ldap_bind_password: pydantic.SecretStr | None = None
ldap_base_dn: str = "dc=box,dc=pydis,dc=wtf"
- ldap_certificate_location: pydantic.FilePath
+ ldap_certificate_location: pydantic.FilePath | None = None
# Keycloak
- keycloak_address: pydantic.AnyUrl
+ keycloak_address: pydantic.AnyUrl | None = None
keycloak_username: str = "kingarthur"
- keycloak_password: pydantic.SecretStr
+ keycloak_password: pydantic.SecretStr | None = None
keycloak_user_realm: str = "pydis"
diff --git a/arthur/exts/directory/ldap.py b/arthur/exts/directory/ldap.py
index dd2fc6c..70fe1ab 100644
--- a/arthur/exts/directory/ldap.py
+++ b/arthur/exts/directory/ldap.py
@@ -427,10 +427,23 @@ class LDAP(commands.Cog):
async def setup(bot: KingArthur) -> None:
"""Add the extension to the bot."""
- if ldap.BONSAI_AVAILABLE and freeipa.BONSAI_AVAILABLE and CONFIG.enable_ldap:
- await bot.add_cog(LDAP(bot))
- else:
+ if not all(ldap.BONSAI_AVAILABLE, freeipa.BONSAI_AVAILABLE, CONFIG.enable_ldap):
logger.warning(
"Not loading LDAP sync utilities as LDAP dependencies are not available "
"or LDAP is disabled by config, see README.md for more."
)
+ return
+ if not all(
+ CONFIG.ldap_host,
+ CONFIG.ldap_bind_password,
+ CONFIG.ldap_certificate_location,
+ CONFIG.keycloak_address,
+ CONFIG.keycloak_password,
+ ):
+ logger.warning(
+ "Not loading LDAP sync utilities as one or more LDAP environment variables"
+ "are not set, see README.md for more."
+ )
+ return
+
+ await bot.add_cog(LDAP(bot))