Skip to content

Commit 09c6937

Browse files
authored
Merge pull request #146 from adobe-apiplatform/v2
Bring branch up to date
2 parents cc0f166 + 11f48c2 commit 09c6937

File tree

12 files changed

+127
-186
lines changed

12 files changed

+127
-186
lines changed

tests/config_file_test.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import types
2222
import unittest
2323
import os
24+
import os.path
2425
import yaml
2526

2627
import mock
@@ -43,14 +44,17 @@ def assert_eq(self, result, expected, error_message):
4344

4445
@mock.patch('__builtin__.open')
4546
@mock.patch('yaml.load')
46-
def test_load_root_config(self, mock_yaml, mock_open):
47+
@mock.patch('os.path.isfile')
48+
def test_load_root_config(self, mock_isfile, mock_yaml, mock_open):
4749
'''
4850
tests ConfigFileLoader.load_root_config by inputing a root configuration
4951
file path, and asserts that the resulting processed content has the
5052
file references properly updated
53+
:type mock_isfile: Mock
5154
:type mock_yaml: Mock
5255
:type mock_open: Mock
5356
'''
57+
mock_isfile.return_value = True
5458
mocked_open = mock_open('test')
5559
mocked_open_name = '%s.open' % __name__
5660
with patch(mocked_open_name, mocked_open, create=True):
@@ -72,9 +76,7 @@ def test_load_root_config(self, mock_yaml, mock_open):
7276
]
7377
}
7478
}
75-
with mock.patch(os.path.isfile) as m_isfile:
76-
m_isfile.return_value = True
77-
yml = ConfigFileLoader.load_root_config('config-test/user-sync-config-test.yml')
79+
yml = ConfigFileLoader.load_root_config('config-test/user-sync-config-test.yml')
7880

7981
# test path updating
8082
self.assert_eq(yml['logging']['file_log_directory'], os.path.abspath('config-test/log-test-1'),
@@ -92,24 +94,25 @@ def test_load_root_config(self, mock_yaml, mock_open):
9294

9395
@mock.patch('__builtin__.open')
9496
@mock.patch('yaml.load')
95-
def test_load_root_default_config(self, mock_yaml, mock_open):
97+
@mock.patch('os.path.isfile')
98+
def test_load_root_default_config(self, mock_isfile, mock_yaml, mock_open):
9699
'''
97100
tests ConfigFileLoader.load_root_config by inputing a root configuration
98101
file path, and asserts that the resulting processed content has the
99102
file references properly updated
103+
:type mock_isfile: Mock
100104
:type mock_yaml: Mock
101105
:type mock_open: Mock
102106
'''
107+
mock_isfile.return_value = True
103108
mocked_open = mock_open('test')
104109
mocked_open_name = '%s.open' % __name__
105110
with patch(mocked_open_name, mocked_open, create=True):
106111
mock_yaml.return_value = {
107112
'adobe_users': {'connectors': {'umapi': 'test-123'}},
108113
'logging': {'log_to_file': True},
109114
}
110-
with mock.patch(os.path.isfile) as m_isfile:
111-
m_isfile.return_value = True
112-
yml = ConfigFileLoader.load_root_config('config-test-2/user-sync-config-test.yml')
115+
yml = ConfigFileLoader.load_root_config('config-test-2/user-sync-config-test.yml')
113116

114117
# assert default values are preserved
115118
self.assert_eq(yml['logging']['file_log_directory'], os.path.abspath('config-test-2/logs'),
@@ -121,14 +124,17 @@ def test_load_root_default_config(self, mock_yaml, mock_open):
121124

122125
@mock.patch('__builtin__.open')
123126
@mock.patch('yaml.load')
124-
def test_load_sub_config(self, mock_yaml, mock_open):
127+
@mock.patch('os.path.isfile')
128+
def test_load_sub_config(self, mock_isfile, mock_yaml, mock_open):
125129
'''
126130
same purpose as test_load_root_config, but tests against sub
127131
configuration path updates (which is currently only the private key
128132
path in the umapi configuration file)
133+
:type mock_isfile: Mock
129134
:type mock_yaml: Mock
130135
:type mock_open: Mock
131136
'''
137+
mock_isfile.return_value = True
132138
mocked_open = mock_open('test')
133139
mocked_open_name = '%s.open' % __name__
134140
with patch(mocked_open_name, mocked_open, create=True):
@@ -141,9 +147,7 @@ def test_load_sub_config(self, mock_yaml, mock_open):
141147
'test-2': 123
142148
}
143149
}
144-
with mock.patch(os.path.isfile) as m_isfile:
145-
m_isfile.return_value = True
146-
yml = ConfigFileLoader.load_sub_config('sub-config-test/user-sync-config-test.yml')
150+
yml = ConfigFileLoader.load_sub_config('sub-config-test/user-sync-config-test.yml')
147151

