Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3mon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
km3py
km3mon
Commits
f351f35e
Commit
f351f35e
authored
6 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Add authentication option. Closes
#7
parent
82964e9f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/routes.py
+49
-2
49 additions, 2 deletions
app/routes.py
with
49 additions
and
2 deletions
app/routes.py
+
49
−
2
View file @
f351f35e
from
os.path
import
join
from
flask
import
render_template
,
send_from_directory
from
os.path
import
join
,
exists
from
functools
import
wraps
import
toml
from
flask
import
render_template
,
send_from_directory
,
request
,
Response
from
app
import
app
CONFIG_PATH
=
"
pipeline.toml
"
PLOTS_PATH
=
"
../plots
"
USERNAME
=
None
PASSWORD
=
None
app
.
config
[
'
FREEZER_DESTINATION
'
]
=
'
../km3web
'
PLOTS
=
[[
'
dom_activity
'
,
'
dom_rates
'
],
[
'
pmt_rates
'
,
'
pmt_hrv
'
],
...
...
@@ -13,6 +18,42 @@ TRIGGER_PLOTS = [['trigger_rates'], ['trigger_rates_lin']]
K40_PLOTS
=
[[
'
intradom
'
],
[
'
angular_k40rate_distribution
'
]]
RTTC_PLOTS
=
[[
'
rttc
'
]]
if
exists
(
CONFIG_PATH
):
config
=
toml
.
load
(
CONFIG_PATH
)
if
"
WebServer
"
in
config
:
print
(
"
Reading authentication information from
'
%s
'"
%
CONFIG_PATH
)
USERNAME
=
config
[
"
WebServer
"
][
"
username
"
]
PASSWORD
=
config
[
"
WebServer
"
][
"
password
"
]
def
check_auth
(
username
,
password
):
"""
This function is called to check if a username /
password combination is valid.
"""
if
USERNAME
is
not
None
and
PASSWORD
is
not
None
:
return
username
==
USERNAME
and
password
==
PASSWORD
else
:
return
True
def
authenticate
():
"""
Sends a 401 response that enables basic auth
"""
return
Response
(
'
Could not verify your access level for that URL.
\n
'
'
You have to login with proper credentials
'
,
401
,
{
'
WWW-Authenticate
'
:
'
Basic realm=
"
Login Required
"'
})
def
requires_auth
(
f
):
@wraps
(
f
)
def
decorated
(
*
args
,
**
kwargs
):
auth
=
request
.
authorization
if
not
auth
or
not
check_auth
(
auth
.
username
,
auth
.
password
):
return
authenticate
()
return
f
(
*
args
,
**
kwargs
)
return
decorated
@app.after_request
def
add_header
(
r
):
...
...
@@ -28,16 +69,19 @@ def add_header(r):
@app.route
(
'
/
'
)
@app.route
(
'
/index.html
'
)
@requires_auth
def
index
():
return
render_template
(
'
plots.html
'
,
plots
=
PLOTS
)
@app.route
(
'
/ahrs.html
'
)
@requires_auth
def
ahrs
():
return
render_template
(
'
plots.html
'
,
plots
=
AHRS_PLOTS
)
@app.route
(
'
/rttc.html
'
)
@requires_auth
def
rttc
():
return
render_template
(
'
plots.html
'
,
...
...
@@ -50,6 +94,7 @@ def rttc():
@app.route
(
'
/k40.html
'
)
@requires_auth
def
k40
():
return
render_template
(
'
plots.html
'
,
...
...
@@ -62,11 +107,13 @@ def k40():
@app.route
(
'
/trigger.html
'
)
@requires_auth
def
trigger
():
return
render_template
(
'
plots.html
'
,
plots
=
TRIGGER_PLOTS
)
@app.route
(
'
/plots/<path:filename>
'
)
@requires_auth
def
custom_static
(
filename
):
print
(
filename
)
filepath
=
join
(
app
.
root_path
,
PLOTS_PATH
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment