Skip to content

Commit

Permalink
Merge pull request #1412 from p-l-/enh-documentdb
Browse files Browse the repository at this point in the history
DB: support Amazon DocumentDB
  • Loading branch information
p-l- committed Aug 1, 2022
2 parents c93d4e6 + 5651ffb commit 1028a8f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ivre/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,7 @@ class DBNmap(DBActive):
backends = {
"http": ("http", "HttpDBNmap"),
"mongodb": ("mongo", "MongoDBNmap"),
"documentdb": ("document", "DocumentDBNmap"),
"postgresql": ("sql.postgres", "PostgresDBNmap"),
"tinydb": ("tiny", "TinyDBNmap"),
}
Expand Down Expand Up @@ -3625,6 +3626,7 @@ class DBView(DBActive):
"elastic": ("elastic", "ElasticDBView"),
"http": ("http", "HttpDBView"),
"mongodb": ("mongo", "MongoDBView"),
"documentdb": ("document", "DocumentDBView"),
"postgresql": ("sql.postgres", "PostgresDBView"),
"tinydb": ("tiny", "TinyDBView"),
}
Expand Down Expand Up @@ -3793,6 +3795,7 @@ class DBPassive(DB):
backends = {
"http": ("http", "HttpDBPassive"),
"mongodb": ("mongo", "MongoDBPassive"),
"documentdb": ("document", "DocumentDBPassive"),
"postgresql": ("sql.postgres", "PostgresDBPassive"),
"sqlite": ("sql.sqlite", "SqliteDBPassive"),
"tinydb": ("tiny", "TinyDBPassive"),
Expand Down Expand Up @@ -4268,6 +4271,7 @@ class DBAgent(DB):

backends = {
"mongodb": ("mongo", "MongoDBAgent"),
"documentdb": ("document", "DocumentDBAgent"),
"tinydb": ("tiny", "TinyDBAgent"),
}

Expand Down Expand Up @@ -4722,6 +4726,7 @@ class DBFlow(DB):

backends = {
"mongodb": ("mongo", "MongoDBFlow"),
"documentdb": ("document", "DocumentDBFlow"),
"postgresql": ("sql.postgres", "PostgresDBFlow"),
"tinydb": ("tiny", "TinyDBFlow"),
}
Expand Down
55 changes: 55 additions & 0 deletions ivre/db/document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-

# This file is part of IVRE.
# Copyright 2011 - 2022 Pierre LALET <pierre@droids-corp.org>
#
# IVRE is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IVRE is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with IVRE. If not, see <http://www.gnu.org/licenses/>.

"""This sub-module contains functions to interact with the Amazon
DocumentDB databases.
"""


from ivre.db.mongo import (
MongoDBActive,
MongoDBNmap,
MongoDBView,
MongoDBPassive,
MongoDBAgent,
MongoDBFlow,
)


class DocumentDBNmap(MongoDBNmap):
pass


class DocumentDBView(MongoDBView):
# DocumentDB has no support for text indexes
indexes = MongoDBActive.indexes
schema_migrations_indexes = MongoDBActive.schema_migrations_indexes


class DocumentDBPassive(MongoDBPassive):
pass


class DocumentDBAgent(MongoDBAgent):
pass


class DocumentDBFlow(MongoDBFlow):
pass
23 changes: 18 additions & 5 deletions ivre/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ def db_client(self):
if self.mongodb_srv is not None:
self._db_client = pymongo.MongoClient(self.mongodb_srv)
else:
self._db_client = pymongo.MongoClient(host=self.host, **self.params)
self._db_client = pymongo.MongoClient(
host=self.host,
**{
param: value
for param, value in self.params.items()
if not param.startswith("colname_")
},
)
return self._db_client

@property
Expand Down Expand Up @@ -842,22 +849,28 @@ class MongoDBActive(MongoDB, DBActive):
("ports.service_product", pymongo.ASCENDING),
("ports.service_version", pymongo.ASCENDING),
],
{},
{"name": "ivre.hosts.$ports.service"},
),
([("ports.scripts.id", pymongo.ASCENDING)], {}),
(
[
("ports.scripts.http-headers.name", pymongo.ASCENDING),
("ports.scripts.http-headers.value", pymongo.ASCENDING),
],
{"sparse": True},
{
"sparse": True,
"name": "ivre.hosts.$ports.$scripts.http-headers",
},
),
(
[
("ports.scripts.http-app.application", pymongo.ASCENDING),
("ports.scripts.http-app.version", pymongo.ASCENDING),
],
{"sparse": True},
{
"sparse": True,
"name": "ivre.hosts.$ports.$scripts.http-app",
},
),
(
[("ports.scripts.dns-domains.parents", pymongo.ASCENDING)],
Expand Down Expand Up @@ -993,7 +1006,7 @@ class MongoDBActive(MongoDB, DBActive):
("traces.hops.ipaddr_1", pymongo.ASCENDING),
("traces.hops.ttl", pymongo.ASCENDING),
],
{},
{"name": "ivre.hosts.$traces.$hops"},
),
(
[
Expand Down

0 comments on commit 1028a8f

Please sign in to comment.