-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
44 lines (31 loc) · 1.11 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Simple Flask web service to test authz flows."""
from logging import basicConfig, NOTSET
from os import environ as env
from flask import Flask
from ..decorators import auth_required, auth_user
from .. import service
app = Flask(__name__)
@app.route("/")
@auth_required
def index():
"""Send ok if authorized as any user."""
return "ok\n", 200
@app.route("/protected")
@auth_required(users=["admin"])
def protected():
"""Greet admin; reject others."""
return "hello admin\n", 200
@app.route("/<username>/account")
@auth_user
def account_settings(username):
"""Show a message only to the authorized user whose name matches the USERNAME param."""
return "set your password", 200
@app.route("/<user>/history")
@auth_user(arg="user")
def user_history(user):
"""Show a message only to the authz user whose name matches the USER param."""
return "set your password", 200
login = app.route("/login", methods=["POST"])(service.login)
logout = app.route("/logout", methods=["POST"])(service.logout)
basicConfig(filename=f"{env.get('TEST_DATA_DIR', '.')}/wsgi.log", level=NOTSET)
app.run(debug=True)