netmetr-proxy
Helper proxy to sit between netmetr web client and backend. Adds a token/key and calls backend for:
- Monthly stats approval
- Uncleaned data download
browser netmetr-proxy backend
| | |
| GET | POST |
| --- month ----> | --- month-------> |
| + year | + year |
| | + token |
| | |
| <-- response -- | <-- response ---- |
| (zip or json) | |
| | |
It also adds some input validation, since the backend will happily return empty CSVs for future dates or even a .zip file with plaintext "illegal parameters" content.
Dependencies
- Python >= 3.6
- pyaml >= 17
- flask >= 0.12
Installation
$ virtualenv -p `which python3.6` .venv
$ source .venv/bin/activate
$ pip install netmetr_proxy
$ cp config.example.yml config.yml
$ $EDITOR config.yml # set backend url & access token
Running in production
uWSGI:
$ uwsgi --master --single-interpreter --threads 2 --http :5000 -H .venv -w netmetr_proxy.server
GUnicorn:
$ gunicorn -w 2 -k gevent --timeout 160 -n netmetr-proxy netmetr_proxy:server:app
Usage
Downloading uncleaned open data
GET /opendata
month <int>
year <int>
Returns opendata ZIP for download (NetMetr-opendata-dirty-{year}-{month}.zip).
Monthly stats approval
GET /approve
month <int>
year <int>
Returns:
GET /approve?year=2018&month=3
-> 200
{"success": true, "message": "Results for 2018-03 were successfully approved."}
if called again:
GET /approve?year=2018&month=3
-> 200
{"success": true, "message": "Results for 2018-03 were already approved before."}
Error responses
Returns errors from backend wrapped in 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!'}
Returns HTTP 400 and an error message for missing invalid params (bad format or future date):
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).'}
Returns 404 for any non-existing endpoint:
GET /
-> 404
GET /foo
-> 404
Development
Starting server with auto reload on file changes:
$ FLASK_APP=netmetr_proxy/server.py FLASK_DEBUG=1 flask run
Linting Python code:
$ flake8 --config=.flake8rc *py
License
GPLv3
Metadata
Release files for netmetr-proxy 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| netmetr-proxy-0.1.3.tar.gz | 19.1 kB | Without provenance | Details |
Release files / netmetr-proxy-0.1.3.tar.gz
| Download URL | netmetr-proxy-0.1.3.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
091b4810565324ecd00ddaad3d006087c0e6436456326a34d0bfb83364041324
|
|
BLAKE2b-256 checksum How to use checksums |
1c630251071bbafe8b03d34f6a263edf7e9560a381267971712ac9db903050aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.12
|
Security for netmetr-proxy 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.