Skip to content
Snippets Groups Projects
Commit f384a9da authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add RQ Dashboard blueprint

- RQ Dashboard shall only be accessible to admin users
- "REDIS_URL" is hard-coded in rq-dashboard (had to rename RQ_REDIS_URL)
parent a17dfd20
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,7 @@ def register_cli(app):
@app.cli.command()
def runworker():
"""Run RQ worker"""
redis_url = current_app.config['RQ_REDIS_URL']
redis_url = current_app.config['REDIS_URL']
redis_connection = redis.from_url(redis_url)
with rq.Connection(redis_connection):
worker = rq.Worker(current_app.config['QUEUES'])
......
......@@ -10,6 +10,7 @@ Create the WSGI application.
"""
import sqlalchemy as sa
import rq_dashboard
from flask import Flask
from whitenoise import WhiteNoise
from . import settings, models
......@@ -30,6 +31,7 @@ from .commands import register_cli
def create_app(config=None):
app = Flask(__name__)
app.config.from_object(rq_dashboard.default_settings)
app.config.from_object(settings)
app.config.from_envvar('LOCAL_SETTINGS', silent=True)
app.config.update(config or {})
......@@ -118,6 +120,7 @@ def create_app(config=None):
app.register_blueprint(user_api, url_prefix='/api/v1/user')
app.register_blueprint(inventory_api, url_prefix='/api/v1/inventory')
app.register_blueprint(network_api, url_prefix='/api/v1/network')
app.register_blueprint(rq_dashboard.blueprint, url_prefix='/rq')
app.wsgi_app = WhiteNoise(app.wsgi_app, root='static/')
app.wsgi_app.add_files(
......
......@@ -11,14 +11,23 @@ This module implements the main blueprint.
"""
import os
import redis
from flask import Blueprint, render_template, jsonify, g, current_app
from flask_login import login_required
import rq_dashboard
from flask import Blueprint, render_template, jsonify, g, current_app, abort
from flask_login import login_required, current_user
from rq import push_connection, pop_connection
from .. import utils
bp = Blueprint('main', __name__)
# Allow only admin to access the RQ Dashboard
@rq_dashboard.blueprint.before_request
@login_required
def before_request():
if not current_user.is_admin:
abort(403)
# Declare custom error handlers for all views
@bp.app_errorhandler(403)
def forbidden_error(error):
......@@ -63,7 +72,7 @@ def modified_static_file(endpoint, values):
def get_redis_connection():
redis_connection = getattr(g, '_redis_connection', None)
if redis_connection is None:
redis_url = current_app.config['RQ_REDIS_URL']
redis_url = current_app.config['REDIS_URL']
redis_connection = g._redis_connection = redis.from_url(redis_url)
return redis_connection
......
......@@ -30,7 +30,7 @@ SESSION_TYPE = 'redis'
SESSION_REDIS_URL = 'redis://redis:6379/0'
CACHE_TYPE = 'redis'
CACHE_REDIS_URL = 'redis://redis:6379/1'
RQ_REDIS_URL = 'redis://redis:6379/2'
REDIS_URL = 'redis://redis:6379/2'
QUEUES = ['default']
LDAP_HOST = 'esss.lu.se'
......
......@@ -28,6 +28,7 @@
<a class="nav-item nav-link {{ is_active(path.startswith("/network")) }}" href="{{ url_for('network.list_hosts') }}">Network</a>
{% if current_user.is_authenticated and current_user.is_admin %}
<a class="nav-item nav-link" href="{{ url_for('admin.index') }}">Admin</a>
<a class="nav-item nav-link" href="{{ url_for('rq_dashboard.overview') }}">RQ Dashboard</a>
{% endif %}
<a class="nav-item nav-link" href="{{ config['DOCUMENTATION_URL'] }}" target="_blank">Help</a>
</div>
......
......@@ -96,6 +96,7 @@ dependencies:
- ecdsa=0.13=py36_0
- pip:
- ansible-tower-cli==3.2.1
- arrow==0.12.1
- dominate==2.3.1
- email-validator==1.0.2
- git+https://github.com/beenje/flask-bootstrap@4.0.0.0.dev1
......@@ -107,6 +108,7 @@ dependencies:
- inflection==0.3.1
- pytest-factoryboy==2.0.1
- rq==0.10.0
- rq-dashboard==0.3.10
- sphinxcontrib-httpdomain==1.6.0
- sqlalchemy-citext==1.3.post0
- sqlalchemy-continuum==1.3.3
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment