def find_or_create_domain(self, session, _domain, _source, label="", info=""): _domain = db.Domain.normalize(_domain) # find or create domain domain = session.query(db.Domain).filter_by(domain=_domain).first() if not domain: domain = db.Domain(domain=_domain, active=True) session.add(domain) assert domain # find or create source source = session.query(db.Source).\ filter(db.Source.domain == domain).\ filter_by(source=_source).\ first() if not source: source = db.Source(domain_id=domain.id, source=_source, label=label, info=info) session.add(source) return domain
def test_genkeypair(self): codename = crypto_util.genrandomid() filesystem_id = crypto_util.hash_codename(codename) journalist_filename = crypto_util.display_id() source = db.Source(filesystem_id, journalist_filename) db.db_session.add(source) db.db_session.commit() crypto_util.genkeypair(source.filesystem_id, codename) self.assertIsNotNone(crypto_util.getkey(filesystem_id))
def init_source_without_keypair(): """Initialize a source: create their database record and the filesystem directory that stores their submissions & replies. Return a source object and their codename string. :returns: A 2-tuple. The first entry, the :class:`db.Source` initialized. The second, their codename string. """ # Create source identity and database record codename = crypto_util.genrandomid() filesystem_id = crypto_util.hash_codename(codename) journalist_filename = crypto_util.display_id() source = db.Source(filesystem_id, journalist_filename) db.db_session.add(source) db.db_session.commit() # Create the directory to store their submissions and replies os.mkdir(store.path(source.filesystem_id)) return source, codename