sources/ldap: improve error handling during sync
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
53b9e5b93f
commit
ce98255607
|
@ -1,9 +1,11 @@
|
||||||
"""Sync LDAP Users and groups into authentik"""
|
"""Sync LDAP Users and groups into authentik"""
|
||||||
import ldap3
|
import ldap3
|
||||||
import ldap3.core.exceptions
|
import ldap3.core.exceptions
|
||||||
|
from django.core.exceptions import FieldError
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
from authentik.core.models import Group
|
from authentik.core.models import Group
|
||||||
|
from authentik.events.models import Event, EventAction
|
||||||
from authentik.sources.ldap.sync.base import LDAP_UNIQUENESS, BaseLDAPSynchronizer
|
from authentik.sources.ldap.sync.base import LDAP_UNIQUENESS, BaseLDAPSynchronizer
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,14 +49,17 @@ class GroupLDAPSynchronizer(BaseLDAPSynchronizer):
|
||||||
"defaults": defaults,
|
"defaults": defaults,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except IntegrityError as exc:
|
except (IntegrityError, FieldError) as exc:
|
||||||
self._logger.warning("Failed to create group", exc=exc)
|
Event.new(
|
||||||
self._logger.warning(
|
EventAction.CONFIGURATION_ERROR,
|
||||||
(
|
message=(
|
||||||
"To merge new group with existing group, set the group's "
|
f"Failed to create group: {str(exc)} "
|
||||||
|
"To merge new group with existing group, set the groups's "
|
||||||
f"Attribute '{LDAP_UNIQUENESS}' to '{uniq}'"
|
f"Attribute '{LDAP_UNIQUENESS}' to '{uniq}'"
|
||||||
)
|
),
|
||||||
)
|
source=self._source,
|
||||||
|
dn=group_dn,
|
||||||
|
).save()
|
||||||
else:
|
else:
|
||||||
self._logger.debug("Synced group", group=ak_group.name, created=created)
|
self._logger.debug("Synced group", group=ak_group.name, created=created)
|
||||||
group_count += 1
|
group_count += 1
|
||||||
|
|
|
@ -3,6 +3,7 @@ from datetime import datetime
|
||||||
|
|
||||||
import ldap3
|
import ldap3
|
||||||
import ldap3.core.exceptions
|
import ldap3.core.exceptions
|
||||||
|
from django.core.exceptions import FieldError
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
from pytz import UTC
|
from pytz import UTC
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ class UserLDAPSynchronizer(BaseLDAPSynchronizer):
|
||||||
"defaults": defaults,
|
"defaults": defaults,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except IntegrityError as exc:
|
except (IntegrityError, FieldError) as exc:
|
||||||
Event.new(
|
Event.new(
|
||||||
EventAction.CONFIGURATION_ERROR,
|
EventAction.CONFIGURATION_ERROR,
|
||||||
message=(
|
message=(
|
||||||
|
|
Reference in New Issue