Skip to content

Commit 9e35a95

Browse files
committed
added get/delete method for mongol db plugin
1 parent b3704cf commit 9e35a95

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

libnmap/plugins/dbplugin.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
class NmapDBPlugin(object):
4+
def __init__(self):
5+
self.dbname = 'nmapdb'
6+
self.store = 'reports'
7+
8+
def db_insert(self, dict_data):
9+
raise NotImplementedError
10+
def db_update(self, id):
11+
raise NotImplementedError
12+
def db_delete(self, id):
13+
raise NotImplementedError
14+
def db_get(self, id):
15+
raise NotImplementedError
16+
def db_find(self, key):
17+
raise NotImplementedError

libnmap/plugins/mongodb.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
from libnmap.plugins.dbplugin import NmapDBPlugin
33
from pymongo import MongoClient
4+
from bson.objectid import ObjectId
45

56
class NmapMongoPlugin(NmapDBPlugin):
67
def __init__(self, **kwargs):
@@ -10,3 +11,20 @@ def __init__(self, **kwargs):
1011

1112
def db_insert(self, dict_data):
1213
self.collection.insert(dict_data)
14+
15+
def db_get(self, report_id=None):
16+
rid = report_id
17+
if report_id is not None and isinstance(report_id, str):
18+
rid = ObjectId(report_id)
19+
20+
if isinstance(rid, ObjectId):
21+
r = self.collection.find({ '_id': rid })
22+
else:
23+
r = self.collection.find()
24+
return r
25+
26+
def db_delete(self, report_id=None):
27+
if report_id is not None and isinstance(report_id, str):
28+
ir = self.collection.remove({ '_id': ObjectId(report_id)})
29+
else:
30+
r= self.collection.remove({ '_id': report_id })

0 commit comments

Comments
 (0)