howler-api 3.1.0.dev390__py3-none-any.whl → 3.1.0.dev392__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -377,10 +377,10 @@ class ESCollection(Generic[ModelType]):
377
377
  elasticsearch.exceptions.AuthenticationException,
378
378
  ) as e:
379
379
  if not isinstance(e, SearchRetryException):
380
- logger.warning(
380
+ logger.exception(
381
381
  f"No connection to Elasticsearch server(s): "
382
382
  f"{' | '.join(self.datastore.get_hosts(safe=True))}"
383
- f", because [{e}] retrying {func.__name__}..."
383
+ f", because [{str(e)}] retrying {func.__name__}..." # noqa: TRY401
384
384
  )
385
385
 
386
386
  time.sleep(min(retries, self.MAX_RETRY_BACKOFF))
howler/datastore/store.py CHANGED
@@ -4,18 +4,28 @@ import logging
4
4
  import os
5
5
  import re
6
6
  from os import environ
7
+ from pathlib import Path
7
8
  from typing import Any, Optional, cast
8
9
  from urllib.parse import urlparse
9
10
 
10
11
  import elasticsearch
11
12
  import elasticsearch.client
12
13
 
14
+ from howler.common.logging.format import HWL_DATE_FORMAT, HWL_LOG_FORMAT
13
15
  from howler.datastore.collection import ESCollection
14
16
  from howler.datastore.exceptions import DataStoreException
15
17
  from howler.odm.models.config import Config
16
18
  from howler.odm.models.config import config as _config
17
19
 
18
20
  TRANSPORT_TIMEOUT = int(environ.get("HWL_DATASTORE_TRANSPORT_TIMEOUT", "10"))
21
+ CERTS_PATH = Path(os.environ.get("HWL_CERT_DIRECTORY", "/etc/howler/certs"))
22
+
23
+ logger = logging.getLogger("howler.datastore.store")
24
+ logger.setLevel(logging.INFO)
25
+ console = logging.StreamHandler()
26
+ console.setLevel(logging.INFO)
27
+ console.setFormatter(logging.Formatter(HWL_LOG_FORMAT, HWL_DATE_FORMAT))
28
+ logger.addHandler(console)
19
29
 
20
30
 
21
31
  class ESStore(object):
@@ -58,9 +68,23 @@ class ESStore(object):
58
68
  self._username: Optional[str] = None
59
69
  self._password: Optional[str] = None
60
70
  self._hosts = []
71
+ self._cert: str | None = None
61
72
 
62
73
  for host in config.datastore.hosts:
63
74
  self._hosts.append(str(host))
75
+
76
+ cert = CERTS_PATH / f"{host.name}.crt"
77
+ if cert.exists():
78
+ if self._cert is None:
79
+ self._cert = str(cert)
80
+ logger.info("Using certificate %s for elasticsearch network traffic", self._cert)
81
+ else:
82
+ logger.error("Only a single certificate path is supported - ignoring additional paths.")
83
+ logger.error(
84
+ "If you have multiple certificates, bundle them into a single .pem file and specify "
85
+ "it for the first host."
86
+ )
87
+
64
88
  if os.getenv(f"{host.name.upper()}_HOST_APIKEY_ID", None) is not None:
65
89
  self._apikey = (
66
90
  os.environ[f"{host.name.upper()}_HOST_APIKEY_ID"],
@@ -81,6 +105,7 @@ class ESStore(object):
81
105
  if self._apikey is not None:
82
106
  self.client = elasticsearch.Elasticsearch(
83
107
  hosts=self._hosts, # type: ignore
108
+ ca_certs=self._cert, # type: ignore
84
109
  api_key=self._apikey,
85
110
  max_retries=0,
86
111
  request_timeout=TRANSPORT_TIMEOUT,
@@ -88,6 +113,7 @@ class ESStore(object):
88
113
  elif self._username is not None and self._password is not None:
89
114
  self.client = elasticsearch.Elasticsearch(
90
115
  hosts=self._hosts, # type: ignore
116
+ ca_certs=self._cert, # type: ignore
91
117
  basic_auth=(self._username, self._password),
92
118
  max_retries=0,
93
119
  request_timeout=TRANSPORT_TIMEOUT,
@@ -95,6 +121,7 @@ class ESStore(object):
95
121
  else:
96
122
  self.client = elasticsearch.Elasticsearch(
97
123
  hosts=self._hosts, # type: ignore
124
+ ca_certs=self._cert, # type: ignore
98
125
  max_retries=0,
99
126
  request_timeout=TRANSPORT_TIMEOUT,
100
127
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: howler-api
3
- Version: 3.1.0.dev390
3
+ Version: 3.1.0.dev392
4
4
  Summary: Howler - API server
5
5
  License: MIT
6
6
  Keywords: howler,alerting,gc,canada,cse-cst,cse,cst,cyber,cccs
@@ -53,14 +53,14 @@ howler/cronjobs/view_cleanup.py,sha256=ULWLR1uFcRemRgkEDrMqmBamHiE0dgDvu49VK0qDk
53
53
  howler/datastore/README.md,sha256=ekWl1YJSrHlZpU5PgBkPEzPWjdbTdav6Rd2P0ccIesw,4758
54
54
  howler/datastore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
55
  howler/datastore/bulk.py,sha256=VfolZfiaBD4ZTK3j6IVVVq4GMjVXb5elrsGwwM_nONE,2829
56
- howler/datastore/collection.py,sha256=joi4-lUMWGH1DBO3ag36GriSI7J2n-UpIfb1-KaBdTU,91191
56
+ howler/datastore/collection.py,sha256=1VuWTShCVIo3afye9gM7uSpAvSGvqm7j6w0ZOUEX9N8,91214
57
57
  howler/datastore/constants.py,sha256=x7ODomtOQmDjmXoAxly4onPAnUkq4BLZ1TBg-UgpU1g,2415
58
58
  howler/datastore/exceptions.py,sha256=yZvQXRI4mR50ltGFHbdZAD4TIbhdKJku6LLTPQ0JZRk,955
59
59
  howler/datastore/howler_store.py,sha256=kW7FKM-tILcfTmrjSB1yZm-ZnumPS_tiQEZUDaQoDkg,2915
60
60
  howler/datastore/migrations/fix_process.py,sha256=J0FxqcXbQ161sgmQ5teyEcPuX7WYB9wqs0CO8m1jk0U,1218
61
61
  howler/datastore/operations.py,sha256=5WdJBewXRIG71ZexQcYASv0IYoDi1m9ia8332u5mXSs,3919
62
62
  howler/datastore/schemas.py,sha256=kuxqYVWMgqnrdU-ypkDxoSzEtECUrRCKXjU_R5Kg7X4,3158
63
- howler/datastore/store.py,sha256=MzIvZy8deMgpnKR-TKTTcttH6kkYy4EBSYMCh0Q-J0E,7055
63
+ howler/datastore/store.py,sha256=SvCDaGuZwkx3d0ii-Higg6afITDshtXKQfeBvuXiqDE,8289
64
64
  howler/datastore/support/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
65
65
  howler/datastore/support/build.py,sha256=iBVfWophzoPlx6rvR5w3Axb6gjqLuDeDBpKj7lO-1l0,7877
66
66
  howler/datastore/support/schemas.py,sha256=kuxqYVWMgqnrdU-ypkDxoSzEtECUrRCKXjU_R5Kg7X4,3158
@@ -192,7 +192,7 @@ howler/utils/path.py,sha256=DfOU4i4zSs4wchHoE8iE7aWVLkTxiC_JRGepF2hBYBk,690
192
192
  howler/utils/socket_utils.py,sha256=nz1SklC9xBHUSfHyTJjpq3mbozX1GDf01WzdGxfaUII,2212
193
193
  howler/utils/str_utils.py,sha256=HE8Hqh2HlOLaj16w0H9zKOyDJLp-f1LQ50y_WeGZaEk,8389
194
194
  howler/utils/uid.py,sha256=p9dsqyvZ-lpiAuzZWCPCeEM99kdk0Ly9czf04HNdSuw,1341
195
- howler_api-3.1.0.dev390.dist-info/METADATA,sha256=B6KC111Nk4ffzkOiq9qvKN2Aux-eiRPsKc3FzGk7ybU,2804
196
- howler_api-3.1.0.dev390.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
197
- howler_api-3.1.0.dev390.dist-info/entry_points.txt,sha256=Lu9SBGvwe0wczJHmc-RudC24lmQk7tv3ZBXon9RIihg,259
198
- howler_api-3.1.0.dev390.dist-info/RECORD,,
195
+ howler_api-3.1.0.dev392.dist-info/METADATA,sha256=fF6W3KTMSNqqSwcwjZoLozEVP_Gi2cVKNvqGi0iRnVw,2804
196
+ howler_api-3.1.0.dev392.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
197
+ howler_api-3.1.0.dev392.dist-info/entry_points.txt,sha256=Lu9SBGvwe0wczJHmc-RudC24lmQk7tv3ZBXon9RIihg,259
198
+ howler_api-3.1.0.dev392.dist-info/RECORD,,