Example #1
0
 def get_primary_key(self, dn: str) -> str:
     if not dn.startswith(self._dn_prefix) or not dn.endswith(
             self._dn_suffix):
         raise HTTPBadRequestField(
             description="Invalid dn {}, expected {}pk{}".format(
                 dn, self._dn_prefix, self._dn_suffix),
             field=self._primary_key)
     pk = dn[len(self._dn_prefix):-len(self._dn_suffix)]
     if '=' in pk:
         raise HTTPBadRequestField(
             description="Invalid dn {}, expected {}pk{}".format(
                 dn, self._dn_prefix, self._dn_suffix),
             field=self._primary_key)
     return pk
 def get(self, fetches: LdapFetch) -> Dict[str, Any]:
     res: Dict[str, Any] = OrderedDict()
     for field in self.fields:
         try:
             field.get(fetches, res)
         except falcon.HTTPBadRequest as e:
             raise HTTPBadRequestField(e.title, e.description, field.key)
     return res
 def get_fetch(self, fetches: Set[str]):
     for view in self.views:
         try:
             view.get_fetch(fetches)
         except HTTPBadRequestField as e:
             e.field = {view.key: e.field}
             raise
         except falcon.HTTPBadRequest as e:
             raise HTTPBadRequestField(e.title, e.description, view.key)
 def set_fetch(self, fetches: Set[str], assignments: Dict[str, Any]):
     for view in self.views:
         view_assignments = assignments.get(view.key)
         if view_assignments is not None:
             try:
                 view.set_fetch(fetches, view_assignments)
             except HTTPBadRequestField as e:
                 e.field = {view.key: e.field}
                 raise
             except falcon.HTTPBadRequest as e:
                 raise HTTPBadRequestField(e.title, e.description, view.key)
 def get(self, fetches: LdapFetch) -> Dict[str, Union[Dict[str, Any], List[str]]]:
     results: Dict[str, Union[Dict[str, Any], List[str]]] = dict()
     for view in self.views:
         try:
             results[view.key] = view.get(fetches)
         except HTTPBadRequestField as e:
             e.field = {view.key: e.field}
             raise
         except falcon.HTTPBadRequest as e:
             raise HTTPBadRequestField(e.title, e.description, view.key)
     return results
 def set_post(
         self, fetches: LdapFetch, assignments: Dict[str, Dict[str, Any]], is_new: bool
 ):
     for view in self.views:
         view_assignments = assignments.get(view.key)
         if view_assignments is not None:
             try:
                 view.set_post(fetches, view_assignments, is_new)
             except HTTPBadRequestField as e:
                 e.field = {view.key: e.field}
                 raise
             except falcon.HTTPBadRequest as e:
                 raise HTTPBadRequestField(e.title, e.description, view.key)
 def create(
         self, fetches: LdapFetch, addlist: LdapAddlist,
         assignments: Dict[str, Dict[str, Any]]
 ):
     for view in self.views:
         view_assignments = assignments.get(view.key)
         if view_assignments is not None:
             try:
                 view.create(fetches, addlist, view_assignments)
             except HTTPBadRequestField as e:
                 e.field = {view.key: e.field}
                 raise
             except falcon.HTTPBadRequest as e:
                 raise HTTPBadRequestField(e.title, e.description, view.key)
Example #8
0
 def _create(self, view: ViewDetails, assignments: Dict[str, Dict[str,
                                                                  Any]]):
     primary_key: Optional[str] = None
     for value in assignments.values():
         if self._primary_key in value:
             primary_key = value[self._primary_key]
     if not primary_key:
         raise HTTPBadRequestField(
             description="Missing primary key in assignments",
             field=self._primary_key)
     addlist: LdapAddlist = LdapAddlist(
         {'objectClass': list(self._classes)})
     dn = self.get_dn(primary_key)
     view.create(LdapFetch(dn, {}), addlist, assignments)
     try:
         self._db.add(dn, attributes=addlist)
     except LDAPExceptionError as e:
         raise FalconLdapError(e)
     view.set_post(LdapFetch(dn, {}), assignments, True)
 def create(self, fetches: LdapFetch, modlist: LdapAddlist, assignments: Dict[str, Any]):
     for field in self.fields:
         try:
             field.create(fetches, modlist, assignments)
         except falcon.HTTPBadRequest as e:
             raise HTTPBadRequestField(e.title, e.description, field.key)
 def set_post(self, fetches: LdapFetch, assignments: Dict[str, Any], is_new: bool):
     for field in self.fields:
         try:
             field.set_post(fetches, assignments, is_new)
         except falcon.HTTPBadRequest as e:
             raise HTTPBadRequestField(e.title, e.description, field.key)
 def set_fetch(self, fetches: Set[str], assignments: Dict[str, Any]):
     for field in self.fields:
         try:
             field.set_fetch(fetches, assignments)
         except falcon.HTTPBadRequest as e:
             raise HTTPBadRequestField(e.title, e.description, field.key)
 def get_fetch(self, fetches: Set[str]):
     for field in self.fields:
         try:
             field.get_fetch(fetches)
         except falcon.HTTPBadRequest as e:
             raise HTTPBadRequestField(e.title, e.description, field.key)