File: httpauth_example.py

package info (click to toggle)
prometheus-flask-exporter 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 896 kB
  • sloc: python: 2,889; sh: 709; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from flask import Flask
from flask_httpauth import HTTPBasicAuth
from prometheus_flask_exporter import PrometheusMetrics

app = Flask(__name__)
auth = HTTPBasicAuth()
metrics = PrometheusMetrics(app, metrics_decorator=auth.login_required)


@auth.verify_password
def verify_credentials(username, password):
    return (username, password) in {('metrics', 'test'), ('user', 'pass')}


@app.route('/test')
@auth.login_required
def index():
    return 'Hello world'


if __name__ == '__main__':
    app.run('0.0.0.0', 4000)