Skip to content

Commit

Permalink
Fix debug mode for anitya
Browse files Browse the repository at this point in the history
Let's use the debug value in anitya config file as the flask app.debug
is not working as expected.

Signed-off-by: Michal Konecny <[email protected]>
  • Loading branch information
Zlopez committed Dec 12, 2024
1 parent 25b11cf commit abd7b77
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ up:
$(MAKE) init-db
@echo "Empty database initialized. Run dump-restore to fill it by production dump."
restart:
$(MAKE) halt && $(call compose-tool) up -d
$(MAKE) halt && $(MAKE) up
halt:
$(call compose-tool) down -t1
bash-web:
Expand Down
2 changes: 1 addition & 1 deletion anitya/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def create(config=None):

# Debug related initialization
# WARNING: For debug and development purpose only
if app.debug: # pragma: no cover
if anitya_config["DEBUG"]: # pragma: no cover
app.register_blueprint(debug.debug_blueprint)

oauth = OAuth(app)
Expand Down
2 changes: 2 additions & 0 deletions anitya/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
SECRET_KEY="changeme please",
# URL to the database
DB_URL="sqlite:////var/tmp/anitya-dev.sqlite",
# DEBUG mode
DEBUG=False,
# List of admins based on their openid
ANITYA_WEB_ADMINS=[],
ADMIN_EMAIL="[email protected]",
Expand Down
10 changes: 0 additions & 10 deletions anitya/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,4 @@
</a>
{% endfor %}
</div>
{% if config["DEBUG"] %}
<div class="d-flex align-itmes-start gap-3">
<a title="user" class="btn btn-outline-primary" role="button" href="{{ url_for('anitya_debug.login', name='user') }}">
<span>User</span>
</a>
<a title="admin" class="btn btn-outline-primary" role="button" href="{{ url_for('anitya_debug.login', name='admin') }}">
<span>Admin</span>
</a>
</div>
{% endif %}
{% endblock %}
14 changes: 14 additions & 0 deletions anitya/templates/login_debug.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "master.html" %}

{% block title %}Login · Anitya{% endblock %}

{% block body %}
<div class="d-flex align-itmes-start gap-3">
<a title="user" class="btn btn-outline-primary" role="button" href="{{ url_for('anitya_debug.login', name='user') }}">
<span>User</span>
</a>
<a title="admin" class="btn btn-outline-primary" role="button" href="{{ url_for('anitya_debug.login', name='admin') }}">
<span>Admin</span>
</a>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions anitya/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_full_config_file(self, mock_exists, mock_log):
"SECRET_KEY": "very_secret",
"PERMANENT_SESSION_LIFETIME": timedelta(seconds=3600),
"DB_URL": "sqlite:////var/tmp/anitya-dev.sqlite",
"DEBUG": False,
"ANITYA_WEB_ADMINS": ["http://pingou.id.fedoraproject.org"],
"ADMIN_EMAIL": "[email protected]",
"ANITYA_LOG_CONFIG": {
Expand Down
2 changes: 2 additions & 0 deletions anitya/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def login():
next_url = "/"

flask.session["next_url"] = next_url
if anitya_config["DEBUG"]: # pragma: no cover
return flask.render_template("login_debug.html")
return flask.render_template("login.html")


Expand Down
3 changes: 3 additions & 0 deletions files/anitya.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ permanent_session_lifetime = 3600
# URL to the database
db_url = "sqlite:////var/tmp/anitya-dev.sqlite"

# Anitya DEBUG mode
debug = false

# List of web administrators. The values should be the value of the "id" column
# for the user in the "users" table of the database. They need to log in before
# this record is created. An example value would be
Expand Down

0 comments on commit abd7b77

Please sign in to comment.