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

[#293] add support for configuring tokens through django-setup-configuration #297

Merged
merged 44 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
290a102
[#293] pin django-setup-configuration to commit
Nov 28, 2024
68dbc5d
[#293] update base settings
Nov 28, 2024
8e0cb4b
[#293] pin django-setup-configuration to new release
Nov 28, 2024
426b8ce
[#293] remove duplicate entry in INSTALLED_APPS
Nov 28, 2024
2b06644
[#293] add TokenAuth migration
Nov 28, 2024
03ae840
[#293] add migration tests
Nov 28, 2024
fe63bfb
[#293] update TokenAuth admin
Nov 28, 2024
df538e4
[#293] add missing utils function
Nov 28, 2024
e0d611d
[#293] update TokenAuthFactory
Nov 29, 2024
134417f
[#293] add TokenAuthConfigurationStep
Nov 29, 2024
82f4aa9
[#293] apply django field validation
SonnyBA Nov 29, 2024
03f082f
[#293] add test for verifying idempotent behavior
SonnyBA Nov 29, 2024
380bc34
[#293] include documentation
SonnyBA Nov 29, 2024
44c496d
[#293] fix TokenAuthFactory
SonnyBA Nov 29, 2024
3721940
[#293] regenerate documentation
SonnyBA Nov 29, 2024
1e79dba
[#293] apply formatting
SonnyBA Nov 29, 2024
985e99b
[#293] update documentation examples
SonnyBA Dec 3, 2024
c84f55a
[#293] move optional fields
SonnyBA Dec 3, 2024
cfc9ae9
[#293] generate unique tokens in consistenly
SonnyBA Dec 3, 2024
dfc9e11
[#293] apply feedback to tests
SonnyBA Dec 3, 2024
f71452a
[#293] Update exception handling
SonnyBA Dec 3, 2024
caad8cb
[#293] move validation & allow loading token through configuration
SonnyBA Dec 3, 2024
01a2bef
[#293] rename `group` to `items` & remove it's default
SonnyBA Dec 3, 2024
f411395
[#293] update help text for `identifier`
SonnyBA Dec 3, 2024
f3badb1
[#293] use `secrets` stlib module & regenerate test tokens
SonnyBA Dec 3, 2024
6cc0976
[#293] add `null=True` for identifier field during the migration
SonnyBA Dec 3, 2024
0b4b71f
[#293] add whitespace like validation for tokens
SonnyBA Dec 3, 2024
1d342bd
[#293] update `identifier` generation for migration
SonnyBA Dec 3, 2024
1eff253
[#293] apply incrementing pattern for `TokenAuthFactory`
SonnyBA Dec 3, 2024
422ea74
[#293] remove version pin from .in file
SonnyBA Dec 3, 2024
2781208
[#293] update documentation
SonnyBA Dec 3, 2024
d0decec
[#293] remove `model_dump` usage
SonnyBA Dec 3, 2024
bf02194
[#293] update docker-compose setup
SonnyBA Dec 4, 2024
56ac44a
[#293] apply formatting
SonnyBA Dec 4, 2024
31f2258
[#293] add missing `setup_configuration.sh` script
SonnyBA Dec 4, 2024
625631f
[#293] add missing migration
SonnyBA Dec 4, 2024
9d1704c
[#293] rename `model` to `item`
SonnyBA Dec 4, 2024
ea6802c
[#293] rename config namespace
SonnyBA Dec 4, 2024
bacd852
[#293] don't allow any whitespace for tokens
SonnyBA Dec 4, 2024
837f265
[#293] remove setup_configuration volume from web container
SonnyBA Dec 4, 2024
47936cb
[#293] update documentation examples
SonnyBA Dec 4, 2024
2711785
[#293] squash migrations
SonnyBA Dec 4, 2024
8238e66
[#293] fix redis url
SonnyBA Dec 4, 2024
bb1c946
[#293] handle more specific database errors
SonnyBA Dec 4, 2024
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ WORKDIR /app
# COPY ./cache /app/cache
COPY ./bin/docker_start.sh /start.sh
COPY ./bin/wait_for_db.sh /wait_for_db.sh
COPY ./bin/setup_configuration.sh /setup_configuration.sh
COPY ./bin/celery_worker.sh /celery_worker.sh
COPY ./bin/celery_flower.sh /celery_flower.sh

Expand Down
14 changes: 14 additions & 0 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# setup initial configuration using environment variables
# Run this script from the root of the repository

set -e

if [[ "${RUN_SETUP_CONFIG,,}" =~ ^(true|1|yes)$ ]]; then
# wait for required services
/wait_for_db.sh

src/manage.py migrate
src/manage.py setup_configuration --yaml-file setup_configuration/data.yaml
fi
Empty file modified bin/wait_for_db.sh
100644 → 100755
Empty file.
57 changes: 41 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
# See: https://hub.docker.com/_/postgres/
image: postgres
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
POSTGRES_HOST_AUTH_METHOD: trust
# NOTE: this works for bitnami, not sure if this works for regular
# postgres image
volumes:
Expand All @@ -17,22 +17,46 @@ services:
web:
image: maykinmedia/open-klant:latest
build: .
environment: &web-env
- DJANGO_SETTINGS_MODULE=openklant.conf.docker
- IS_HTTPS=no
- DB_NAME=postgres
- DB_USER=postgres
- DB_HOST=db
- ALLOWED_HOSTS=*
- CACHE_DEFAULT=redis:6379/0
- CACHE_AXES=redis:6379/0
- SUBPATH=${SUBPATH:-/}
- SECRET_KEY=${SECRET_KEY:-django-insecure-f8s@b*ds4t84-q_2#c0j0506@!l2q6r5_pq5e!vm^_9c*#^66b}
- CELERY_BROKER_URL=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0
- DISABLE_2FA=true
environment: &web_env
DJANGO_SETTINGS_MODULE: openklant.conf.docker
IS_HTTPS: no
DB_NAME: postgres
DB_USER: postgres
DB_HOST: db
ALLOWED_HOSTS: '*'
CACHE_DEFAULT: redis:6379/0
CACHE_AXES: redis:6379/0
SUBPATH: ${SUBPATH:-/}
SECRET_KEY: ${SECRET_KEY:-django-insecure-f8s@b*ds4t84-q_2#c0j0506@!l2q6r5_pq5e!vm^_9c*#^66b}
CELERY_BROKER_UR: redis://redis:6379/0
CELERY_RESULT_BACKEND: redis://redis:6379/0
DISABLE_2FA: true

volumes:
- media:/app/media
- private_media:/app/private_media
- log:/app/log
ports:
- 8000:8000
depends_on:
db:
condition: service_started
redis:
condition: service_started
web-init:
condition: service_completed_successfully

web-init:
build: .
environment:
<<: *web_env
#
# Django-setup-configuration
RUN_SETUP_CONFIG: ${RUN_SETUP_CONFIG:-true}
command: /setup_configuration.sh
volumes:
- log:/app/log
- ./docker/setup_configuration:/app/setup_configuration
depends_on:
- db
- redis
Expand All @@ -43,4 +67,5 @@ services:
volumes:
db:
log:

media:
private_media:
10 changes: 10 additions & 0 deletions docker/setup_configuration/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
openklant_tokens_config_enable: true
openklant_tokens:
items:
- identifier: token-1
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067
contact_person: Person 1
email: [email protected]
organization: Organization XYZ
application: Application XYZ
administration: Administration XYZ
1 change: 1 addition & 0 deletions docs/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ this.

config
migration
setup_configuration
63 changes: 63 additions & 0 deletions docs/installation/setup_configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. _installation_configuration_cli:
SonnyBA marked this conversation as resolved.
Show resolved Hide resolved

==============================
Open Klant configuration (CLI)
==============================

After deploying Open Klant, it needs to be configured to be fully functional.
The django management command ``setup_configuration`` assist with this configuration.
You can get the full command documentation with:
SonnyBA marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: bash

python ./src/manage.py setup_configuration --help

.. warning:: This command is declarative - if configuration is manually changed after
running the command and you then run the exact same command again, the manual
changes will be reverted.

Preparation
===========

The command executes the list of pluggable configuration steps, and each step
requires specific configuration information, that should be prepared.
Here is the description of all available configuration steps and the configuration
format, used by each step.

Token configuration
----------------------

Create a (single) YAML configuration file with your settings:

.. code-block:: yaml

openklant_tokens_config_enable: true
openklant_tokens:
group:
- identifier: token-1
contact_person: Person 1
email: [email protected]
organization: Organization XYZ # optional
application: Application XYZ # optional
administration: Administration XYZ # optional

- identifier: token-2
contact_person: Person 2
email: [email protected]

Execution
=========

Open Klant configuration
------------------------

With the full command invocation, everything is configured at once. Each configuration step
is idempotent, so any manual changes made via the admin interface will be updated if the command
is run afterwards.

.. code-block:: bash

python ./src/manage.py setup_configuration --yaml-file /path/to/config.yaml

.. note:: Due to a cache-bug in the underlying framework, you need to restart all
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was part of the original docs, but is this still an issue actually? @annashamray do you remember what this was about?

replicas for part of this change to take effect everywhere.
2 changes: 2 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
open-api-framework

django-setup-configuration
23 changes: 20 additions & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
amqp==5.2.0
# via kombu
annotated-types==0.7.0
# via pydantic
ape-pie==0.2.0
# via
# commonground-api-common
Expand Down Expand Up @@ -151,8 +153,10 @@ django-sendfile2==0.7.1
# via django-privates
django-sessionprofile==3.0.0
# via open-api-framework
django-setup-configuration==0.3.0
# via open-api-framework
django-setup-configuration==0.4.0
# via
# -r requirements/base.in
# open-api-framework
django-simple-certmanager==2.3.0
# via zgw-consumers
django-solo==2.3.0
Expand Down Expand Up @@ -254,6 +258,14 @@ psycopg2==2.9.9
# via open-api-framework
pycparser==2.22
# via cffi
pydantic==2.10.2
# via
# django-setup-configuration
# pydantic-settings
pydantic-core==2.27.1
# via pydantic
pydantic-settings[yaml]==2.6.1
# via django-setup-configuration
pyjwt==2.9.0
# via
# commonground-api-common
Expand All @@ -271,7 +283,9 @@ python-dateutil==2.9.0.post0
python-decouple==3.8
# via open-api-framework
python-dotenv==1.0.1
# via open-api-framework
# via
# open-api-framework
# pydantic-settings
pytz==2024.1
# via
# drf-yasg
Expand All @@ -281,6 +295,7 @@ pyyaml==6.0.1
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
qrcode==7.4.2
# via django-two-factor-auth
redis==5.0.8
Expand Down Expand Up @@ -321,6 +336,8 @@ tornado==6.4.1
typing-extensions==4.12.2
# via
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# qrcode
# zgw-consumers
tzdata==2024.1
Expand Down
23 changes: 22 additions & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ amqp==5.2.0
# via
# -r requirements/base.txt
# kombu
annotated-types==0.7.0
# via
# -r requirements/base.txt
# pydantic
ape-pie==0.2.0
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -243,7 +247,7 @@ django-sessionprofile==3.0.0
# via
# -r requirements/base.txt
# open-api-framework
django-setup-configuration==0.3.0
django-setup-configuration==0.4.0
# via
# -r requirements/base.txt
# open-api-framework
Expand Down Expand Up @@ -479,6 +483,19 @@ pycparser==2.22
# via
# -r requirements/base.txt
# cffi
pydantic==2.10.2
# via
# -r requirements/base.txt
# django-setup-configuration
# pydantic-settings
pydantic-core==2.27.1
# via
# -r requirements/base.txt
# pydantic
pydantic-settings[yaml]==2.6.1
# via
# -r requirements/base.txt
# django-setup-configuration
pyflakes==3.2.0
# via flake8
pygments==2.18.0
Expand Down Expand Up @@ -520,6 +537,7 @@ python-dotenv==1.0.1
# via
# -r requirements/base.txt
# open-api-framework
# pydantic-settings
pytz==2024.1
# via
# -r requirements/base.txt
Expand All @@ -531,6 +549,7 @@ pyyaml==6.0.1
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
# vcrpy
qrcode==7.4.2
# via
Expand Down Expand Up @@ -630,6 +649,8 @@ typing-extensions==4.12.2
# -r requirements/base.txt
# faker
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# qrcode
# zgw-consumers
tzdata==2024.1
Expand Down
23 changes: 22 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ amqp==5.2.0
# via
# -r requirements/base.txt
# kombu
annotated-types==0.7.0
# via
# -r requirements/base.txt
# pydantic
ape-pie==0.2.0
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -250,7 +254,7 @@ django-sessionprofile==3.0.0
# via
# -r requirements/base.txt
# open-api-framework
django-setup-configuration==0.3.0
django-setup-configuration==0.4.0
# via
# -r requirements/base.txt
# open-api-framework
Expand Down Expand Up @@ -488,6 +492,19 @@ pycparser==2.22
# via
# -r requirements/base.txt
# cffi
pydantic==2.10.2
# via
# -r requirements/base.txt
# django-setup-configuration
# pydantic-settings
pydantic-core==2.27.1
# via
# -r requirements/base.txt
# pydantic
pydantic-settings[yaml]==2.6.1
# via
# -r requirements/base.txt
# django-setup-configuration
pyflakes==3.2.0
# via flake8
pygments==2.18.0
Expand Down Expand Up @@ -531,6 +548,7 @@ python-dotenv==1.0.1
# via
# -r requirements/base.txt
# open-api-framework
# pydantic-settings
pytz==2024.1
# via
# -r requirements/base.txt
Expand All @@ -542,6 +560,7 @@ pyyaml==6.0.1
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
# vcrpy
qrcode==7.4.2
# via
Expand Down Expand Up @@ -643,6 +662,8 @@ typing-extensions==4.12.2
# -r requirements/base.txt
# faker
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# qrcode
# zgw-consumers
tzdata==2024.1
Expand Down
2 changes: 1 addition & 1 deletion src/openklant/components/token/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@admin.register(TokenAuth)
class TokenAuthAdmin(admin.ModelAdmin):
list_display = (
"token",
"identifier",
"contact_person",
"organization",
"administration",
Expand Down
Loading
Loading