Skip to content

Commit

Permalink
ES创建连接时使用“是否验证服务端ssl证书”字段 (#2815)
Browse files Browse the repository at this point in the history
  • Loading branch information
feiazifeiazi authored Sep 19, 2024
1 parent 0e649e9 commit b1efe08
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion sql/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self, instance: Instance = None):
self.password = instance.password
self.db_name = instance.db_name
self.mode = instance.mode
self.is_ssl = instance.is_ssl

# 判断如果配置了隧道则连接隧道,只测试了MySQL
if self.instance.tunnel:
Expand Down
12 changes: 6 additions & 6 deletions sql/engines/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,13 +1046,13 @@ def get_connection(self, db_name=None):
if self.conn:
return self.conn
if self.instance:
scheme = "https" if self.is_ssl else "http"
scheme = "https" if self.instance.is_ssl else "http"
hosts = [
{
"host": self.host,
"port": self.port,
"scheme": scheme,
"use_ssl": self.is_ssl,
"use_ssl": self.instance.is_ssl,
}
]
http_auth = (
Expand All @@ -1064,7 +1064,7 @@ def get_connection(self, db_name=None):
self.conn = Elasticsearch(
hosts=hosts,
http_auth=http_auth,
verify_certs=True, # 需要证书验证
verify_certs=self.instance.verify_ssl, # 需要证书验证
)
except Exception as e:
raise Exception(f"Elasticsearch 连接建立失败: {str(e)}")
Expand Down Expand Up @@ -1095,13 +1095,13 @@ def get_connection(self, db_name=None):
if self.conn:
return self.conn
if self.instance:
scheme = "https" if self.is_ssl else "http"
scheme = "https" if self.instance.is_ssl else "http"
hosts = [
{
"host": self.host,
"port": self.port,
"scheme": scheme,
"use_ssl": self.is_ssl,
"use_ssl": self.instance.is_ssl,
}
]
http_auth = (
Expand All @@ -1114,7 +1114,7 @@ def get_connection(self, db_name=None):
self.conn = OpenSearch(
hosts=hosts,
http_auth=http_auth,
verify_certs=True, # 开启证书验证
verify_certs=self.instance.verify_ssl, # 开启证书验证
)
except Exception as e:
raise Exception(f"OpenSearch 连接建立失败: {str(e)}")
Expand Down
4 changes: 2 additions & 2 deletions sql/engines/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_connection(self, db_name=None):
encoding_errors="ignore",
decode_responses=True,
socket_connect_timeout=10,
ssl=self.is_ssl,
ssl=self.instance.is_ssl,
)
else:
return redis.Redis(
Expand All @@ -47,7 +47,7 @@ def get_connection(self, db_name=None):
encoding_errors="ignore",
decode_responses=True,
socket_connect_timeout=10,
ssl=self.is_ssl,
ssl=self.instance.is_ssl,
)

name = "Redis"
Expand Down

0 comments on commit b1efe08

Please sign in to comment.