位于netmetr web客户端和后端之间的助手代理。添加令牌/密钥并调用后端。
netmetr-prox的Python项目详细描述
netmetr-proxy
位于netmetrweb客户端和后端之间的助手代理。添加令牌/密钥并调用后端:
- 月度统计审批
- 未清理数据下载
browser netmetr-proxy backend
| | |
| GET | POST |
| --- month ----> | --- month-------> |
| + year | + year |
| | + token |
| | |
| <-- response -- | <-- response ---- |
| (zip or json) | |
| | |
它还添加了一些输入验证,因为后端很乐意为将来的日期返回空的csv,甚至返回一个带有明文"illegal parameters"
内容的.zip
文件。在
依赖关系
- Python>;=3.6
- pyaml>;=17
- 烧瓶>;=0.12
安装
^{pr2}$试生产
威斯康星州:
$ uwsgi --master --single-interpreter --threads 2 --http :5000 -H .venv -w netmetr_proxy.server
古尼科恩:
$ gunicorn -w 2 -k gevent --timeout 160 -n netmetr-proxy netmetr_proxy:server:app
使用
下载未清理的开放数据
GET /opendata
month <int>
year <int>
返回opendata ZIP以供下载(NetMetr-opendata-dirty-{year}-{month}.zip
)。在
月度统计批准
GET /approve
month <int>
year <int>
退货:
GET /approve?year=2018&month=3
-> 200
{"success": true, "message": "Results for 2018-03 were successfully approved."}
如果再次调用:
GET /approve?year=2018&month=3
-> 200
{"success": true, "message": "Results for 2018-03 were already approved before."}
错误响应
返回用JSON包装的后端错误:
GET /opendata?year=2018&month=1
# invalid key in config results in "ERROR: invalid key!" message
# from backend (with HTTP 200 for some reason…)
-> 403
{'error': 'invalid key!'}
返回HTTP 400和错误消息,说明缺少无效参数(格式错误或未来日期):
GET /opendata?year=2018&month=0
-> 400
{'error': 'Invalid date.'}
GET /opendata?year=0&month=march
-> 400
{'error': 'Invalid date.'}
GET /approve?year=2018
-> 400
{'error': 'Missing or invalid parameter (year, month).'}
对于任何不存在的终结点,返回404:
GET /
-> 404
GET /foo
-> 404
发展
在文件更改时自动重新加载启动服务器:
$ FLASK_APP=netmetr_proxy/server.py FLASK_DEBUG=1 flask run
Linting Python代码:
$ flake8 --config=.flake8rc *py
许可证
GPLv3
- 项目
标签: