Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License.
This class does very little error checking, and knows nothing about ldap class definitions. It implements the minimum emulation of the python ldap library to work with nova.
"""
ldap.SCOPE_BASE: 'SCOPE_BASE', ldap.SCOPE_ONELEVEL: 'SCOPE_ONELEVEL', ldap.SCOPE_SUBTREE: 'SCOPE_SUBTREE', }
#Only enable a lower level than WARN if you are actively debugging
"""Match an ldap query to an attribute dictionary.
The characters &, |, and ! are supported in the query. No syntax checking is performed, so malformed queries will not work correctly. """ # cut off the parentheses # cut off the & or | # cut off the ! and the nested parentheses return not _match_query(query[2:-1], attrs)
"""Split a string into parenthesized groups."""
"""Match a given key and value against an attribute list.""" # This is a wild card search. Implemented as all or nothing for now. return True # for serviceId, the backend is returning a list of numbers # make sure we convert them to strings first before comparing # them str_sids = [str(x) for x in attrs[key]] return str(value) in str_sids # it is an objectclass check, so check subclasses values = _subs(value) for v in values: if v in attrs[key]: return True return False
"""Returns a list of subclass strings.
The strings represent the ldap objectclass plus any subclasses that inherit from it. Fakeldap doesn't know about the ldap object structure, so subclasses need to be defined manually in the dictionary below.
""" subs = {'groupOfNames': ['keystoneTenant', 'keystoneRole', 'keystoneTenantRole']} if value in subs: return [value] + subs[value] return [value]
def get_instance(cls):
"""Fake LDAP connection."""
else: self.db = shelve.open(url[7:])
"""This method is ignored, but provided for compatibility.""" raise ldap.SERVER_DOWN
except KeyError: LOG.debug(_('FakeLdap bind fail: dn=%s not found'), dn) raise ldap.NO_SUCH_OBJECT
except (KeyError, IndexError): LOG.debug(_('FakeLdap bind fail: password for dn=%s not found'), dn) raise ldap.INAPPROPRIATE_AUTH
' not match') % dn)
"""This method is ignored, but provided for compatibility.""" if server_fail: raise ldap.SERVER_DOWN
"""Add an object with the specified attributes at dn.""" raise ldap.SERVER_DOWN
'dn': dn, 'attrs': attrs}) LOG.debug(_('FakeLdap add item failed: dn=%s is' ' already in store.'), dn) raise ldap.ALREADY_EXISTS(dn)
for k, v in attrs])
"""Remove the ldap object at specified dn.""" raise ldap.SERVER_DOWN
"""Remove the ldap object at specified dn.""" if server_fail: raise ldap.SERVER_DOWN
key = '%s%s' % (self.__prefix, dn) LOG.debug(_('FakeLdap delete item: dn=%s'), dn) try: del self.db[key] except KeyError: LOG.debug(_('FakeLdap delete item failed: dn=%s not found.'), dn) raise ldap.NO_SUCH_OBJECT self.db.sync()
"""Modify the object at dn using the attribute list.
:param dn: an LDAP DN :param attrs: a list of tuples in the following form: ([MOD_ADD | MOD_DELETE | MOD_REPACE], attribute, value) """ raise ldap.SERVER_DOWN
'dn': dn, 'attrs': attrs})
else: if len(values) == 0: LOG.debug(_('FakeLdap modify item failed: ' 'item has no attribute "%s" to delete'), k) raise ldap.NO_SUCH_ATTRIBUTE values[:] = [] else: 'item has no attribute "%(k)s" with ' 'value "%(v)s" to delete') % { 'k': k, 'v': val}) else: LOG.debug(_('FakeLdap modify item failed: unknown' ' command %s'), cmd) raise NotImplementedError(_('modify_s action %s not' ' implemented') % cmd)
"""Search for all matching objects under dn using the query.
Args: dn -- dn to search under scope -- only SCOPE_BASE and SCOPE_SUBTREE are supported query -- query to filter objects by fields -- fields to return. Returns all fields if not specified
""" raise ldap.SERVER_DOWN
_('FakeLdap search at dn=%(dn)s scope=%(scope)s query=%(query)s') % {'dn': dn, 'scope': SCOPE_NAMES.get(scope, scope), 'query': query}) ' SCOPE_BASE')) for k, v in self.db.iteritems() if re.match('%s.*,%s' % (self.__prefix, dn), k)] for k, v in self.db.iteritems() if re.match('%s\w+=[^,]+,%s' % (self.__prefix, dn), k)] else: LOG.debug('FakeLdap search fail: unknown scope %s', scope) raise NotImplementedError(_('Search scope %s not implemented.') % scope)
# filter the objects by query # filter the attributes by fields if not fields or k in fields])
|