Skip to content

Commit d7a15a2

Browse files
committed
LDAP add SPAWNER_USER_STATE option to dynamic_attributes
1 parent b1e9cc6 commit d7a15a2

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ldap_hooks/hooks.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
SPAWNER_SUBMIT_DATA = '1'
1616
LDAP_SEARCH_ATTRIBUTE_QUERY = '2'
17+
SPAWNER_USER_STATE = '3'
1718
DYNAMIC_ATTRIBUTE_METHODS = (SPAWNER_SUBMIT_DATA,
18-
LDAP_SEARCH_ATTRIBUTE_QUERY)
19+
LDAP_SEARCH_ATTRIBUTE_QUERY,
20+
SPAWNER_USER_STATE)
1921

2022
INCREMENT_ATTRIBUTE = '1'
2123
SEARCH_RESULT_OPERATION_ACTIONS = (INCREMENT_ATTRIBUTE,)
@@ -351,15 +353,18 @@ def get_interpolated_dynamic_attributes(logger, sources, dynamic_attributes):
351353
if attr_val == LDAP_SEARCH_ATTRIBUTE_QUERY:
352354
if LDAP_SEARCH_ATTRIBUTE_QUERY in sources \
353355
and sources[LDAP_SEARCH_ATTRIBUTE_QUERY]:
354-
attribute = get_dict_key(sources[LDAP_SEARCH_ATTRIBUTE_QUERY],
355-
attr_key)
356-
val = attribute
356+
val = get_dict_key(sources[LDAP_SEARCH_ATTRIBUTE_QUERY],
357+
attr_key)
357358
if attr_val == SPAWNER_SUBMIT_DATA:
358359
if SPAWNER_SUBMIT_DATA in sources \
359360
and sources[SPAWNER_SUBMIT_DATA]:
360-
attribute = get_dict_key(sources[SPAWNER_SUBMIT_DATA],
361-
attr_key)
362-
val = attribute
361+
val = get_dict_key(sources[SPAWNER_SUBMIT_DATA],
362+
attr_key)
363+
if attr_val == SPAWNER_USER_STATE:
364+
if SPAWNER_USER_STATE in sources \
365+
and sources[SPAWNER_USER_STATE]:
366+
val = get_dict_key(sources[SPAWNER_USER_STATE],
367+
attr_key)
363368
if not val:
364369
logger.error("LDAP - Missing {} in {} which is required for {} in"
365370
" get_interpolated_dynamic_attributes".format(
@@ -572,7 +577,8 @@ def setup_ldap_entry_hook(spawner):
572577
"LDAP - Retrived attributes {}".format(attributes))
573578
# Extract attributes from existing object
574579
sources = {LDAP_SEARCH_ATTRIBUTE_QUERY: attributes,
575-
SPAWNER_SUBMIT_DATA: ldap_dict}
580+
SPAWNER_SUBMIT_DATA: ldap_dict,
581+
SPAWNER_USER_STATE: spawner.user}
576582
spawner.log.debug("LDAP - dynamic_attributes "
577583
"pre interpolated: {}".format(
578584
instance.dynamic_attributes
@@ -652,7 +658,8 @@ def setup_ldap_entry_hook(spawner):
652658
ldap_dict.update(attributes)
653659

654660
# Prepare required dynamic attributes
655-
sources.update({SPAWNER_SUBMIT_DATA: ldap_dict})
661+
sources.update({SPAWNER_SUBMIT_DATA: ldap_dict,
662+
SPAWNER_USER_STATE: spawner.user})
656663
spawner.log.debug("LDAP - Sources state before interpolating with "
657664
" dynamic attributes {}".format(sources))
658665
prepared_dynamic_attributes = get_interpolated_dynamic_attributes(

0 commit comments

Comments
 (0)