Example #1
0
    def exists(self, misc):
        """
        Check whether the given uuid or dn exists
        """

        if is_uuid(misc):
            return bool(self.db.find_one({'_uuid': misc}, {'_uuid': 1}))
        else:
            return bool(self.db.find_one({'dn': misc}, {'_uuid': 1}))
Example #2
0
    def exists(self, misc):
        """
        Check whether the given uuid or dn exists
        """
        json = self.__load()
        if is_uuid(misc):
            return misc in json['objects']
        else:
            for uuid in json:
                for obj in json[uuid]:
                    if "dn" in json[uuid][obj] and json[uuid][obj]["dn"] == misc:
                        return True

        return False
Example #3
0
    def exists(self, misc):
        if is_uuid(misc):
            fltr_tpl = "%s=%%s" % self.uuid_entry
            fltr = ldap.filter.filter_format(fltr_tpl, [misc])

            res = self.con.search_s(self.lh.get_base(False), ldap.SCOPE_SUBTREE,
                    fltr, [self.uuid_entry])

        else:
            res = self.con.search_s(misc, ldap.SCOPE_ONELEVEL, '(objectClass=*)',
                [self.uuid_entry])

        if not res:
            return False

        return len(res) == 1
Example #4
0
    def __init__(self, _id, what=None, user=None):
        self.__env = Environment.getInstance()
        self.__log = getLogger(__name__)
        self.__factory = ObjectFactory.getInstance()
        self.__base = None
        self.__extensions = {}
        self.__initial_extension_state = {}
        self.__retractions = {}
        self.__attribute_map = {}
        self.__method_map = {}
        self.__current_user = user
        self.__acl_resolver = PluginRegistry.getInstance("ACLResolver")
        self.__attribute_type_map = {}
        self.__attributes = []
        self.__method_type_map = {}
        self.__property_map = {}
        self.__foreign_attrs = []

        # Do we have a uuid when opening?
        dn_or_base = _id
        if is_uuid(_id):
            index = PluginRegistry.getInstance("ObjectIndex")
            res = index.search({'_uuid': _id}, {'dn': 1})
            if res.count() == 1:
                dn_or_base = res[0]['dn']
            else:
                raise ProxyException(C.make_error('OBJECT_NOT_FOUND', id=_id))

        # Load available object types
        object_types = self.__factory.getObjectTypes()

        base_mode = "update"
        base, extensions = self.__factory.identifyObject(dn_or_base)
        if what:
            if not what in object_types:
                raise ProxyException(C.make_error('OBJECT_UNKNOWN_TYPE', type=type))

            base = what
            base_mode = "create"
            extensions = []

        if not base:
            raise ProxyException(C.make_error('OBJECT_NOT_FOUND', id=dn_or_base))

        # Get available extensions
        self.__log.debug("loading %s base object for %s" % (base, dn_or_base))
        all_extensions = object_types[base]['extended_by']

        # Load base object and extenions
        self.__base = self.__factory.getObject(base, dn_or_base, mode=base_mode)
        self.__base_type = base
        self.__base_mode = base_mode
        for extension in extensions:
            self.__log.debug("loading %s extension for %s" % (extension, dn_or_base))
            self.__extensions[extension] = self.__factory.getObject(extension, self.__base.uuid)
            self.__extensions[extension].dn = self.__base.dn
            self.__initial_extension_state[extension] = True
        for extension in all_extensions:
            if extension not in self.__extensions:
                self.__extensions[extension] = None
                self.__initial_extension_state[extension] = False

        # Generate method mapping
        for obj in [base] + extensions:
            for method in object_types[obj]['methods']:
                if obj == self.__base.__class__.__name__:
                    self.__method_map[method] = getattr(self.__base, method)
                    self.__method_type_map[method] = self.__base_type
                    continue
                if obj in self.__extensions:
                    self.__method_map[method] = getattr(self.__extensions[obj], method)
                    self.__method_type_map[method] = obj

        # Generate read and write mapping for attributes
        self.__attribute_map = self.__factory.get_attributes_by_object(self.__base_type)

        # Generate attribute to object-type mapping
        for attr in [n for n, o in self.__base.getProperties().items() if not o['foreign']]:
            self.__attributes.append(attr)
        self.__property_map = self.__base.getProperties()
        for ext in all_extensions:
            if self.__extensions[ext]:
                props = self.__extensions[ext].getProperties()
            else:
                props = self.__factory.getObjectProperties(ext)

            for attr in props:
                if not props[attr]['foreign']:
                    self.__attributes.append(attr)
                    self.__property_map[attr] = props[attr]
                else:

                    # Remember foreign properties to be able to the correct
                    # values to them after we have finished building up all classes
                    self.__foreign_attrs.append((attr, ext))

        # Get attribute to object-type mapping
        self.__attribute_type_map = self.__factory.getAttributeTypeMap(self.__base_type)
        self.uuid = self.__base.uuid
        self.dn = self.__base.dn

        self.populate_to_foreign_properties()