148152
# test path updating
149153
self.assert_eq(yml['enterprise']['priv_key_path'], os.path.abspath('keys/test-key.key'),

tests/config_test.py

Lines changed: 0 additions & 89 deletions
This file was deleted.
File renamed without changes.

tests/rules_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def mock_send_commands(commands, callback = None):
194194

195195
action_manager = mock.mock.create_autospec(user_sync.connector.umapi.ActionManager)
196196
action_manager.has_work = lambda: False
197+
action_manager.get_statistics = lambda: (len(commands_list_output), 0)
197198
mock_connector = mock.mock.create_autospec(user_sync.connector.umapi)
198199
mock_connector.iter_users = lambda: list(users_to_return)
199200
mock_connector.send_commands = mock_send_commands

user_sync/app.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,29 @@ def create_config_loader(args):
206206

207207

208208
def create_config_loader_options(args):
209+
'''
210+
This is where all the command-line arguments get set as options in the main config
211+
so that it appears as if they were loaded as part of the main configuration file.
212+
If you add an option that is supposed to be set from the command line here, you
213+
had better make sure you add it to the ones read in get_rule_options.
214+
:param args: the command-line args as parsed
215+
:return: the configured options for the config loader.
216+
'''
209217
config_options = {
210-
'test_mode': args.test_mode,
218+
'delete_strays': False,
219+
'directory_connector_module_name': None,
220+
'directory_connector_overridden_options': None,
221+
'directory_group_filter': None,
222+
'directory_group_mapped': False,
223+
'disentitle_strays': False,
224+
'exclude_strays': False,
211225
'manage_groups': args.manage_groups,
226+
'remove_strays': False,
227+
'stray_list_input_path': None,
228+
'stray_list_output_path': None,
229+
'test_mode': args.test_mode,
212230
'update_user_info': args.update_user_info,
213-
'directory_group_mapped': False,
231+
'username_filter_regex': None,
214232
}
215233

216234
# --users
@@ -256,7 +274,6 @@ def create_config_loader_options(args):
256274
if not adobe_action_args:
257275
raise AssertionException('Missing file path for --adobe-only-user-action %s [file_path]' % adobe_action)
258276
config_options['stray_list_output_path'] = adobe_action_args.pop(0)
259-
logger.info('Writing unmatched users to: %s', config_options['stray_list_output_path'])
260277
elif (adobe_action == 'delete'):
261278
config_options['delete_strays'] = True
262279
elif (adobe_action == 'remove'):
@@ -289,9 +306,9 @@ def log_parameters(args):
289306
'''
290307
logger.info('------- Invocation parameters -------')
291308
logger.info(' '.join(sys.argv))
292-
logger.info('-------- Internal parameters --------')
309+
logger.debug('-------- Internal parameters --------')
293310
for parameter_name, parameter_value in args.__dict__.iteritems():
294-
logger.info(' %s: %s', parameter_name, parameter_value)
311+
logger.debug(' %s: %s', parameter_name, parameter_value)
295312
logger.info('-------------------------------------')
296313

297314

@@ -323,7 +340,7 @@ def main():
323340
finally:
324341
lock.unlock()
325342
else:
326-
logger.info("Process is already locked")
343+
logger.critical("A different User Sync process is currently running.")
327344

328345
except AssertionException as e:
329346
if (not e.is_reported()):

user_sync/config.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def get_directory_connector_configs(self):
127127
directory_config = self.main_config.get_dict_config('directory_users', True)
128128
if directory_config != None:
129129
connectors_config = directory_config.get_dict_config('connectors', True)
130+
# make sure neither ldap nor csv connectors get reported as unused
131+
if connectors_config:
132+
connectors_config.get_list('ldap', True)
133+
connectors_config.get_list('csv', True)
130134
return connectors_config
131135

132136
def get_directory_connector_options(self, connector_name):
@@ -171,8 +175,8 @@ def get_directory_groups(self):
171175
if groups == None:
172176
adobe_groups_by_directory_group[directory_group] = groups = []
173177

174-
adobe_groups_config = item.get_list_config('adobe_groups')
175-
for adobe_group in adobe_groups_config.iter_values(types.StringTypes):
178+
adobe_groups = item.get_list('adobe_groups', True)
179+
for adobe_group in adobe_groups or []:
176180
group = user_sync.rules.AdobeGroup.create(adobe_group)
177181
if group is None:
178182
validation_message = 'Bad adobe group: "%s" in directory group: "%s"' % (adobe_group, directory_group)
@@ -268,17 +272,17 @@ def get_rule_options(self):
268272
default_country_code = directory_config.get_string('default_country_code', True)
269273
if not new_account_type:
270274
new_account_type = user_sync.identity_type.ENTERPRISE_IDENTITY_TYPE
271-
self.logger.info("Using default for new_account_type: %s", new_account_type)
275+
self.logger.debug("Using default for new_account_type: %s", new_account_type)
272276

273277
# process exclusion configuration options
274278
exclude_identity_types = exclude_identity_type_names = []
275279
exclude_users = exclude_users_regexps = []
276280
exclude_groups = exclude_group_names = []
277-
umapi_config = self.main_config.get_dict_config('adobe_users', True)
278-
if umapi_config:
279-
exclude_identity_type_names = umapi_config.get_list('exclude_identity_types', True) or []
280-
exclude_users_regexps = umapi_config.get_list('exclude_users', True) or []
281-
exclude_group_names = umapi_config.get_list('exclude_groups', True) or []
281+
adobe_config = self.main_config.get_dict_config('adobe_users', True)
282+
if adobe_config:
283+
exclude_identity_type_names = adobe_config.get_list('exclude_identity_types', True) or []
284+
exclude_users_regexps = adobe_config.get_list('exclude_users', True) or []
285+
exclude_group_names = adobe_config.get_list('exclude_adobe_groups', True) or []
282286
for name in exclude_identity_type_names:
283287
message_format = 'Illegal value in exclude_identity_types: %s'
284288
identity_type = user_sync.identity_type.parse_identity_type(name, message_format)
@@ -335,6 +339,7 @@ def get_rule_options(self):
335339
'disentitle_strays': options['disentitle_strays'],
336340
'exclude_groups': exclude_groups,
337341
'exclude_identity_types': exclude_identity_types,
342+
'exclude_strays': options['exclude_strays'],
338343
'exclude_users': exclude_users,
339344
'extended_attributes': extended_attributes,
340345
'manage_groups': options['manage_groups'],

user_sync/connector/directory_csv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self, caller_options):
6565
builder.set_string_value('domain_column_name', 'domain')
6666
builder.set_string_value('identity_type_column_name', 'type')
6767
builder.set_string_value('user_identity_type', None)
68-
builder.set_string_value('logger_name', 'connector.' + CSVDirectoryConnector.name)
68+
builder.set_string_value('logger_name', CSVDirectoryConnector.name)
6969
builder.require_string_value('file_path')
7070
options = builder.get_options()
7171

@@ -85,9 +85,9 @@ def load_users_and_groups(self, groups, extended_attributes):
8585
'''
8686
options = self.options
8787
file_path = options['file_path']
88-
self.logger.info('Reading from: %s', file_path)
88+
self.logger.debug('Reading from: %s', file_path)
8989
self.users = users = self.read_users(file_path, extended_attributes)
90-
self.logger.info('Number of users loaded: %d', len(users))
90+
self.logger.debug('Number of users loaded: %d', len(users))
9191
return users.itervalues()
9292

9393
def read_users(self, file_path, extended_attributes):

user_sync/connector/directory_ldap.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, caller_options):
6666
builder.set_string_value('user_domain_format', None)
6767
builder.set_string_value('user_identity_type', None)
6868
builder.set_int_value('search_page_size', 200)
69-
builder.set_string_value('logger_name', 'connector.' + LDAPDirectoryConnector.name)
69+
builder.set_string_value('logger_name', LDAPDirectoryConnector.name)
7070
host = builder.require_string_value('host')
7171
username = builder.require_string_value('username')
7272
builder.require_string_value('base_dn')
@@ -86,18 +86,19 @@ def __init__(self, caller_options):
8686
require_tls_cert = options['require_tls_cert']
8787
logger.debug('Initialized with options: %s', options)
8888

