def configure(self, main_config): """Implementation of IConfigurable.configure""" # Setup our models model_setup() # Our own config schema, defines required items, default values and transform functions schema = { 'ckanext.ldap.uri': {'required': True}, 'ckanext.ldap.base_dn': {'required': True}, 'ckanext.ldap.search.filter': {'required': True}, 'ckanext.ldap.username': {'required': True}, 'ckanext.ldap.email': {'required': True}, 'ckanext.ldap.auth.dn': {}, 'ckanext.ldap.auth.password': {'required_if': 'ckanext.ldap.auth.dn'}, 'ckanext.ldap.auth.method': {'default': 'SIMPLE', 'validate': _allowed_auth_methods}, 'ckanext.ldap.auth.mechanism': {'default': 'DIGEST-MD5', 'validate': _allowed_auth_mechanisms}, 'ckanext.ldap.search.alt': {}, 'ckanext.ldap.search.alt_msg': {'required_if': 'ckanext.ldap.search.alt'}, 'ckanext.ldap.fullname': {}, 'ckanext.ldap.organization.id': {}, 'ckanext.ldap.organization.role': {'default': 'member', 'validate': _allowed_roles}, 'ckanext.ldap.ckan_fallback': {'default': False, 'parse': p.toolkit.asbool}, 'ckanext.ldap.prevent_edits': {'default': False, 'parse': p.toolkit.asbool}, 'ckanext.ldap.migrate': {'default': False, 'parse': p.toolkit.asbool}, 'ckanext.ldap.debug_level': {'default': 0, 'parse': p.toolkit.asint}, 'ckanext.ldap.trace_level': {'default': 0, 'parse': p.toolkit.asint}, } errors = [] for i in schema: v = None if i in main_config: v = main_config[i] elif i.replace('ckanext.', '') in main_config: log.warning('LDAP configuration options should be prefixed with \'ckanext.\'. ' + 'Please update {0} to {1}'.format(i.replace('ckanext.', ''), i)) # Support ldap.* options for backwards compatibility main_config[i] = main_config[i.replace('ckanext.', '')] v = main_config[i] if v: if 'parse' in schema[i]: v = (schema[i]['parse'])(v) try: if 'validate' in schema[i]: (schema[i]['validate'])(v) config[i] = v except ConfigError as e: errors.append(str(e)) elif schema[i].get('required', False): errors.append('Configuration parameter {} is required'.format(i)) elif schema[i].get('required_if', False) and schema[i]['required_if'] in config: errors.append('Configuration parameter {} is required when {} is presnt'.format(i, schema[i]['required_if'])) elif 'default' in schema[i]: config[i] = schema[i]['default'] if len(errors): raise ConfigError("\n".join(errors)) # make sure all the strings in the config are unicode formatted for key, value in config.iteritems(): if isinstance(value, str): config[key] = unicode(value, encoding='utf-8')
def configure(self, main_config): """Implementation of IConfigurable.configure""" # Setup our models model_setup() # Our own config schema, defines required items, default values and transform functions schema = { 'ckanext.ldap.uri': {'required': True}, 'ckanext.ldap.base_dn': {'required': True}, 'ckanext.ldap.search.filter': {'required': True}, 'ckanext.ldap.username': {'required': True}, 'ckanext.ldap.email': {'required': True}, 'ckanext.ldap.auth.dn': {}, 'ckanext.ldap.auth.password': {'required_if': 'ckanext.ldap.auth.dn'}, 'ckanext.ldap.auth.method': {'default': 'SIMPLE', 'validate': _allowed_auth_methods}, 'ckanext.ldap.auth.mechanism': {'default': 'DIGEST-MD5', 'validate': _allowed_auth_mechanisms}, 'ckanext.ldap.search.alt': {}, 'ckanext.ldap.search.alt_msg': {'required_if': 'ckanext.ldap.search.alt'}, 'ckanext.ldap.fullname': {}, 'ckanext.ldap.organization.id': {}, 'ckanext.ldap.organization.role': {'default': 'member', 'validate': _allowed_roles}, 'ckanext.ldap.ckan_fallback': {'default': False, 'parse': p.toolkit.asbool}, 'ckanext.ldap.prevent_edits': {'default': False, 'parse': p.toolkit.asbool}, 'ckanext.ldap.migrate': {'default': False, 'parse': p.toolkit.asbool}, 'ckanext.ldap.debug_level': {'default': '0','parse': p.toolkit.asint}, 'ckanext.ldap.trace_level': {'default': '0','parse': p.toolkit.asint} } errors = [] for i in schema: v = None if i in main_config: v = main_config[i] elif i.replace('ckanext.', '') in main_config: log.warning('LDAP configuration options should be prefixed with \'ckanext.\'. ' + 'Please update {0} to {1}'.format(i.replace('ckanext.', ''), i)) # Support ldap.* options for backwards compatibility main_config[i] = main_config[i.replace('ckanext.', '')] v = main_config[i] if v: if 'parse' in schema[i]: v = (schema[i]['parse'])(v) try: if 'validate' in schema[i]: (schema[i]['validate'])(v) config[i] = v except ConfigError as e: errors.append(str(e)) elif schema[i].get('required', False): errors.append('Configuration parameter {} is required'.format(i)) elif schema[i].get('required_if', False) and schema[i]['required_if'] in config: errors.append('Configuration parameter {} is required when {} is presnt'.format(i, schema[i]['required_if'])) elif 'default' in schema[i]: config[i] = schema[i]['default'] if len(errors): raise ConfigError("\n".join(errors)) # make sure all the strings in the config are unicode formatted for key, value in config.iteritems(): if isinstance(value, str): config[key] = unicode(value, encoding='utf-8')
def configure(self, main_config): """Implementation of IConfigurable.configure""" # Setup our models model_setup() # Our own config schema, defines required items, default values and transform functions schema = { 'ldap.uri': {'required': True}, 'ldap.base_dn': {'required': True}, 'ldap.search.filter': {'required': True}, 'ldap.username': {'required': True}, 'ldap.email': {'required': True}, 'ldap.auth.dn': {}, 'ldap.auth.password': {'required_if': 'ldap.auth.dn'}, 'ldap.search.alt': {}, 'ldap.search.alt_msg': {'required_if': 'ldap.search.alt'}, 'ldap.fullname': {}, 'ldap.organization.id': {}, 'ldap.organization.role': {'default': 'member', 'validate': _allowed_roles}, 'ldap.ckan_fallback': {'default': False, 'parse': p.toolkit.asbool}, 'ldap.prevent_edits': {'default': False, 'parse': p.toolkit.asbool} } errors = [] for i in schema: if i in main_config: v = main_config[i] if 'parse' in schema[i]: v = (schema[i]['parse'])(v) try: if 'validate' in schema[i]: (schema[i]['validate'])(v) config[i] = v except ConfigError as e: errors.append(str(e)) elif schema[i].get('required', False): errors.append('Configuration parameter {} is required'.format(i)) elif schema[i].get('required_if', False) and schema[i]['required_if'] in config: errors.append('Configuration parameter {} is required when {} is presnt'.format(i, schema[i]['required_if'])) elif 'default' in schema[i]: config[i] = schema[i]['default'] if len(errors): raise ConfigError("\n".join(errors))
def configure(self, main_config): """Implementation of IConfigurable.configure""" # Setup our models model_setup() # Our own config schema, defines required items, default values and transform functions schema = { 'ldap.uri': { 'required': True }, 'ldap.base_dn': { 'required': True }, 'ldap.search.filter': { 'required': True }, 'ldap.username': { 'required': True }, 'ldap.email': { 'required': True }, 'ldap.auth.dn': {}, 'ldap.auth.password': { 'required_if': 'ldap.auth.dn' }, 'ldap.search.alt': {}, 'ldap.search.alt_msg': { 'required_if': 'ldap.search.alt' }, 'ldap.fullname': {}, 'ldap.organization.id': {}, 'ldap.organization.role': { 'default': 'member', 'validate': _allowed_roles }, 'ldap.ckan_fallback': { 'default': False, 'parse': p.toolkit.asbool }, 'ldap.prevent_edits': { 'default': False, 'parse': p.toolkit.asbool } } errors = [] for i in schema: if i in main_config: v = main_config[i] if 'parse' in schema[i]: v = (schema[i]['parse'])(v) try: if 'validate' in schema[i]: (schema[i]['validate'])(v) config[i] = v except ConfigError as e: errors.append(str(e)) elif schema[i].get('required', False): errors.append( 'Configuration parameter {} is required'.format(i)) elif schema[i].get('required_if', False) and schema[i]['required_if'] in config: errors.append( 'Configuration parameter {} is required when {} is presnt'. format(i, schema[i]['required_if'])) elif 'default' in schema[i]: config[i] = schema[i]['default'] if len(errors): raise ConfigError("\n".join(errors))
def configure(self, config): '''Implementation of IConfigurable.configure :param config: ''' # Setup our models model_setup() # Our own config schema, defines required items, default values and # transform functions schema = { u'ckanext.ldap.uri': { u'required': True }, u'ckanext.ldap.base_dn': { u'required': True }, u'ckanext.ldap.search.filter': { u'required': True }, u'ckanext.ldap.username': { u'required': True }, u'ckanext.ldap.email': { u'required': True }, u'ckanext.ldap.auth.dn': {}, u'ckanext.ldap.auth.password': { u'required_if': u'ckanext.ldap.auth.dn' }, u'ckanext.ldap.auth.method': { u'default': u'SIMPLE', u'validate': _allowed_auth_methods }, u'ckanext.ldap.auth.mechanism': { u'default': u'DIGEST-MD5', u'validate': _allowed_auth_mechanisms }, u'ckanext.ldap.search.alt': {}, u'ckanext.ldap.search.alt_msg': { u'required_if': u'ckanext.ldap.search.alt' }, u'ckanext.ldap.fullname': {}, u'ckanext.ldap.organization.id': {}, u'ckanext.ldap.organization.role': { u'default': u'member', u'validate': _allowed_roles }, u'ckanext.ldap.ckan_fallback': { u'default': False, u'parse': toolkit.asbool }, u'ckanext.ldap.prevent_edits': { u'default': False, u'parse': toolkit.asbool }, u'ckanext.ldap.migrate': { u'default': False, u'parse': toolkit.asbool }, u'ckanext.ldap.debug_level': { u'default': 0, u'parse': toolkit.asint }, u'ckanext.ldap.trace_level': { u'default': 0, u'parse': toolkit.asint }, } errors = [] for key, options in schema.items(): config_value = config.get(key, None) if config_value: if u'parse' in options: config_value = (options[u'parse'])(config_value) try: if u'validate' in options: (options[u'validate'])(config_value) toolkit.config[key] = config_value except ConfigError as e: errors.append(str(e)) elif options.get(u'required', False): errors.append( u'Configuration parameter {0} is required'.format(key)) elif u'required_if' in options and options[ u'required_if'] in toolkit.config: errors.append(u'Configuration parameter {0} is required ' u'when {1} is present'.format( key, options[u'required_if'])) elif u'default' in options: toolkit.config[key] = options[u'default'] # make sure the config options are all unicode for LDAP if isinstance(toolkit.config.get(key, None), str): toolkit.config[key] = unicode(toolkit.config.get(key)) if len(errors): raise ConfigError(u'\n'.join(errors))