Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
4e2dfd87
Commit
4e2dfd87
authored
Nov 04, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
e520934a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
20 deletions
+33
-20
application/libs/flask_elasticsearch/elasticsearch.py
application/libs/flask_elasticsearch/elasticsearch.py
+33
-20
No files found.
application/libs/flask_elasticsearch/elasticsearch.py
View file @
4e2dfd87
...
...
@@ -73,29 +73,42 @@ class FlaskElasticsearch:
return
getattr
(
ctx
.
elasticsearch
,
item
)
@
staticmethod
def
_get_config
()
:
"""
Retrieves
Elasticsearch configuration from the current Flask application context."""
def
get_es_config
()
->
dict
:
"""
Get
Elasticsearch configuration from the current Flask application context."""
with
current_app
.
app_context
():
if
current_app
:
config_helper
=
ConfigHelper
(
current_app
)
cfg
=
config_helper
.
Elasticsearch
host
=
cfg
.
Host
or
'localhost'
port
=
int
(
cfg
.
Port
)
or
9200
user
=
cfg
.
User
or
None
password
=
cfg
.
Password
or
None
use_ssl
=
cfg
.
UseSsl
==
'True'
or
False
verify_certs
=
cfg
.
VerifyCerts
==
'False'
ca_certs
=
cfg
.
CaCerts
or
None
options
=
dict
(
hosts
=
[{
'host'
:
host
,
'port'
:
port
}],
http_auth
=
None
if
not
user
else
(
user
,
password
),
use_ssl
=
use_ssl
,
verify_certs
=
verify_certs
,
ca_certs
=
ca_certs
)
return
options
return
config_helper
.
Elasticsearch
else
:
logger
.
error
(
'Attempted to access application configuration outside of application context.'
)
raise
RuntimeError
(
'Attempted to access application configuration outside of application context.'
)
@
staticmethod
def
build_es_options
(
cfg
)
->
dict
:
"""
Build Elasticsearch connection options from the configuration.
:param cfg: Elasticsearch's configuration from the Flask application context.
"""
host
=
cfg
.
get
(
'Host'
,
'localhost'
)
port
=
int
(
cfg
.
get
(
'Port'
,
9200
))
user
=
cfg
.
get
(
'User'
)
password
=
cfg
.
get
(
'Password'
)
use_ssl
=
cfg
.
get
(
'UseSsl'
,
'False'
)
==
'True'
verify_certs
=
cfg
.
get
(
'VerifyCerts'
,
'False'
)
==
'True'
ca_certs
=
cfg
.
get
(
'CaCerts'
)
options
=
{
'hosts'
:
[{
'host'
:
host
,
'port'
:
port
}],
'http_auth'
:
(
user
,
password
)
if
user
and
password
else
None
,
'use_ssl'
:
use_ssl
,
'verify_certs'
:
verify_certs
,
'ca_certs'
:
ca_certs
}
return
options
def
_get_config
(
self
)
->
dict
:
"""Combines getting Elasticsearch configuration and building options."""
cfg
=
self
.
get_es_config
()
return
self
.
build_es_options
(
cfg
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment