Exemplo n.º 1
0
 def add_entry(self, entry, entry_name, path):
     if not entry:
         raise ECException("Invalid entry")
     if not entry_name or len(entry_name) == 0:
         raise ECException("Invalid entry name")
     dest_cont = self.get_container_by_path(simplify_path(path))
     dest_cont.add_credential(entry, entry_name)
Exemplo n.º 2
0
 def add_container(self, cont, cont_name, path):
     if not cont:
         raise ECException("Invalid container")
     if not cont_name or len(cont_name) == 0:
         raise ECException("Invalid container name")
     dest_cont = self.get_container_by_path(simplify_path(path))
     dest_cont.add_node(cont, cont_name)
Exemplo n.º 3
0
 def get_container_by_path(self, path):
     dest_cont = self.root
     cont_chain = simplify_path(path).split("/")
     for c in cont_chain:
         if len(c):
             dest_cont = dest_cont.get_container(c)
     return dest_cont
Exemplo n.º 4
0
 def test_simplify_path(self):
     self.assertEqual('/', simplify_path('/'))
     self.assertEqual('/', simplify_path('///'))
     self.assertEqual('/', simplify_path(' / '))
     self.assertEqual('/', simplify_path(' / / '))
     self.assertEqual('/', simplify_path(' // '))
     self.assertEqual('/foo/bar', simplify_path('/foo/bar'))
     self.assertEqual('/foo/bar', simplify_path(' // / / foo  / / bar / '))
     self.assertEqual('/foo bar/bas', simplify_path('/foo bar/bas'))
Exemplo n.º 5
0
 def update_entry(self, path, updated_name, updated_entry):
     if not updated_entry:
         raise ECException("Invalid entry")
     if not updated_name or len(updated_name) == 0:
         raise ECException("Invalid entry name")
     cont_path, current_name = os.path.split(path)
     cont = self.get_container_by_path(simplify_path(cont_path))
     if updated_name != current_name:
         cont.rename_credential(current_name, updated_name)
     cont.replace_credential(updated_entry, updated_name)
Exemplo n.º 6
0
 def is_valid_path(self, path):
     """Returns true if the given path is valid (i.e., is a path to a
     container or entry in the store)."""
     dest_cont = self.root
     cont_chain = list(filter(None, simplify_path(path).split("/")))
     cc_count = len(cont_chain)
     for c in cont_chain:
         cc_count -= 1
         try:
             if cc_count > 0:
                 dest_cont = dest_cont.get_container(c)
             else:
                 if not dest_cont.has_container(c):
                     if not dest_cont.has_entry(c):
                         return False
         except ECNotFoundException:
             return False
         except ECException as ex:
             log.warning("Unexpected exception: {0}".format(ex))
             return False
     return True
Exemplo n.º 7
0
 def get_containers_by_path(self, path):
     cont = self.get_container_by_path(simplify_path(path))
     return cont.get_containers()
Exemplo n.º 8
0
 def get_container_count_by_path(self, path):
     cont = self.get_container_by_path(simplify_path(path))
     return len(cont.get_containers())
Exemplo n.º 9
0
 def get_entry_by_path(self, path):
     cont_path, ent_name = os.path.split(simplify_path(path))
     cont = self.get_container_by_path(cont_path)
     return ent_name, cont.get_entry(ent_name)