Skip to content

Commit 5ec2a68

Browse files
committed
fix: fix es ssl
1 parent 3488efe commit 5ec2a68

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

backend/apps/db/es_engine.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,26 @@
1111
from common.error import SingleMessageError
1212

1313

14+
def get_es_auth(conf: DatasourceConf):
15+
username = f"{conf.username}"
16+
password = f"{conf.password}"
17+
18+
credentials = f"{username}:{password}"
19+
encoded_credentials = b64encode(credentials.encode()).decode()
20+
21+
return {
22+
"Content-Type": "application/json",
23+
"Authorization": f"Basic {encoded_credentials}"
24+
}
25+
26+
1427
def get_es_connect(conf: DatasourceConf):
1528
es_client = Elasticsearch(
1629
[conf.host], # ES address
1730
basic_auth=(conf.username, conf.password),
1831
verify_certs=False,
19-
compatibility_mode=True
32+
compatibility_mode=True,
33+
headers=get_es_auth(conf)
2034
)
2135
return es_client
2236

@@ -95,18 +109,8 @@ def get_es_data_by_http(conf: DatasourceConf, sql: str):
95109
url = url[:-1]
96110

97111
host = f'{url}/_sql?format=json'
98-
username = f"{conf.username}"
99-
password = f"{conf.password}"
100-
101-
credentials = f"{username}:{password}"
102-
encoded_credentials = b64encode(credentials.encode()).decode()
103-
104-
headers = {
105-
"Content-Type": "application/json",
106-
"Authorization": f"Basic {encoded_credentials}"
107-
}
108112

109-
response = requests.post(host, data=json.dumps({"query": sql}), headers=headers, verify=False)
113+
response = requests.post(host, data=json.dumps({"query": sql}), headers=get_es_auth(conf), verify=False)
110114

111115
# print(response.json())
112116
res = response.json()

0 commit comments

Comments
 (0)