From e63d975c9606e409bf4c74fa1d4a90bfbf83a943 Mon Sep 17 00:00:00 2001 From: spadakan Date: Mon, 18 Dec 2023 07:00:56 -0500 Subject: [PATCH 1/5] added opensearch keys to a secret --- opl/http.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/opl/http.py b/opl/http.py index 3e20a32..9491853 100644 --- a/opl/http.py +++ b/opl/http.py @@ -1,12 +1,23 @@ import logging import requests - +from requests.auth import HTTPBasicAuth import urllib3 - - -session = requests.Session() - +import os + +enable_new_search = os.getenv('NEW_SEARCH_ENABLED', 'false').lower() == 'true' + +if enable_new_search: + username = os.getenv('OPEN_SEARCH_DASBOARD') + password = os.getenv('OPEN_SEARCH_PASSWORD') + session = requests.Session() + session.auth = HTTPBasicAuth(username, password) + session.verify = False + session.headers.update({ + "Content-Type": "application/json", + }) +else: + session = requests.Session() def disable_insecure_request_warnings(disable_it): if disable_it: From cf5069d2b6422e62a3ced56c1aecd2637231d3c7 Mon Sep 17 00:00:00 2001 From: spadakan Date: Mon, 18 Dec 2023 07:06:44 -0500 Subject: [PATCH 2/5] fixing lint errors --- opl/http.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opl/http.py b/opl/http.py index 9491853..4e18d19 100644 --- a/opl/http.py +++ b/opl/http.py @@ -19,6 +19,7 @@ else: session = requests.Session() + def disable_insecure_request_warnings(disable_it): if disable_it: logging.debug("Disabling insecure request warnings") From 2739348771ca3c3d8bf900e53eef25198f681594 Mon Sep 17 00:00:00 2001 From: spadakan Date: Mon, 18 Dec 2023 07:27:10 -0500 Subject: [PATCH 3/5] fixing black formatter issues --- opl/http.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/opl/http.py b/opl/http.py index 4e18d19..750829d 100644 --- a/opl/http.py +++ b/opl/http.py @@ -2,20 +2,23 @@ import requests from requests.auth import HTTPBasicAuth + import urllib3 import os -enable_new_search = os.getenv('NEW_SEARCH_ENABLED', 'false').lower() == 'true' +enable_new_search = os.getenv("NEW_SEARCH_ENABLED", "false").lower() == "true" if enable_new_search: - username = os.getenv('OPEN_SEARCH_DASBOARD') - password = os.getenv('OPEN_SEARCH_PASSWORD') + username = os.getenv("OPEN_SEARCH_USERNAME") + password = os.getenv("OPEN_SEARCH_PASSWORD") session = requests.Session() session.auth = HTTPBasicAuth(username, password) session.verify = False - session.headers.update({ - "Content-Type": "application/json", - }) + session.headers.update( + { + "Content-Type": "application/json", + } + ) else: session = requests.Session() From f6d34e4cfde21fcca6ba43ffe9eefe3c3e1835e5 Mon Sep 17 00:00:00 2001 From: Sarath Padakandla Date: Wed, 10 Jan 2024 17:53:16 -0500 Subject: [PATCH 4/5] added new elastic search authentication --- opl/investigator/elasticsearch_loader.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/opl/investigator/elasticsearch_loader.py b/opl/investigator/elasticsearch_loader.py index 5c76c17..20561ff 100644 --- a/opl/investigator/elasticsearch_loader.py +++ b/opl/investigator/elasticsearch_loader.py @@ -1,10 +1,15 @@ import json import logging import tempfile +from requests.auth import HTTPBasicAuth import opl.http import opl.status_data +# Environment variables for OpenSearch credentials +open_search_username = "insights_perf" +open_search_password = os.environ.get('OPEN_SEARCH_PASSWORD') + def load(server, index, query, paths): out = {} @@ -21,7 +26,7 @@ def load(server, index, query, paths): f"Querying ES with url={url}, headers={headers} and json={json.dumps(data)}" ) - response = opl.http.get(url, headers=headers, json=data) + response = opl.http.get(url, auth=HTTPBasicAuth(open_search_username, open_search_password), headers=headers, json=data) for item in response["hits"]["hits"]: logging.debug( From f0fa9348c78c2d045b851ce410ee2e09c7054d51 Mon Sep 17 00:00:00 2001 From: Sarath Padakandla Date: Wed, 10 Jan 2024 17:54:54 -0500 Subject: [PATCH 5/5] Update http.py added verification false for https --- opl/http.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/opl/http.py b/opl/http.py index 750829d..c90b0c5 100644 --- a/opl/http.py +++ b/opl/http.py @@ -1,28 +1,13 @@ import logging import requests -from requests.auth import HTTPBasicAuth import urllib3 -import os - -enable_new_search = os.getenv("NEW_SEARCH_ENABLED", "false").lower() == "true" - -if enable_new_search: - username = os.getenv("OPEN_SEARCH_USERNAME") - password = os.getenv("OPEN_SEARCH_PASSWORD") - session = requests.Session() - session.auth = HTTPBasicAuth(username, password) - session.verify = False - session.headers.update( - { - "Content-Type": "application/json", - } - ) -else: - session = requests.Session() +session = requests.Session() +session.verify=False + def disable_insecure_request_warnings(disable_it): if disable_it: logging.debug("Disabling insecure request warnings")