Skip to content

Commit c9818a8

Browse files
committed
correct wrong return in mongo plugin + lint
modified: libnmap/plugins/backendplugin.py modified: libnmap/plugins/mongodb.py
1 parent 489a513 commit c9818a8

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

libnmap/plugins/backendplugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def get(self, id):
3535
"""
3636
raise NotImplementedError
3737

38-
def getall(self):
38+
def getall(self, filter):
3939
"""
40-
:return: collection of NmapReport
40+
:return: collection of tuple (id,NmapReport)
4141
:param filter: Nice to have implement a filter capability
4242
"""
4343
raise NotImplementedError

libnmap/plugins/mongodb.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010

1111
class NmapMongodbPlugin(NmapBackendPlugin):
12+
"""
13+
This class handle the persistence of NmapRepport object in mongodb
14+
Implementation is made using pymongo
15+
Object of this class must be create via the
16+
BackendPluginFactory.create(**url) where url is a named dict like
17+
{'plugin_name': "mongodb"} this dict may reeive all the param
18+
MongoClient() support
19+
"""
1220
def __init__(self, dbname=None, store=None, **kwargs):
1321
NmapBackendPlugin.__init__(self)
1422
if dbname is not None:
@@ -26,11 +34,11 @@ def insert(self, report):
2634
"""
2735
j = json.dumps(report, cls=ReportEncoder)
2836
try:
29-
id = self.collection.insert(json.loads(j))
37+
oid = self.collection.insert(json.loads(j))
3038
except:
3139
print "MONGODB cannot insert"
3240
raise
33-
return str(id)
41+
return str(oid)
3442

3543
def get(self, str_report_id=None):
3644
""" select a NmapReport by Id
@@ -44,26 +52,27 @@ def get(self, str_report_id=None):
4452

4553
if isinstance(rid, ObjectId):
4654
#get a specific report by mongo's id
47-
resultSet = self.collection.find({'_id': rid})
48-
if resultSet.count() == 1:
55+
resultset = self.collection.find({'_id': rid})
56+
if resultset.count() == 1:
4957
#search by id means only one in the iterator
50-
record = resultSet[0]
58+
record = resultset[0]
5159
#remove mongo's id to recreate the NmapReport Obj
5260
del record['_id']
5361
nmapreport = NmapParser.parse_fromdict(record)
5462
return nmapreport
5563

5664
def getall(self, dict_filter=None):
57-
"""return a list of all NmapReport saved in the backend
65+
"""return a list of tuple (id,NmapReport) saved in the backend
5866
TODO : add a filter capability
5967
"""
60-
nmapreportList = []
61-
r = self.collection.find()
62-
for report in r:
68+
nmapreportlist = []
69+
resultset = self.collection.find()
70+
for report in resultset:
71+
oid = report['_id']
6372
del report['_id']
6473
nmapreport = NmapParser.parse_fromdict(report)
65-
nmapreportList.append(nmapreport)
66-
return nmapreportList
74+
nmapreportlist.append((oid, nmapreport))
75+
return nmapreportlist
6776

6877
def delete(self, report_id=None):
6978
"""

0 commit comments

Comments
 (0)