mirror of https://github.com/jumpserver/jumpserver
fix: es使用https报错
parent
3608b025e5
commit
0a0312695b
|
@ -16,7 +16,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from django.db.models import QuerySet as DJQuerySet
|
from django.db.models import QuerySet as DJQuerySet
|
||||||
from elasticsearch7 import Elasticsearch
|
from elasticsearch7 import Elasticsearch
|
||||||
from elasticsearch7.helpers import bulk
|
from elasticsearch7.helpers import bulk
|
||||||
from elasticsearch7.exceptions import RequestError
|
from elasticsearch7.exceptions import RequestError, SSLError
|
||||||
from elasticsearch7.exceptions import NotFoundError as NotFoundError7
|
from elasticsearch7.exceptions import NotFoundError as NotFoundError7
|
||||||
|
|
||||||
from elasticsearch8.exceptions import NotFoundError as NotFoundError8
|
from elasticsearch8.exceptions import NotFoundError as NotFoundError8
|
||||||
|
@ -40,11 +40,16 @@ class NotSupportElasticsearch8(JMSException):
|
||||||
default_detail = _('Not Support Elasticsearch8')
|
default_detail = _('Not Support Elasticsearch8')
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidElasticsearchSSL(JMSException):
|
||||||
|
default_code = 'invalid_elasticsearch_SSL'
|
||||||
|
default_detail = _(
|
||||||
|
'Connection failed: Self-signed certificate used. Please check server certificate configuration')
|
||||||
|
|
||||||
|
|
||||||
class ESClient(object):
|
class ESClient(object):
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
hosts = kwargs.get('hosts', [])
|
version = get_es_client_version(**kwargs)
|
||||||
version = get_es_client_version(hosts=hosts)
|
|
||||||
if version == 6:
|
if version == 6:
|
||||||
return ESClientV6(*args, **kwargs)
|
return ESClientV6(*args, **kwargs)
|
||||||
if version == 7:
|
if version == 7:
|
||||||
|
@ -95,11 +100,16 @@ class ESClientV8(ESClientBase):
|
||||||
return {field: {'order': direction}}
|
return {field: {'order': direction}}
|
||||||
|
|
||||||
|
|
||||||
def get_es_client_version(hosts, **kwargs):
|
def get_es_client_version(**kwargs):
|
||||||
es = Elasticsearch(hosts=hosts, max_retries=0, **kwargs)
|
try:
|
||||||
info = es.info()
|
es = Elasticsearch(**kwargs)
|
||||||
version = int(info['version']['number'].split('.')[0])
|
info = es.info()
|
||||||
return version
|
version = int(info['version']['number'].split('.')[0])
|
||||||
|
return version
|
||||||
|
except SSLError:
|
||||||
|
raise InvalidElasticsearchSSL
|
||||||
|
except Exception:
|
||||||
|
raise InvalidElasticsearch
|
||||||
|
|
||||||
|
|
||||||
class ES(object):
|
class ES(object):
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:e4baadc170ded5134bed55533c4c04e694be6ea7b8e151d80c1092728e26a75b
|
oid sha256:4c47b806817e09e63c804277a1a2db8bdf959807e482605322be323922c38209
|
||||||
size 177500
|
size 177735
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:08667579241592ecacd1baf330147a720a9e41171444b925f90778613a7e1d9a
|
oid sha256:d83f99f39e0052ea2592a3f5bb4be56a94be0963436b45031083891c44a44ba0
|
||||||
size 145230
|
size 145454
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:93fed3f6a027f645520852f40c5f7722a5be579a3a8bb7b7029e3d0bc9794056
|
oid sha256:9021dd51a99b425416105a1e2a5b7b63f6725dec2de3b124a0520e4e1a09003f
|
||||||
size 145341
|
size 145565
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue