Skip to content

Commit

Permalink
Allow loading the bot without LDAP env vars set
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Aug 19, 2024
1 parent e429c8b commit c63b74b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 5 additions & 5 deletions arthur/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
19 changes: 16 additions & 3 deletions arthur/exts/directory/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,23 @@ async def sync(self, ctx: commands.Context) -> None:

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))

0 comments on commit c63b74b

Please sign in to comment.