Skip to content

Commit e7079c2

Browse files
authored
Merge pull request #32 from adobe-apiplatform/revert-31-morr-cxmap
Revert "Complex Mapping feature (LIGHTLY TESTED, NEEDS REVIEW)"
2 parents b0fa845 + 4fee512 commit e7079c2

5 files changed

Lines changed: 36 additions & 199 deletions

File tree

user_sync/config.py

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,15 @@ def get_directory_groups(self):
198198

199199
dashboard_groups_config = item.get_list_config('dashboard_groups')
200200
for dashboard_group in dashboard_groups_config.iter_values(types.StringTypes):
201-
group = self.create_dashboard_group(dashboard_group)
202-
if (group is None):
201+
parts = dashboard_group.split(GROUP_NAME_DELIMITER)
202+
group_name = parts.pop()
203+
organization_name = GROUP_NAME_DELIMITER.join(parts)
204+
if (len(organization_name) == 0):
205+
organization_name = user_sync.rules.OWNING_ORGANIZATION_NAME
206+
if (len(group_name) == 0):
203207
validation_message = 'Bad dashboard group: "%s" in directory group: "%s"' % (dashboard_group, directory_group)
204-
raise user_sync.error.AssertionException(validation_message)
208+
raise user_sync.error.AssertionException(validation_message)
209+
group = user_sync.rules.Group(group_name, organization_name)
205210
groups.append(group)
206211

207212
return adobe_groups_by_directory_group
@@ -307,40 +312,6 @@ def get_rule_options(self):
307312
if (new_account_type == None):
308313
new_account_type = user_sync.identity_type.ENTERPRISE_IDENTITY_TYPE
309314
self.logger.warning("Assuming the identity type for users is: %s", new_account_type)
310-
311-
after_mapping_hook = None
312-
extended_attributes = None
313-
extensions_config = self.main_config.get_list_config('extensions', True)
314-
if (extensions_config != None):
315-
for extension_config in extensions_config.iter_dict_configs():
316-
context = extension_config.get_string('context')
317-
if context == 'per-user':
318-
if (after_mapping_hook == None):
319-
after_mapping_hook_text = extension_config.get_string('after_mapping_hook')
320-
if (after_mapping_hook_text is not None):
321-
after_mapping_hook = compile(after_mapping_hook_text, '<per-user after-mapping-hook>', 'exec')
322-
extended_attributes = extension_config.get_list('extended_attributes')
323-
324-
# [TODO morr 2017-02-27]: Do we really need to pre-create extended dashboard groups here? Or
325-
# could it be done on the fly, when they're encountered in values returned from hook code? If
326-
# the latter, we could do the customer a big favor by not requiring them to be declared in the
327-
# extension config.
328-
#
329-
# This should be revisited once the Complex Mapping feature as a whole is working and has been
330-
# thoroughly tested.
331-
#
332-
for extended_dashboard_group in extension_config.get_list('extended_dashboard_groups'):
333-
group = self.create_dashboard_group(extended_dashboard_group)
334-
if (group is None):
335-
validation_message = 'Bad dashboard group: "%s" in extension with context "%s"' % (extended_dashboard_group, context)
336-
raise user_sync.error.AssertionException(validation_message)
337-
338-
else:
339-
self.logger.warning("No valid hook found in extension with context '%s'; extension ignored")
340-
else:
341-
self.logger.warning("Duplicate extension context '%s' ignored", context)
342-
else:
343-
self.logger.warning("Unrecognized extension context '%s' ignored", context)
344315

345316
options = self.options
346317
result = {
@@ -352,9 +323,7 @@ def get_rule_options(self):
352323
'remove_user_key_list': options['remove_user_key_list'],
353324
'remove_list_output_path': options['remove_list_output_path'],
354325
'remove_nonexistent_users': options['remove_nonexistent_users'],
355-
'default_country_code': default_country_code,
356-
'after_mapping_hook': after_mapping_hook,
357-
'extended_attributes': extended_attributes
326+
'default_country_code': default_country_code
358327
}
359328
return result
360329

