Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
django-yunohost-integration
Advanced tools
Python package django_yunohost_integration with helpers for integrate a Django project as YunoHost package.
A example usage of this package is here:
Pull requests welcome ;)
These projects used django_yunohost_integration
:
scripts/install
local_test
)test
against local_test
"installation"SSOwat is fully supported:
$YNH_APP_ARG_ADMIN
) will be created as Django's super userTo create/update the first user in install
/upgrade
, e.g.:
./manage.py create_superuser --username="$admin" --email="$admin_mail"
This Create/update Django superuser and set a unusable password. A password is not needed, because auth done via SSOwat ;)
Main parts in settings.py
:
from pathlib import Path as __Path
from django_yunohost_integration.base_settings import * # noqa
from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret
DEBUG = bool(int('__DEBUG_ENABLED__')) # Set via config_panel.toml
# -----------------------------------------------------------------------------
DATA_DIR_PATH = __Path('__DATA_DIR__') # /home/yunohost.app/$app
assert DATA_DIR_PATH.is_dir(), f'Directory not exists: {DATA_DIR_PATH}'
INSTALL_DIR_PATH = __Path('__INSTALL_DIR__') # /var/www/$app
assert INSTALL_DIR_PATH.is_dir(), f'Directory not exists: {INSTALL_DIR_PATH}'
LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app/$app.log
assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}'
PATH_URL = '__PATH_URL__' # $YNH_APP_ARG_PATH
PATH_URL = PATH_URL.strip('/')
# -----------------------------------------------------------------------------
# Function that will be called to finalize a user profile:
YNH_SETUP_USER = 'setup_user.setup_project_user'
SECRET_KEY = __get_or_create_secret(DATA_DIR_PATH / 'secret.txt') # /home/yunohost.app/$app/secret.txt
# INSTALLED_APPS.append('<insert-your-app-here>')
# -----------------------------------------------------------------------------
At least you have to set these settings:
from django_yunohost_integration.base_settings import * # noqa
INSTALLED_APPS.append('django_yunohost_integration')
MIDDLEWARE.insert(
MIDDLEWARE.index('django.contrib.auth.middleware.AuthenticationMiddleware') + 1,
# login a user via HTTP_REMOTE_USER header from SSOwat:
'django_yunohost_integration.sso_auth.auth_middleware.SSOwatRemoteUserMiddleware',
)
# Keep ModelBackend around for per-user permissions and superuser
AUTHENTICATION_BACKENDS = (
'axes.backends.AxesBackend', # AxesBackend should be the first backend!
#
# Authenticate via SSO and nginx 'HTTP_REMOTE_USER' header:
'django_yunohost_integration.sso_auth.auth_backend.SSOwatUserBackend',
#
# Fallback to normal Django model backend:
'django.contrib.auth.backends.ModelBackend',
)
LOGIN_REDIRECT_URL = None
LOGIN_URL = '/yunohost/sso/'
LOGOUT_REDIRECT_URL = '/yunohost/sso/'
# /yunohost/sso/?action=logout
ROOT_URLCONF = 'urls' # .../conf/urls.py
We install psycopg2
(a PostgreSQL adapter for the Python) that needs some build prerequisites, e.g.:
~$ sudo apt install build-essential python3-dev libpq-dev
For quicker developing of django_yunohost_integration in the context of YunoHost app, it's possible to run the Django developer server with the settings and urls made for YunoHost installation.
e.g.:
~$ git clone https://github.com/YunoHost-Apps/django_yunohost_integration.git
~$ cd django_yunohost_integration/
~/django_yunohost_integration$ ./dev-cli.py
For quicker developing of django_yunohost_integration in the context of YunoHost app, it's possible to run the Django developer server with the settings and urls made for YunoHost installation.
e.g.:
~/django_yunohost_integration$ ./dev-cli.py local-test
test
and password test
is createdhttp://127.0.0.1:8000/app_path/
usage: ./dev-cli.py [-h]
{check-code-style,coverage,fix-code-style,install,local-test,mypy,pip-audit,publish,test,tox,updat
e,update-test-snapshot-files,version}
╭─ options ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help show this help message and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ {check-code-style,coverage,fix-code-style,install,local-test,mypy,pip-audit,publish,test,tox,update,update-test-s… │
│ check-code-style │
│ Check code style by calling darker + flake8 │
│ coverage Run tests and show coverage report. │
│ fix-code-style │
│ Fix code style of all django_yunohost_integration source code files via darker │
│ install Install requirements and 'django_yunohost_integration' via pip as editable. │
│ local-test Build a "local_test" YunoHost installation and start the Django dev. server against it. │
│ mypy Run Mypy (configured in pyproject.toml) │
│ pip-audit Run pip-audit check against current requirements files │
│ publish Build and upload this project to PyPi │
│ test Run unittests │
│ tox Run tox │
│ update Update "requirements*.txt" dependencies files │
│ update-test-snapshot-files │
│ Update all test snapshot files (by remove and recreate all snapshot files) │
│ version Print version and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Starting with v0.9 we only support YunoHost >= v12.
For this the auth_middleware
was changed:
HTTP_REMOTE_USER
changed HTTP_YNH_USER
HTTP_AUTH_USER
was removedSSOwAuthUser
changed to JWT token yunohost.portal
The YunoHost package nginx config should be set:
proxy_set_header Ynh-User $http_ynh_user;
--py-version
to optional, positional argumentassert_project_version
and get_github_version_tag
SyslogHandler
to logging settingsextra_replacements:dict
to create_local_test()
setup_demo_user()
-> setup_project_user()
pytest_helper.run_pytest()
SECURE_PROXY_SSL_HEADER
to settingsFAQs
Glue code to package django projects as yunohost apps.
We found that django-yunohost-integration demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.