diff options
author | 2024-07-26 19:45:24 +0100 | |
---|---|---|
committer | 2024-07-26 19:45:24 +0100 | |
commit | de325b60eb8dfcba5baffd6fe9c6dc6c022c1cf4 (patch) | |
tree | fcc6404fda4e5ce426a573958e668c8134f308ee | |
parent | Expose a BONSAI_AVAILABLE flag from modules that depend on Bonsai (diff) |
Confirm that LDAP is enabled and Bonsai is available on LDAP cogs load
-rw-r--r-- | arthur/exts/directory/ldap.py | 8 | ||||
-rw-r--r-- | arthur/exts/grafana/ldap_team_sync.py | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/arthur/exts/directory/ldap.py b/arthur/exts/directory/ldap.py index 1960fb8..4c63a11 100644 --- a/arthur/exts/directory/ldap.py +++ b/arthur/exts/directory/ldap.py @@ -423,4 +423,10 @@ class LDAP(commands.Cog): async def setup(bot: KingArthur) -> None: """Add the extension to the bot.""" - await bot.add_cog(LDAP(bot)) + if ldap.BONSAI_AVAILABLE and freeipa.BONSAI_AVAILABLE and CONFIG.enable_ldap: + await bot.add_cog(LDAP(bot)) + else: + logger.warning( + "Not loading LDAP sync utilities as LDAP dependencies are not available " + "or LDAP is disabled by config, see README.md for more." + ) diff --git a/arthur/exts/grafana/ldap_team_sync.py b/arthur/exts/grafana/ldap_team_sync.py index 8ef32de..9c18a16 100644 --- a/arthur/exts/grafana/ldap_team_sync.py +++ b/arthur/exts/grafana/ldap_team_sync.py @@ -5,6 +5,7 @@ from discord.ext import commands, tasks from arthur.apis import grafana from arthur.apis.directory import ldap from arthur.bot import KingArthur +from arthur.config import CONFIG from arthur.log import logger from . import MissingMembers, SyncFigures @@ -166,4 +167,11 @@ class GrafanaLDAPTeamSync(commands.Cog): async def setup(bot: KingArthur) -> None: """Add cog to bot.""" - await bot.add_cog(GrafanaLDAPTeamSync(bot)) + if ldap.BONSAI_AVAILABLE and CONFIG.enable_ldap: + await bot.add_cog(GrafanaLDAPTeamSync(bot)) + else: + logger.warning( + "Not loading Grafana LDAP team sync as LDAP dependencies " + "LDAP dependencies are not installed or LDAP is disabled," + " see README.md for more" + ) |