Skip to content

Commit e4cd19a

Browse files
committed
Add profile command and fix crowdsec mmdb read
1 parent 6959d8e commit e4cd19a

File tree

7 files changed

+387
-213
lines changed

7 files changed

+387
-213
lines changed

bin/crowdsec_constants.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
VERSION = "1.2.3"
2+
3+
4+
## LOCAL DUMP CONFIGURATION
5+
LOCAL_DUMP_FILES = {
6+
"crowdsec_full_mmdb": {
7+
"filename": "crowdsec_full.mmdb",
8+
"name": "mmdb",
9+
}
10+
}
11+
12+
## PROFILES CONFIGURATION
13+
BASE_PROFILE_FIELDS = [
14+
"ip",
15+
"reputation",
16+
"confidence",
17+
"as_num",
18+
"as_name",
19+
"location",
20+
"classifications",
21+
]
22+
ANONYMOUS_PROFILE_FIELDS = [
23+
"ip",
24+
"reputation",
25+
"classifications",
26+
] # to replace 'classifications' with proxy_vpn flag when ready]
27+
IP_RANGE_PROFILE_FIELDS = ["ip", "ip_range", "ip_range_24", "ip_range_24_score"]
28+
29+
CROWDSEC_PROFILES = {
30+
"base": BASE_PROFILE_FIELDS,
31+
"anonymous": BASE_PROFILE_FIELDS,
32+
"ip_range": IP_RANGE_PROFILE_FIELDS,
33+
}

bin/crowdsec_utils.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import maxminddb
2+
3+
from crowdsec_constants import VERSION
4+
5+
6+
def get_headers(api_key):
7+
"""Get headers for API requests"""
8+
headers = {
9+
"x-api-key": api_key,
10+
"Accept": "application/json",
11+
"User-Agent": "crowdSec-splunk-app/{}".format(VERSION),
12+
}
13+
return headers
14+
15+
16+
def load_api_key(service):
17+
"""Load API key from storage passwords"""
18+
api_key = None
19+
for passw in service.storage_passwords.list():
20+
if passw.name == "crowdsec-splunk-app_realm:api_key:":
21+
api_key = passw.clear_password
22+
break
23+
return api_key
24+
25+
26+
def load_mmdb(mmdb_path):
27+
return maxminddb.open_database(mmdb_path)
28+
29+
30+
def load_local_dump_settings(service):
31+
local_dump_enabled = False
32+
for conf in service.confs.list():
33+
if conf.name == "crowdsec_settings":
34+
stanza = conf.list()[0]
35+
if stanza:
36+
local_dump_enabled = (
37+
stanza.content.get("local_dump", "0").lower() == "1"
38+
)
39+
return local_dump_enabled

0 commit comments

Comments
 (0)