mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
commit
c38849f771
6 changed files with 72 additions and 23 deletions
2
.flake8
2
.flake8
|
@ -2,6 +2,6 @@
|
||||||
# Move to pyproject.toml after: https://gitlab.com/pycqa/flake8/-/issues/428
|
# Move to pyproject.toml after: https://gitlab.com/pycqa/flake8/-/issues/428
|
||||||
#
|
#
|
||||||
[flake8]
|
[flake8]
|
||||||
exclude = .pytest_cache, .tox, dist, htmlcov, */migrations/*, volumes
|
exclude = .pytest_cache, .tox, dist, htmlcov, */migrations/*
|
||||||
#ignore = E402
|
#ignore = E402
|
||||||
max-line-length = 119
|
max-line-length = 119
|
||||||
|
|
85
README.md
85
README.md
|
@ -15,25 +15,21 @@ Pull requests welcome ;)
|
||||||
|
|
||||||
Glue code to package django projects as yunohost apps.
|
Glue code to package django projects as yunohost apps.
|
||||||
|
|
||||||
This project is:
|
This repository is:
|
||||||
|
|
||||||
* The Python package [django-ynh](https://pypi.org/project/django-ynh/) with helpers for integrate a Django project as YunoHost package
|
* The Python package [django-ynh](https://pypi.org/project/django-ynh/) with helpers for integrate a Django project as YunoHost package
|
||||||
* A example YunoHost Application that can be installed
|
* A example [YunoHost Application](https://install-app.yunohost.org/?app=django_ynh) that can be installed
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* SSOwat integration (see below)
|
||||||
|
* Helper to create first super user for `scripts/install`
|
||||||
* Run Django development server with a local generated YunoHost package installation (called `local_test`)
|
* Run Django development server with a local generated YunoHost package installation (called `local_test`)
|
||||||
|
* Run `pytest` against `local_test` "installation"
|
||||||
|
|
||||||
|
|
||||||
### usage
|
#### SSO authentication
|
||||||
|
|
||||||
To create/update a the first user in `install`/`upgrade`, e.g.:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./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 ;)
|
|
||||||
|
|
||||||
|
|
||||||
## SSO authentication
|
|
||||||
|
|
||||||
[SSOwat](https://github.com/YunoHost/SSOwat) is fully supported:
|
[SSOwat](https://github.com/YunoHost/SSOwat) is fully supported:
|
||||||
|
|
||||||
|
@ -42,12 +38,61 @@ A password is not needed, because auth done via SSOwat ;)
|
||||||
* Login via SSO is fully supported
|
* Login via SSO is fully supported
|
||||||
* User Email, First / Last name will be updated from SSO data
|
* User Email, First / Last name will be updated from SSO data
|
||||||
|
|
||||||
|
### usage
|
||||||
|
|
||||||
|
To create/update the first user in `install`/`upgrade`, e.g.:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./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`:
|
||||||
|
```python
|
||||||
|
from django_ynh.secret_key import get_or_create_secret as __get_or_create_secret
|
||||||
|
|
||||||
|
# Function that will be called to finalize a user profile:
|
||||||
|
YNH_SETUP_USER = 'setup_user.setup_project_user'
|
||||||
|
|
||||||
|
SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt') # /opt/yunohost/$app/secret.txt
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
#...
|
||||||
|
'django_ynh',
|
||||||
|
#...
|
||||||
|
]
|
||||||
|
|
||||||
|
MIDDLEWARE = [
|
||||||
|
#... after AuthenticationMiddleware ...
|
||||||
|
#
|
||||||
|
# login a user via HTTP_REMOTE_USER header from SSOwat:
|
||||||
|
'django_ynh.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_ynh.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/'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## history
|
## history
|
||||||
|
|
||||||
* [compare v0.1.2...master](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.2...master) **dev**
|
* [compare v0.1.2...master](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.2...master) **dev**
|
||||||
* tbc
|
* tbc
|
||||||
* [v0.1.2 - 29.12.2020](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.1...v0.1.2) **unreleased, yet**
|
* [v0.1.2 - 29.12.2020](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.1...v0.1.2)
|
||||||
* Bugfixes
|
* Bugfixes
|
||||||
* [v0.1.1 - 29.12.2020](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.0...v0.1.1)
|
* [v0.1.1 - 29.12.2020](https://github.com/YunoHost-Apps/django_ynh/compare/v0.1.0...v0.1.1)
|
||||||
* Refactor "create_superuser" to a manage command, useable via "django_ynh" in `INSTALLED_APPS`
|
* Refactor "create_superuser" to a manage command, useable via "django_ynh" in `INSTALLED_APPS`
|
||||||
|
@ -61,8 +106,14 @@ A password is not needed, because auth done via SSOwat ;)
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
|
|
||||||
* Report a bug about this package: https://github.com/YunoHost-Apps/django_ynh
|
* Report a bug about this package: https://github.com/YunoHost-Apps/django_ynh
|
||||||
* YunoHost website: https://yunohost.org/
|
* YunoHost website: https://yunohost.org/
|
||||||
|
* PyPi package: https://pypi.org/project/django-ynh/
|
||||||
|
|
||||||
|
These projects used `django_ynh`:
|
||||||
|
|
||||||
|
* https://github.com/YunoHost-Apps/pyinventory_ynh
|
||||||
|
* https://github.com/YunoHost-Apps/django-for-runners_ynh
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,9 @@ assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}'
|
||||||
PATH_URL = '__PATH_URL__' # $YNH_APP_ARG_PATH
|
PATH_URL = '__PATH_URL__' # $YNH_APP_ARG_PATH
|
||||||
PATH_URL = PATH_URL.strip('/')
|
PATH_URL = PATH_URL.strip('/')
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Function that will be called to finalize a user profile:
|
||||||
YNH_SETUP_USER = 'setup_user.setup_demo_user'
|
YNH_SETUP_USER = 'setup_user.setup_demo_user'
|
||||||
|
|
||||||
SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt') # /opt/yunohost/$app/secret.txt
|
SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt') # /opt/yunohost/$app/secret.txt
|
||||||
|
|
|
@ -97,6 +97,7 @@ def create_local_test(django_settings_path, destination, runserver=False):
|
||||||
|
|
||||||
with Path(final_home_path / 'local_settings.py').open('w') as f:
|
with Path(final_home_path / 'local_settings.py').open('w') as f:
|
||||||
f.write('# Only for local test run\n')
|
f.write('# Only for local test run\n')
|
||||||
|
f.write('DEBUG = True\n')
|
||||||
f.write('SERVE_FILES = True # used in src/inventory_project/urls.py\n')
|
f.write('SERVE_FILES = True # used in src/inventory_project/urls.py\n')
|
||||||
f.write('AUTH_PASSWORD_VALIDATORS = [] # accept all passwords\n')
|
f.write('AUTH_PASSWORD_VALIDATORS = [] # accept all passwords\n')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Start django_ynh in YunoHost setup locally.
|
Build a "local_test" YunoHost installation and start the Django dev. server against it.
|
||||||
|
|
||||||
Run via:
|
Run via:
|
||||||
make local-test
|
make local-test
|
||||||
|
|
|
@ -23,7 +23,6 @@ poetry-publish = "*" # https://github.com/jedie/poetry-publish
|
||||||
bx_py_utils = "*"
|
bx_py_utils = "*"
|
||||||
tox = "*"
|
tox = "*"
|
||||||
pytest = "*"
|
pytest = "*"
|
||||||
pytest-randomly = "*"
|
|
||||||
pytest-cov = "*"
|
pytest-cov = "*"
|
||||||
pytest-django = "*"
|
pytest-django = "*"
|
||||||
coveralls = "*"
|
coveralls = "*"
|
||||||
|
|
Loading…
Add table
Reference in a new issue