summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Näslund <victor@sunet.se>2022-11-16 19:38:36 +0100
committerVictor Näslund <victor@sunet.se>2022-11-16 19:38:36 +0100
commit49cd9e90ae5f9a374ccd73f4a064d89729cdfb5e (patch)
tree01788862c606087c7a94e8493670e2d429a16c55
parent419862b9575f7a2254d777ab0e0d38a09e065603 (diff)
renamed key search to filter
-rw-r--r--setup.cfg2
-rw-r--r--src/soc_collector/data/collector_root_ca.crt13
-rw-r--r--src/soc_collector/db.py6
-rw-r--r--src/soc_collector/soc_collector_cli.py7
4 files changed, 21 insertions, 7 deletions
diff --git a/setup.cfg b/setup.cfg
index 8026ee7..853bd3a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[options.package_data]
# If any package or subpackage contains *.txt or *.rst files, include them:
-soc_collector = py.typed data/collector_root_ca.crt
+soc_collector = py.typed, data/collector_root_ca.crt
[options.entry_points]
# If any package or subpackage contains *.txt or *.rst files, include them:
diff --git a/src/soc_collector/data/collector_root_ca.crt b/src/soc_collector/data/collector_root_ca.crt
new file mode 100644
index 0000000..b9cddf1
--- /dev/null
+++ b/src/soc_collector/data/collector_root_ca.crt
@@ -0,0 +1,13 @@
+-----BEGIN CERTIFICATE-----
+MIIB6zCCAZ2gAwIBAgIUXbzkTFrPe+rAKscqzHHB+Kr6oDQwBQYDK2VwMGsxCzAJ
+BgNVBAYTAlNFMRMwEQYDVQQIDApTb21lLVN0YXRlMQ4wDAYDVQQKDAVTVU5FVDES
+MBAGA1UECwwJU1VORVQgU09DMSMwIQYDVQQDDBpjb2xsZWN0b3ItZGV2LnNvYy5z
+dW5ldC5zZTAeFw0yMjExMTYxNTI0NDdaFw0yNzExMTUxNTI0NDdaMGsxCzAJBgNV
+BAYTAlNFMRMwEQYDVQQIDApTb21lLVN0YXRlMQ4wDAYDVQQKDAVTVU5FVDESMBAG
+A1UECwwJU1VORVQgU09DMSMwIQYDVQQDDBpjb2xsZWN0b3ItZGV2LnNvYy5zdW5l
+dC5zZTAqMAUGAytlcAMhAFBwDjb3i5fjxrbcFOMXTZfKnIDx6h9XiojAXPXD/VpD
+o1MwUTAdBgNVHQ4EFgQUlY3rq7wlYJwaiTED1AJUTnevhxUwHwYDVR0jBBgwFoAU
+lY3rq7wlYJwaiTED1AJUTnevhxUwDwYDVR0TAQH/BAUwAwEB/zAFBgMrZXADQQCL
+9S14sR+y0AbHMTmC2BzuLmwPexK23VDgZemCRiBwR1DZ8x5Vzd/IR+WqmUaFhGPv
+utaY9PGGHZoZtrbb5WEE
+-----END CERTIFICATE-----
diff --git a/src/soc_collector/db.py b/src/soc_collector/db.py
index d601a82..f537f4a 100644
--- a/src/soc_collector/db.py
+++ b/src/soc_collector/db.py
@@ -21,7 +21,7 @@ from bson import ObjectId
class SearchInput(BaseModel):
"""Handle search data for HTTP request"""
- search: Optional[Dict[str, Any]]
+ filter: Dict[str, Any]
limit: int = 25
skip: int = 0
@@ -68,9 +68,9 @@ class DBClient:
"""
data: List[Dict[str, Any]] = []
- cursor = self.collection.find(search_data.search)
+ cursor = self.collection.find(search_data.filter)
- cursor.sort({"ip": ASCENDING, "timestamp": DESCENDING}).limit(search_data.limit).skip(search_data.skip)
+ cursor.sort([("ip", ASCENDING), ("timestamp", DESCENDING)]).limit(search_data.limit).skip(search_data.skip)
try:
async for document in cursor:
diff --git a/src/soc_collector/soc_collector_cli.py b/src/soc_collector/soc_collector_cli.py
index 27df732..9f8c793 100644
--- a/src/soc_collector/soc_collector_cli.py
+++ b/src/soc_collector/soc_collector_cli.py
@@ -180,8 +180,9 @@ def main() -> None:
info: Show info about the database, currently number of documents.
search: json blog OR path to file. skip defaults to 0 and limit to 25.
- '{"search": {"port": 111, "ip": "192.0.2.28"}, "skip": 0, "limit": 25}' OR ./search_data.json
- '{"search": {"asn_country_code": "SE", "result": {"$exists": "cve_2015_0002"}}}'
+ '{"filter": {"port": 111, "ip": "192.0.2.28"}, "skip": 0, "limit": 25}' OR ./search_data.json
+ '{"filter": {"asn_country_code": "SE", "result": {"$exists": "cve_2015_0002"}}}'
+ '{"filter": {}}'
get: key OR path to document using its "_id".
637162378c92893fff92bf7e OR ./data.json
@@ -217,7 +218,7 @@ def main() -> None:
case $prev in
search)
- COMPREPLY="'{\\"search\\": {\\"asn_country_code\\": \\"SE\\", \\"ip\\": \\"8.8.8.8\\"}}'"
+ COMPREPLY="'{\\"filter\\": {\\"asn_country_code\\": \\"SE\\", \\"ip\\": \\"192.0.2.28\\"}}'"
return
;;
esac