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
96c23853
Commit
96c23853
authored
Nov 04, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
5a67515b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
application/common/config.py
application/common/config.py
+10
-5
application/lib/flask_elasticsearch/elasticsearch.py
application/lib/flask_elasticsearch/elasticsearch.py
+3
-3
application/views/user/user.py
application/views/user/user.py
+4
-0
No files found.
application/common/config.py
View file @
96c23853
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
from
typing
import
Any
from
typing
import
Any
from
flask
import
Flask
from
flask
import
Flask
from
loguru
import
logger
class
ConfigHelper
:
class
ConfigHelper
:
...
@@ -27,14 +28,18 @@ class ConfigHelper:
...
@@ -27,14 +28,18 @@ class ConfigHelper:
def
__init__
(
self
,
app
:
Flask
):
def
__init__
(
self
,
app
:
Flask
):
self
.
app
=
app
self
.
app
=
app
def
get_config
(
self
,
key
:
str
)
->
Any
:
def
__getattr__
(
self
,
name
)
:
"""
"""
Fetch a config value based on the provided key
.
Get a config value as an attribute
.
:param
key: The key for the config value
.
:param
name: The name of the config key
.
:return: The value for the provided key.
:return: The value for the provided key
, or None if it does not exist
.
"""
"""
return
self
.
app
.
config
.
get
(
key
)
try
:
return
self
.
app
.
config
[
name
]
except
KeyError
:
logger
.
error
(
f
'Key
{
name
}
error'
)
raise
KeyError
(
f
'Key
{
name
}
error'
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
f
"<ConfigHelper with app
{
self
.
app
}
>"
return
f
"<ConfigHelper with app
{
self
.
app
}
>"
...
...
application/lib/flask_elasticsearch/elasticsearch.py
View file @
96c23853
...
@@ -50,8 +50,8 @@ class FlaskElasticsearch:
...
@@ -50,8 +50,8 @@ class FlaskElasticsearch:
if
ctx
.
elasticsearch
.
ping
():
if
ctx
.
elasticsearch
.
ping
():
logger
.
info
(
'Connected to Elasticsearch'
)
logger
.
info
(
'Connected to Elasticsearch'
)
else
:
else
:
logger
.
error
(
'C
onnected
to Elasticsearch'
)
logger
.
error
(
'C
an not connect
to Elasticsearch'
)
raise
ConnectionError
(
'C
onnected
to Elasticsearch'
)
raise
ConnectionError
(
'C
an not connect
to Elasticsearch'
)
return
getattr
(
ctx
.
elasticsearch
,
item
)
return
getattr
(
ctx
.
elasticsearch
,
item
)
@
staticmethod
@
staticmethod
...
@@ -60,7 +60,7 @@ class FlaskElasticsearch:
...
@@ -60,7 +60,7 @@ class FlaskElasticsearch:
with
current_app
.
app_context
():
with
current_app
.
app_context
():
if
current_app
:
if
current_app
:
config_helper
=
ConfigHelper
(
current_app
)
config_helper
=
ConfigHelper
(
current_app
)
cfg
=
config_helper
.
get_config
(
'Elasticsearch'
)
cfg
=
config_helper
.
Elasticsearch
if
cfg
is
None
:
if
cfg
is
None
:
raise
KeyError
(
'Key Elasticsearch is not defined'
)
raise
KeyError
(
'Key Elasticsearch is not defined'
)
...
...
application/views/user/user.py
View file @
96c23853
...
@@ -17,6 +17,7 @@ from marshmallow import ValidationError
...
@@ -17,6 +17,7 @@ from marshmallow import ValidationError
from
application.schemas
import
UserSchema
from
application.schemas
import
UserSchema
from
application.utils
import
ElasticsearchUtils
from
application.utils
import
ElasticsearchUtils
from
application.common
import
ConfigHelper
user_api
=
Blueprint
(
'user_api'
,
__name__
)
user_api
=
Blueprint
(
'user_api'
,
__name__
)
...
@@ -51,6 +52,9 @@ def create_user():
...
@@ -51,6 +52,9 @@ def create_user():
@
user_api
.
route
(
'/tests'
,
methods
=
[
'POST'
])
@
user_api
.
route
(
'/tests'
,
methods
=
[
'POST'
])
def
test_user
():
def
test_user
():
ch
=
ConfigHelper
(
current_app
)
print
(
ch
.
System
)
print
(
ch
.
Sys
)
data
=
request
.
get_json
()
data
=
request
.
get_json
()
start
=
data
.
get
(
'start'
)
start
=
data
.
get
(
'start'
)
end
=
data
.
get
(
'end'
)
end
=
data
.
get
(
'end'
)
...
...
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