@@ -369,23 +338,7 @@ def create_dashboard_options(self, connector_config_sources, owner):
369338
connector_config['enterprise'] = new_enterprise_section
370339

371340
return connector_config
372-
373-
def create_dashboard_group(self, dashboard_group_qualified_name):
374-
parts = dashboard_group_qualified_name.split(GROUP_NAME_DELIMITER)
375-
group_name = parts.pop()
376-
organization_name = GROUP_NAME_DELIMITER.join(parts)
377-
if (len(organization_name) == 0):
378-
organization_name = user_sync.rules.OWNING_ORGANIZATION_NAME
379-
380-
group = None
381-
if (len(group_name) > 0):
382-
# check for existing group in case someone mistakenly declared an extended group that's already a mapping target
383-
group = user_sync.rules.get_dashboard_group(group_name, organization_name)
384-
if group is None:
385-
group = user_sync.rules.Group(group_name, organization_name)
386-
387-
return group
388-
341+
389342
def check_unused_config_keys(self):
390343
directory_connectors_config = self.get_directory_connector_configs()
391344
self.main_config.report_unused_values(self.logger, [directory_connectors_config])

user_sync/connector/directory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ def initialize(self, options = {}):
4040
'''
4141
self.state = self.implementation.connector_initialize(options)
4242

43-
def load_users_and_groups(self, groups, extended_attributes=None):
43+
def load_users_and_groups(self, groups):
4444
'''
4545
:type groups: list(str)
46-
:type extended_attributes: list(str)
4746
:rtype (bool, iterable(dict))
4847
'''
49-
return self.implementation.connector_load_users_and_groups(self.state, groups, extended_attributes)
48+
return self.implementation.connector_load_users_and_groups(self.state, groups)
5049

user_sync/connector/directory_csv.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ def connector_initialize(options):
3737
state = CSVDirectoryConnector(options)
3838
return state
3939

40-
def connector_load_users_and_groups(state, groups, extended_attributes):
40+
def connector_load_users_and_groups(state, groups):
4141
'''
4242
:type state: CSVDirectoryConnector
4343
:type groups: list(str)
44-
:type extended_attributes: list(str)
4544
:rtype (bool, iterable(dict))
4645
'''
47-
48-
# CSV supports arbitrary aka "extended" attrs by default, so the value of extended_attributes has no impact on this particular connector
49-
5046
return state.load_users_and_groups(groups)
5147

5248
class CSVDirectoryConnector(object):

user_sync/connector/directory_ldap.py

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ def connector_initialize(options):
3939
connector = LDAPDirectoryConnector(options)
4040
return connector
4141

42-
def connector_load_users_and_groups(state, groups, extended_attributes):
42+
def connector_load_users_and_groups(state, groups):
4343
'''
4444
:type state: LDAPDirectoryConnector
4545
:type groups: list(str)
46-
:type extended_attributes: list(str)
4746
:rtype (bool, iterable(dict))
4847
'''
49-
return state.load_users_and_groups(groups, extended_attributes)
48+
return state.load_users_and_groups(groups)
5049

5150
class LDAPDirectoryConnector(object):
5251
name = 'ldap'
@@ -104,10 +103,9 @@ def __init__(self, caller_options):
104103
self.connection = connection
105104
logger.info('Connected')
106105

107-
def load_users_and_groups(self, groups, extended_attributes):
106+
def load_users_and_groups(self, groups):
108107
'''
109108
:type groups: list(str)
110-
:type extended_attributes: list(str)
111109
:rtype (bool, iterable(dict))
112110
'''
113111
options = self.options
@@ -127,12 +125,12 @@ def load_users_and_groups(self, groups, extended_attributes):
127125

128126
self.user_by_dn = user_by_dn = {}
129127
self.user_by_uid = user_by_uid = {}
130-
for user_dn, user in self.iter_users(users_filter, extended_attributes):
128+
for user_dn, user in self.iter_users(users_filter):
131129
uid = user.get('uid')
132130
if (uid != None):
133131
user_by_uid[uid] = user
134132
user_by_dn[user_dn] = user
135-
133+
136134
self.logger.info('Total users loaded: %d', len(user_by_dn))
137135

138136
for group in groups:
@@ -252,18 +250,15 @@ def iter_ldap_group_members(self, group):
252250
for attribute_value in attribute_values:
253251
yield (attribute, attribute_value)
254252

255-
def iter_users(self, users_filter, extended_attributes):
253+
def iter_users(self, users_filter):
256254
options = self.options
257255
base_dn = options['base_dn']
258-
259-
user_attribute_names = ["givenName", "sn", "c", "uid"]
256+
257+
user_attribute_names = ["givenName", "sn", "c", "uid"]
260258
user_attribute_names.extend(self.user_email_formatter.get_attribute_names())
261259
user_attribute_names.extend(self.user_username_formatter.get_attribute_names())
262260
user_attribute_names.extend(self.user_domain_formatter.get_attribute_names())
263261

264-
extended_attributes -= user_attribute_names
265-
user_attribute_names.extend(extended_attributes)
266-
267262
result_iter = self.iter_search_result(base_dn, ldap.SCOPE_SUBTREE, users_filter, user_attribute_names)
268263
for dn, record in result_iter:
269264
if (dn == None):
@@ -274,53 +269,35 @@ def iter_users(self, users_filter, extended_attributes):
274269
if (last_attribute_name != None):
275270
self.logger.warn('No email attribute: %s for dn: %s', last_attribute_name, dn)
276271
continue
277-
278-
source_attributes = {}
279272

280273
user = user_sync.connector.helper.create_blank_user()
281-
source_attributes['email'] = email
282274
user['email'] = email
283-
275+
284276
username, last_attribute_name = self.user_username_formatter.generate_value(record)
285-
source_attributes['username'] = username
286277
if (username == None and last_attribute_name != None):
287278
self.logger.info('No username attribute: %s for dn: %s', last_attribute_name, dn)
288279
user['username'] = username if username != None else email
289-
280+
290281
domain, last_attribute_name = self.user_domain_formatter.generate_value(record)
291-
source_attributes['domain'] = domain
292282
if (domain != None):
293283
user['domain'] = domain
294284
elif (last_attribute_name != None):
295285
self.logger.info('No domain attribute: %s for dn: %s', last_attribute_name, dn)
296286

297287
given_name_value = LDAPValueFormatter.get_attribute_value(record, 'givenName')
298-
source_attributes['givenName'] = given_name_value
299-
if (given_name_value != None):
288+
if (given_name_value != None):
300289
user['firstname'] = given_name_value
301290
sn_value = LDAPValueFormatter.get_attribute_value(record, 'sn')
302-
source_attributes['sn'] = sn_value
303291
if sn_value != None:
304292
user['lastname'] = sn_value
305293
c_value = LDAPValueFormatter.get_attribute_value(record, 'c')
306-
source_attributes['c'] = c_value
307294
if c_value != None:
308295
user['country'] = c_value
309-
296+
310297
uid = LDAPValueFormatter.get_attribute_value(record, 'uid')
311-
source_attributes['uid'] = uid
312298
if (uid != None):
313299
user['uid'] = uid
314-
315-
if extended_attributes is not None:
316-
for extended_attribute in extended_attributes:
317-
extended_attribute_value = LDAPValueFormatter.get_attribute_value(record, extended_attribute)
318-
source_attributes[extended_attribute] = extended_attribute_value
319-
320-
# [TODO morr 2017-02-26]: Could be omitted if no hook; worth considering?
321-
# [TODO morr 2017-02-28]: Is the copy necessary? Could just assign I think
322-
user['source_attributes'] = source_attributes.copy()
323-
300+
324301
yield (dn, user)
325302

326303
def iter_search_result(self, base_dn, scope, filter_string, attributes):

0 commit comments

Comments
 (0)