def export_keepass(creds, password): db = Database() groups = {} for c in creds: # Create the group if we havent yet if c.group.name not in groups.keys(): groups[c.group.name] = db.create_group(title=c.group.name) kpg = groups[c.group.name] # Add tags list to the end of the description tags = "\n\nTags: " for t in c.tags.all(): tags += "[" tags += t.name tags += "] " desc = unicode(c.description) + tags # Create the entry e = kpg.create_entry(title=c.title, username=c.username, password=c.password, url=c.url, notes=desc) if c.attachment: e.binary_desc = c.attachment_name e.binary = c.attachment.read() # Send the response response = HttpResponse(content_type="application/x-keepass") db.save(response, password=password) response["Content-Disposition"] = "attachment; filename=RatticExport.kdb" response["Content-Length"] = response.tell() return response
def test_save(self): """ Test creating and saving a database. """ db = Database() i_group = db.create_default_group() e_group = db.create_group(title="eMail") e1 = i_group.create_entry(title="FirstEntry", username="******", password="******", url="http://example.com") e2 = i_group.create_entry(title="SecondEntry", username="******", password="******", url="http://example.com") e3 = e_group.create_entry(title="ThirdEntry", username="******", password="******", url="http://example.com") ser = db.to_dict(hierarchy=True, hide_passwords=True) with self.assertRaisesRegexp(ValueError, r"Unable to save without target file."): db.save(password='******') stream = BytesIO() db.save(dbfile=stream, password='******') stream.seek(0) with self.assertRaises(exc.AuthenticationError): db.load(dbfile=stream, password='******') stream.seek(0) db.load(dbfile=stream, password='******') self.maxDiff = None self.assertEquals(ser, db.to_dict(hierarchy=True, hide_passwords=True))
def export_keepass(creds, password): db = Database() groups = {} for c in creds: # Create the group if we havent yet if c.group.name not in groups.keys(): groups[c.group.name] = db.create_group(title=c.group.name) kpg = groups[c.group.name] # Add tags list to the end of the description tags = '\n\nTags: ' for t in c.tags.all(): tags += '[' tags += t.name tags += '] ' desc = str(c.description) + tags # Create the entry kpg.create_entry( title=c.title, username=c.username, password=c.password, url=c.url, notes=desc, ) # Send the response response = HttpResponse(mimetype='application/x-keepass') db.save(response, password=password) response['Content-Disposition'] = 'attachment; filename=RatticExport.kdb' response['Content-Length'] = response.tell() return response
def export_keepass(creds, password, filename='RatticExport.kdb'): db = Database() groups = {} for c in creds: # Create the group if we havent yet if c.group.name not in groups.keys(): groups[c.group.name] = db.create_group(title=c.group.name) kpg = groups[c.group.name] # Add tags list to the end of the description tags = '\n\nTags: ' for t in c.tags.all(): tags += '[' tags += t.name tags += '] ' desc = unicode(c.description) + tags # Create the entry e = kpg.create_entry( title=c.title, username=c.username, password=c.password, url=c.url, notes=desc, ) if c.attachment: e.binary_desc = c.attachment_name e.binary = c.attachment.read() # Send the response response = HttpResponse(content_type='application/x-keepass') db.save(response, password=password) response['Content-Disposition'] = 'attachment; filename=' + filename response['Content-Length'] = response.tell() return response