Merge pull request #14 from YunoHost-Apps/remove-deps1

Make some dependencies optional
This commit is contained in:
Jens Diemer 2021-01-19 18:21:20 +01:00 committed by GitHub
commit 3292fba03d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 18 deletions

View file

@ -121,8 +121,10 @@ Notes:
## history
* [compare v0.1.4...master](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.4...master) **dev**
* [compare v0.1.5...master](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.5...master) **dev**
* tbc
* [v0.1.5 - 17.01.2021](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.4...v0.1.5)
* Make some deps `gunicorn`, `psycopg2-binary`, `django-redis`, `django-axes` optional
* [v0.1.4 - 08.01.2021](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.3...v0.1.4)
* Bugfix [CSRF verification failed on POST requests #7](https://github.com/YunoHost-Apps/django_ynh/issues/7)
* [v0.1.3 - 08.01.2021](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.2...v0.1.3)

View file

@ -1 +1 @@
__version__ = '0.1.4'
__version__ = '0.1.5'

View file

@ -1,12 +1,17 @@
import base64
import logging
from axes.exceptions import AxesBackendPermissionDenied
from django.conf import settings
from django.contrib import auth
from django.contrib.auth import get_user_model
from django.contrib.auth.middleware import RemoteUserMiddleware
try:
from axes.exceptions import AxesBackendPermissionDenied as SuspiciousOperation # log to Axes DB models
except ImportError:
from django.core.exceptions import SuspiciousOperation
from django_ynh.sso_auth.user_profile import call_setup_user, update_user_profile
@ -50,38 +55,38 @@ class SSOwatRemoteUserMiddleware(RemoteUserMiddleware):
else:
# emits a signal indicating user login failed, which is processed by
# axes.signals.log_user_login_failed which logs and flags the failed request.
raise AxesBackendPermissionDenied('Cookie missing')
raise SuspiciousOperation('Cookie missing')
else:
logger.info('SSOwat username from cookies: %r', username)
if username != user.username:
raise AxesBackendPermissionDenied('Wrong username')
raise SuspiciousOperation('Wrong username')
# Compare with HTTP_AUTH_USER
try:
username = request.META['HTTP_AUTH_USER']
except KeyError:
logger.error('HTTP_AUTH_USER missing!')
raise AxesBackendPermissionDenied('No HTTP_AUTH_USER')
raise SuspiciousOperation('No HTTP_AUTH_USER')
if username != user.username:
raise AxesBackendPermissionDenied('Wrong HTTP_AUTH_USER username')
raise SuspiciousOperation('Wrong HTTP_AUTH_USER username')
# Also check 'HTTP_AUTHORIZATION', but only the username ;)
try:
authorization = request.META['HTTP_AUTHORIZATION']
except KeyError:
logger.error('HTTP_AUTHORIZATION missing!')
raise AxesBackendPermissionDenied('No HTTP_AUTHORIZATION')
raise SuspiciousOperation('No HTTP_AUTHORIZATION')
scheme, creds = authorization.split(' ', 1)
if scheme.lower() != 'basic':
logger.error('HTTP_AUTHORIZATION with %r not supported', scheme)
raise AxesBackendPermissionDenied('HTTP_AUTHORIZATION scheme not supported')
raise SuspiciousOperation('HTTP_AUTHORIZATION scheme not supported')
creds = str(base64.b64decode(creds), encoding='utf-8')
username = creds.split(':', 1)[0]
if username != user.username:
raise AxesBackendPermissionDenied('Wrong HTTP_AUTHORIZATION username')
raise SuspiciousOperation('Wrong HTTP_AUTHORIZATION username')
if not was_authenticated:
# First request, after login -> update user informations

View file

@ -5,7 +5,7 @@
"description": {
"en": "Glue code to package django projects as yunohost apps."
},
"version": "0.1.4~ynh1",
"version": "0.1.5~ynh1",
"url": "https://github.com/jedie/django_ynh",
"license": "GPL-3.0",
"maintainer": {

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "django_ynh"
version = "0.1.4"
version = "0.1.5"
description = "Glue code to package django projects as yunohost apps."
authors = ["JensDiemer <git@jensdiemer.de>"]
license = "GPL"
@ -14,12 +14,14 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.7,<4.0.0"
django = "*"
gunicorn = "*"
django-axes = "*" # https://github.com/jazzband/django-axes
psycopg2-binary = "*"
django-redis = "*"
# The follogin extra packages are used for install "django_ynh" as YunoHost app:
gunicorn = { version = "*", optional = true }
psycopg2-binary = { version = "*", optional = true }
django-redis = { version = "*", optional = true }
django-axes = { version = "*", optional = true } # https://github.com/jazzband/django-axes
[tool.poetry.dev-dependencies]
django-axes = "*" # https://github.com/jazzband/django-axes
poetry-publish = "*" # https://github.com/jedie/poetry-publish
bx_py_utils = "*"
tox = "*"
@ -33,6 +35,10 @@ flynt = "*"
black = "*"
pyupgrade = "*"
[tool.poetry.extras]
ynh = ["gunicorn", "psycopg2-binary", "django-redis", "django-axes"] # install as YunoHost app
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

View file

@ -28,7 +28,7 @@ log_file="${log_path}/django_ynh.log"
pkg_dependencies="build-essential python3-dev python3-pip python3-venv git postgresql postgresql-contrib"
# To install/upgrade this project via pip:
pip_install_string="django_ynh==0.1.4"
pip_install_string="django_ynh[ynh]==0.1.5"
#=================================================
# Redis HELPERS

View file

@ -32,7 +32,7 @@ def test_version(package_root=None, version=None):
assert_file_contains_string(file_path=Path(package_root, 'pyproject.toml'), string=f'version = "{version}"')
assert_file_contains_string(file_path=Path(package_root, 'manifest.json'), string=f'"version": "{version}~ynh')
assert_file_contains_string(
file_path=Path(package_root, 'scripts', '_common.sh'), string=f'"django_ynh=={version}"'
file_path=Path(package_root, 'scripts', '_common.sh'), string=f'"django_ynh[ynh]=={version}"'
)