Skip to content

Commit

Permalink
only pass TLS options to opensearch-py connection if scheme is https'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Oct 12, 2023
1 parent 900638f commit 5fbd092
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
20 changes: 13 additions & 7 deletions api/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,19 @@
opensearchHttpAuth = None
opensearchReqHttpAuth = None

databaseClient = DatabaseClass(
hosts=[opensearchUrl],
http_auth=opensearchHttpAuth,
verify_certs=opensearchSslVerify,
ssl_assert_hostname=False,
ssl_show_warn=False,
)
if urlparse(opensearchUrl).scheme == 'https':
databaseClient = DatabaseClass(
hosts=[opensearchUrl],
http_auth=opensearchHttpAuth,
verify_certs=opensearchSslVerify,
ssl_assert_hostname=False,
ssl_show_warn=False,
)
else:
databaseClient = DatabaseClass(
hosts=[opensearchUrl],
http_auth=opensearchHttpAuth,
)


def deep_get(d, keys, default=None):
Expand Down
24 changes: 16 additions & 8 deletions shared/bin/pcap_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from collections import defaultdict
from multiprocessing.pool import ThreadPool

from urllib.parse import urlparse
from urllib3.exceptions import NewConnectionError

from watchdog.observers import Observer
Expand Down Expand Up @@ -98,14 +99,21 @@ def __init__(self, logger=None):
try:
self.logger.info(f"{scriptName}:\tconnecting to {args.opensearchMode} {args.opensearchUrl}...")

self.openSearchClient = DatabaseClass(
hosts=[args.opensearchUrl],
http_auth=opensearchHttpAuth,
verify_certs=args.opensearchSslVerify,
ssl_assert_hostname=False,
ssl_show_warn=False,
request_timeout=1,
)
if urlparse(args.opensearchUrl).scheme == 'https':
self.openSearchClient = DatabaseClass(
hosts=[args.opensearchUrl],
http_auth=opensearchHttpAuth,
verify_certs=args.opensearchSslVerify,
ssl_assert_hostname=False,
ssl_show_warn=False,
request_timeout=1,
)
else:
self.openSearchClient = DatabaseClass(
hosts=[args.opensearchUrl],
http_auth=opensearchHttpAuth,
request_timeout=1,
)

self.logger.debug(f"{scriptName}:\t{self.openSearchClient.cluster.health()}")

Expand Down

0 comments on commit 5fbd092

Please sign in to comment.