def children(self): if not self.args.nodes: return Node.root().lower() try: return Node.get(self.tokens_2_filters(self.tokenize_nodes())).lower() except exc.MatchedMultiple as e: import sys print("Couldnt match exactly, listing node: %s %s" % (e.last.attr.name, e.last.value), file=sys.stderr) return e.matched
def _run(self,args): for x in session.query(Attribute).all(): if x.description: # If there are no descriptions, there is no point in # dumping attributes as there is no additional # information as the short names are part of node path raise RuntimeError("Description in an attribute") total = self.dfs(Node.root().lower(), lambda x: None) dumped = self.dfs(Node.root().lower(), self.dump) if total != dumped: raise RuntimeError("Dumped {} leafs but {} found in total".format(dumped, total))
def _run(self,args): filters = self.tokens_2_filters(self.tokenize_nodes()) n = Node.get(filters) n.value = self.encrypt(self.input()) session.commit()
def _run(self, args): # nodes = session.query(Node).filter_by(value=args.node_value).all() nodes_found = Node.query().get_nodes_by_value(args.node_value).all() if not nodes_found: print("No matches") return for nf in nodes_found: for path in nf.get_paths(): path_formatted = [make_token(n) for n in path] print(" ".join(path_formatted))
def _run(self,args): filters = self.tokens_2_filters(self.tokenize_nodes()) # do not modify filters here # in this command the path must be specified exactly goal = Node.get(filters) if not goal.lower() == []: raise Exception('node is not leaf') # ^ FIXME add -r option map(session.delete,goal.higher_edges) # ^ FIXME: there may be better solution via sqlalchemy session.delete(goal) session.commit()
def _run(self,args): filters = self.tokens_2_filters(self.tokenize_nodes()) if filters[-1]['node']: try: a = Attribute.password() filters.append({'attr':a.name}) # append filter for goal we want to retrieve # unless it has been specified by the user as the last node # or there is no configured password attribute except NoResultFound: filters.append({}) # append empty filter so we'll get the "one more" node goal = Node.get(filters) self.output(self.decrypt(goal.value))
def node(self): """ Creates a new node """ filters = self.tokens_2_filters(self.tokenize_nodes()) if not filters[-1]['node'] and filters[-1]['attr']: new_type = Attribute.get(filters.pop()['attr']) else: new_type = Attribute.password() #if new_type and new_type.one_per_higher_node: if new_type: filters.append({'attr': new_type}) getLogger("%s_%s" % (__name__, self.__class__.__name__,)).debug("filters: %s" % filters) try: node = Node.get(filters,create=True) except MatchedMultiple as e: self.die("Multiple values %s " % (",".join([i.name for i in e.matched]),e.last.name)) getLogger("%s_%s" % (__name__, self.__class__.__name__,)).debug("node.value: %s" % node.value) if node.value and not self.args.force: raise ResourceExists() # node.attribute.new_value() # could return new value based on the type so it could be more generic # however a new_type would have to not be None value = self.get_value(new_type) node.value = self.encrypt(value) session.commit() if self.__generated: self.output(value)