sources/ldap: use merger that only appends unique items to list
closes #2211 Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
21efee8f44
commit
bb4be944dc
|
@ -0,0 +1,6 @@
|
||||||
|
"""merge utils"""
|
||||||
|
from deepmerge import Merger
|
||||||
|
|
||||||
|
MERGE_LIST_UNIQUE = Merger(
|
||||||
|
[(list, ["append_unique"]), (dict, ["merge"]), (set, ["union"])], ["override"], ["override"]
|
||||||
|
)
|
|
@ -1,13 +1,13 @@
|
||||||
"""Sync LDAP Users and groups into authentik"""
|
"""Sync LDAP Users and groups into authentik"""
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from deepmerge import always_merger
|
|
||||||
from django.db.models.base import Model
|
from django.db.models.base import Model
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from structlog.stdlib import BoundLogger, get_logger
|
from structlog.stdlib import BoundLogger, get_logger
|
||||||
|
|
||||||
from authentik.core.exceptions import PropertyMappingExpressionException
|
from authentik.core.exceptions import PropertyMappingExpressionException
|
||||||
from authentik.events.models import Event, EventAction
|
from authentik.events.models import Event, EventAction
|
||||||
|
from authentik.lib.merge import MERGE_LIST_UNIQUE
|
||||||
from authentik.sources.ldap.auth import LDAP_DISTINGUISHED_NAME
|
from authentik.sources.ldap.auth import LDAP_DISTINGUISHED_NAME
|
||||||
from authentik.sources.ldap.models import LDAPPropertyMapping, LDAPSource
|
from authentik.sources.ldap.models import LDAPPropertyMapping, LDAPSource
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ class BaseLDAPSynchronizer:
|
||||||
continue
|
continue
|
||||||
setattr(instance, key, value)
|
setattr(instance, key, value)
|
||||||
final_atttributes = {}
|
final_atttributes = {}
|
||||||
always_merger.merge(final_atttributes, instance.attributes)
|
MERGE_LIST_UNIQUE.merge(final_atttributes, instance.attributes)
|
||||||
always_merger.merge(final_atttributes, data.get("attributes", {}))
|
MERGE_LIST_UNIQUE.merge(final_atttributes, data.get("attributes", {}))
|
||||||
instance.attributes = final_atttributes
|
instance.attributes = final_atttributes
|
||||||
instance.save()
|
instance.save()
|
||||||
return (instance, False)
|
return (instance, False)
|
||||||
|
|
Reference in New Issue