From c516bb9ca9884415073a15d436e6593eba81d25b Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 13 May 2022 16:23:23 +0100 Subject: [PATCH] Switch to OpenSearch --- handler/lib/money.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/handler/lib/money.py b/handler/lib/money.py index a0c9f09..6624157 100644 --- a/handler/lib/money.py +++ b/handler/lib/money.py @@ -7,7 +7,7 @@ from pycoingecko import CoinGeckoAPI from forex_python.converter import CurrencyRates import urllib3 import logging -from elasticsearch import Elasticsearch +from opensearchpy import OpenSearch from datetime import datetime # Project imports @@ -17,7 +17,7 @@ import util # TODO: secure ES traffic properly urllib3.disable_warnings() -tracer = logging.getLogger("elasticsearch") +tracer = logging.getLogger("opensearch") tracer.setLevel(logging.CRITICAL) tracer = logging.getLogger("elastic_transport.transport") tracer.setLevel(logging.CRITICAL) @@ -38,12 +38,26 @@ class Money(util.Base): self.cr = CurrencyRates() self.cg = CoinGeckoAPI() if settings.ES.Enabled == "1": - self.es = Elasticsearch( - f"https://{settings.ES.Host}:9200", + # self.es = Elasticsearch( + # f"https://{settings.ES.Host}:9200", + # verify_certs=False, + # basic_auth=(settings.ES.Username, settings.ES.Pass), + # # ssl_assert_fingerprint=("6b264fd2fd107d45652d8add1750a8a78f424542e13b056d0548173006260710"), + # ca_certs="certs/ca.crt", + # ) + # TODO: implement ca certs https://opensearch.org/docs/latest/clients/python/ + auth = (settings.ES.Username, settings.ES.Pass) + self.es = OpenSearch( + hosts=[{"host": settings.ES.Host, "port": 9200}], + http_compress=False, # enables gzip compression for request bodies + http_auth=auth, + # client_cert = client_cert_path, + # client_key = client_key_path, + use_ssl=True, verify_certs=False, - basic_auth=(settings.ES.Username, settings.ES.Pass), - # ssl_assert_fingerprint=("6b264fd2fd107d45652d8add1750a8a78f424542e13b056d0548173006260710"), - ca_certs="certs/ca.crt", + ssl_assert_hostname=False, + ssl_show_warn=False, + # a_certs=ca_certs_path, ) def run_checks_in_thread(self): @@ -73,7 +87,7 @@ class Money(util.Base): cast["type"] = msgtype cast["ts"] = str(datetime.now().isoformat()) cast["xtype"] = "tx" - self.es.index(index=settings.ES.Index, document=cast) + self.es.index(index=settings.ES.Index, body=cast) def lookup_rates(self, platform, ads, rates=None): """