89-
logger.info('Connecting to: %s using username: %s', host, username)
89+
logger.debug('Connecting to: %s using username: %s', host, username)
9090
if not require_tls_cert:
9191
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
92-
connection = ldap.initialize(host)
93-
connection.protocol_version = ldap.VERSION3
94-
connection.set_option(ldap.OPT_REFERRALS, 0)
92+
9593
try:
94+
connection = ldap.initialize(host)
95+
connection.protocol_version = ldap.VERSION3
96+
connection.set_option(ldap.OPT_REFERRALS, 0)
9697
connection.simple_bind_s(username, password)
9798
except Exception as e:
9899
raise user_sync.error.AssertionException(repr(e))
99100
self.connection = connection
100-
logger.info('Connected')
101+
logger.debug('Connected')
101102

102103
def load_users_and_groups(self, groups, extended_attributes):
103104
'''
@@ -116,7 +117,7 @@ def load_users_and_groups(self, groups, extended_attributes):
116117
user_by_uid[uid] = user
117118
user_by_dn[user_dn] = user
118119

119-
self.logger.info('Total users loaded: %d', len(user_by_dn))
120+
self.logger.debug('Total users loaded: %d', len(user_by_dn))
120121

121122
for group in groups:
122123
total_group_members = 0

0 commit comments

Comments
 (0)