Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 (src/): fix logout function #33

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 112 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ flask = "^3.0.3"
authlib = "^1.3.1"
python-dotenv = "^1.0.1"
redis = "^5.0.8"
flask-socketio = "^5.4.1"


[tool.poetry.group.docs.dependencies]
Expand Down
3 changes: 3 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from logging.config import dictConfig

Check failure on line 1 in src/app.py

View workflow job for this annotation

GitHub Actions / Pylint

src/app.py#L1

Missing module docstring (missing-module-docstring, C0114)
from authlib.integrations.flask_client import OAuth
from flask import Flask
from flask_socketio import SocketIO #, emit
from .db_redis import DBManager
# from .db import DBManager

Expand Down Expand Up @@ -39,14 +40,14 @@
app.logger.debug("Loading configs from envs")
app.config.from_object('src.config')

app.logger.debug(f"Setting secret key: {app.config['SECRET_KEY']}")

Check failure on line 43 in src/app.py

View workflow job for this annotation

GitHub Actions / Pylint

src/app.py#L43

Use lazy % formatting in logging functions (logging-fstring-interpolation, W1203)
app.secret_key = app.config['SECRET_KEY']

app.logger.debug("Setting REDIS ip and password: %s %s", app.config['REDIS_IP'], app.config['REDIS_PASSWORD'])

Check failure on line 46 in src/app.py

View workflow job for this annotation

GitHub Actions / Pylint

src/app.py#L46

Line too long (110/100) (line-too-long, C0301)
app.redis_ip = app.config['REDIS_IP']
app.redis_password = app.config['REDIS_PASSWORD']

app.logger.debug("Setting LDAPSYNC ip and port: %s %s", app.config['LDAPSYNC_IP'], app.config['LDAPSYNC_PORT'])

Check failure on line 50 in src/app.py

View workflow job for this annotation

GitHub Actions / Pylint

src/app.py#L50

Line too long (111/100) (line-too-long, C0301)
app.ldapsync_ip = app.config['LDAPSYNC_IP']
app.ldapsync_port = app.config['LDAPSYNC_PORT']

Expand All @@ -67,4 +68,6 @@
}
)

app.logger.debug("OAUTH CONFIGS: %s", oauth._registry)

Check failure on line 71 in src/app.py

View workflow job for this annotation

GitHub Actions / Pylint

src/app.py#L71

Access to a protected member _registry of a client class (protected-access, W0212)

socketio = SocketIO(app)
16 changes: 11 additions & 5 deletions src/routes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from flask import url_for, session, request, render_template, redirect

Check failure on line 1 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L1

Missing module docstring (missing-module-docstring, C0114)
from .app import app, dbms, oauth
from .app import app, dbms, oauth, socketio
import requests


@app.route('/', methods=['GET', 'POST', 'DELETE'])
def homepage():

Check failure on line 7 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L7

Missing function or method docstring (missing-function-docstring, C0116)
user = session.get('user')

app.logger.debug(f"/ User value: {user}")

Check failure on line 10 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L10

Use lazy % formatting in logging functions (logging-fstring-interpolation, W1203)

if user:
_username = user['metadata']['name']
Expand All @@ -24,12 +25,12 @@

if request.method == 'POST':
user_to_update = request.form['id']
app.logger.debug(f"UPDATING USER {user_to_update} REQUEST")

Check failure on line 28 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L28

Use lazy % formatting in logging functions (logging-fstring-interpolation, W1203)

dbms.update_request_status(user_to_update)

user['request_data'] = dbms.get_all_request_data()
app.logger.debug(f"ADMIN REQUEST DATA: {user['request_data']}")

Check failure on line 33 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L33

Use lazy % formatting in logging functions (logging-fstring-interpolation, W1203)

return render_template('users/admin.html', user=user)

Expand All @@ -45,7 +46,7 @@
print(request.method)

user['request_data'] = dbms.get_request_data(_username)
app.logger.debug(f"USER REQUEST DATA: {user['request_data']}")

Check failure on line 49 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L49

Use lazy % formatting in logging functions (logging-fstring-interpolation, W1203)

return render_template('users/user.html', user=user)

Expand All @@ -53,7 +54,7 @@


@app.route('/login')
def login():

Check failure on line 57 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L57

Missing function or method docstring (missing-function-docstring, C0116)
app.logger.debug('Redirecting to Vault')
redirect_uri = url_for('auth', _external=True, _scheme='https')

Expand All @@ -63,17 +64,17 @@


@app.route('/auth')
def auth():

Check failure on line 67 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L67

Missing function or method docstring (missing-function-docstring, C0116)
try:
token = oauth.vault.authorize_access_token()

except Exception as e: # TODO: choose better Exception

Check failure on line 71 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L71

TODO: choose better Exception (fixme, W0511)

Check failure on line 71 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L71

Catching too general exception Exception (broad-exception-caught, W0718)
app.logger.error("Error while autorizing access token, %s", e)

return redirect(url_for('homepage'))

app.logger.debug('Success user auth')
app.logger.debug(f'Token: {token}')

Check failure on line 77 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L77

Use lazy % formatting in logging functions (logging-fstring-interpolation, W1203)

session['user'] = token['userinfo']
session['token'] = token
Expand All @@ -81,19 +82,24 @@
return redirect(url_for('homepage'))

@app.route('/logout')
def logout():

Check failure on line 85 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L85

Missing function or method docstring (missing-function-docstring, C0116)
token = session.get('token')

app.logger.debug(f'Logging out {token}')

Check failure on line 88 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L88

Use lazy % formatting in logging functions (logging-fstring-interpolation, W1203)

oauth.vault.post('auth/token/revoke-self', token=token)
oauth.vault.post('auth/token/revoke', token=token)

app.logger.debug('Cleaning session values')
session.pop('user', None)
session.pop('token', None)
session.clear()

return redirect('/')

@socketio.on('disconnect')
def on_session_close():

Check failure on line 97 in src/routes.py

View workflow job for this annotation

GitHub Actions / Pylint

src/routes.py#L97

Missing function or method docstring (missing-function-docstring, C0116)
logout()

app.logger.debug('Calling Vault to Logout')
_ = requests.get(url="https://vault.unipg.it/ui/vault/logout")

@app.route('/info')
def info():
return render_template('info.html')
Expand Down
2 changes: 1 addition & 1 deletion src/templates/users/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block body %}
<h3>Welcome {{user['infos'].get('name', user['username'])}}</h3>

<div class="position-absolute top-50 start-50 translate-middle">
<div class="d-flex justify-content-center">
<a href="{{ user['uninuvolaurl'] }}"><button type="button" class="btn btn-primary btn-lg">
Start computing
<i class="bi bi-rocket-takeoff-fill"></i>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/users/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h3 class="mt-5">Request status</h3>

{% else %}
{% if user['request_data']['status'] == 'synced' %}
<div class="position-absolute top-50 start-50 translate-middle">
<div class="d-flex justify-content-center">
<a href="{{ user['uninuvolaurl'] }}"><button type="button" class="btn btn-primary btn-lg fs-1">
Start computing
<i class="bi bi-rocket-takeoff-fill"></i>
Expand Down
Loading