Skip to content

Commit f05f3a3

Browse files
authored
[#293] add support for configuring tokens through django-setup-configuration (#297)
1 parent 8ba4f48 commit f05f3a3

32 files changed

+1033
-33
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ WORKDIR /app
5757
# COPY ./cache /app/cache
5858
COPY ./bin/docker_start.sh /start.sh
5959
COPY ./bin/wait_for_db.sh /wait_for_db.sh
60+
COPY ./bin/setup_configuration.sh /setup_configuration.sh
6061
COPY ./bin/celery_worker.sh /celery_worker.sh
6162
COPY ./bin/celery_flower.sh /celery_flower.sh
6263

bin/setup_configuration.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# setup initial configuration using environment variables
4+
# Run this script from the root of the repository
5+
6+
set -e
7+
8+
if [[ "${RUN_SETUP_CONFIG,,}" =~ ^(true|1|yes)$ ]]; then
9+
# wait for required services
10+
/wait_for_db.sh
11+
12+
src/manage.py migrate
13+
src/manage.py setup_configuration --yaml-file setup_configuration/data.yaml
14+
fi

bin/wait_for_db.sh

100644100755
File mode changed.

docker-compose.yml

+41-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
# See: https://hub.docker.com/_/postgres/
88
image: postgres
99
environment:
10-
- POSTGRES_HOST_AUTH_METHOD=trust
10+
POSTGRES_HOST_AUTH_METHOD: trust
1111
# NOTE: this works for bitnami, not sure if this works for regular
1212
# postgres image
1313
volumes:
@@ -17,22 +17,46 @@ services:
1717
web:
1818
image: maykinmedia/open-klant:latest
1919
build: .
20-
environment: &web-env
21-
- DJANGO_SETTINGS_MODULE=openklant.conf.docker
22-
- IS_HTTPS=no
23-
- DB_NAME=postgres
24-
- DB_USER=postgres
25-
- DB_HOST=db
26-
- ALLOWED_HOSTS=*
27-
- CACHE_DEFAULT=redis:6379/0
28-
- CACHE_AXES=redis:6379/0
29-
- SUBPATH=${SUBPATH:-/}
30-
- SECRET_KEY=${SECRET_KEY:-django-insecure-f8s@b*ds4t84-q_2#c0j0506@!l2q6r5_pq5e!vm^_9c*#^66b}
31-
- CELERY_BROKER_URL=redis://redis:6379/0
32-
- CELERY_RESULT_BACKEND=redis://redis:6379/0
33-
- DISABLE_2FA=true
20+
environment: &web_env
21+
DJANGO_SETTINGS_MODULE: openklant.conf.docker
22+
IS_HTTPS: no
23+
DB_NAME: postgres
24+
DB_USER: postgres
25+
DB_HOST: db
26+
ALLOWED_HOSTS: '*'
27+
CACHE_DEFAULT: redis:6379/0
28+
CACHE_AXES: redis:6379/0
29+
SUBPATH: ${SUBPATH:-/}
30+
SECRET_KEY: ${SECRET_KEY:-django-insecure-f8s@b*ds4t84-q_2#c0j0506@!l2q6r5_pq5e!vm^_9c*#^66b}
31+
CELERY_BROKER_UR: redis://redis:6379/0
32+
CELERY_RESULT_BACKEND: redis://redis:6379/0
33+
DISABLE_2FA: true
34+
35+
volumes:
36+
- media:/app/media
37+
- private_media:/app/private_media
38+
- log:/app/log
3439
ports:
3540
- 8000:8000
41+
depends_on:
42+
db:
43+
condition: service_started
44+
redis:
45+
condition: service_started
46+
web-init:
47+
condition: service_completed_successfully
48+
49+
web-init:
50+
build: .
51+
environment:
52+
<<: *web_env
53+
#
54+
# Django-setup-configuration
55+
RUN_SETUP_CONFIG: ${RUN_SETUP_CONFIG:-true}
56+
command: /setup_configuration.sh
57+
volumes:
58+
- log:/app/log
59+
- ./docker/setup_configuration:/app/setup_configuration
3660
depends_on:
3761
- db
3862
- redis
@@ -43,4 +67,5 @@ services:
4367
volumes:
4468
db:
4569
log:
46-
70+
media:
71+
private_media:

docker/setup_configuration/data.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openklant_tokens_config_enable: true
2+
openklant_tokens:
3+
items:
4+
- identifier: token-1
5+
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067
6+
contact_person: Person 1
7+
email: test@example.com
8+
organization: Organization XYZ
9+
application: Application XYZ
10+
administration: Administration XYZ

docs/installation/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ this.
1616

1717
config
1818
migration
19+
setup_configuration
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.. _installation_configuration_cli:
2+
3+
==============================
4+
Open Klant configuration (CLI)
5+
==============================
6+
7+
After deploying Open Klant, it needs to be configured to be fully functional.
8+
The django management command ``setup_configuration`` assist with this configuration.
9+
You can get the full command documentation with:
10+
11+
.. code-block:: bash
12+
13+
python ./src/manage.py setup_configuration --help
14+
15+
.. warning:: This command is declarative - if configuration is manually changed after
16+
running the command and you then run the exact same command again, the manual
17+
changes will be reverted.
18+
19+
Preparation
20+
===========
21+
22+
The command executes the list of pluggable configuration steps, and each step
23+
requires specific configuration information, that should be prepared.
24+
Here is the description of all available configuration steps and the configuration
25+
format, used by each step.
26+
27+
Token configuration
28+
----------------------
29+
30+
Create a (single) YAML configuration file with your settings:
31+
32+
.. code-block:: yaml
33+
34+
openklant_tokens_config_enable: true
35+
openklant_tokens:
36+
group:
37+
- identifier: token-1
38+
contact_person: Person 1
39+
email: person-1@example.com
40+
organization: Organization XYZ # optional
41+
application: Application XYZ # optional
42+
administration: Administration XYZ # optional
43+
44+
- identifier: token-2
45+
contact_person: Person 2
46+
email: person-2@example.com
47+
48+
Execution
49+
=========
50+
51+
Open Klant configuration
52+
------------------------
53+
54+
With the full command invocation, everything is configured at once. Each configuration step
55+
is idempotent, so any manual changes made via the admin interface will be updated if the command
56+
is run afterwards.
57+
58+
.. code-block:: bash
59+
60+
python ./src/manage.py setup_configuration --yaml-file /path/to/config.yaml
61+
62+
.. note:: Due to a cache-bug in the underlying framework, you need to restart all
63+
replicas for part of this change to take effect everywhere.

requirements/base.in

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
open-api-framework
2+
3+
django-setup-configuration

requirements/base.txt

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#
77
amqp==5.2.0
88
# via kombu
9+
annotated-types==0.7.0
10+
# via pydantic
911
ape-pie==0.2.0
1012
# via
1113
# commonground-api-common
@@ -151,8 +153,10 @@ django-sendfile2==0.7.1
151153
# via django-privates
152154
django-sessionprofile==3.0.0
153155
# via open-api-framework
154-
django-setup-configuration==0.3.0
155-
# via open-api-framework
156+
django-setup-configuration==0.4.0
157+
# via
158+
# -r requirements/base.in
159+
# open-api-framework
156160
django-simple-certmanager==2.3.0
157161
# via zgw-consumers
158162
django-solo==2.3.0
@@ -254,6 +258,14 @@ psycopg2==2.9.9
254258
# via open-api-framework
255259
pycparser==2.22
256260
# via cffi
261+
pydantic==2.10.2
262+
# via
263+
# django-setup-configuration
264+
# pydantic-settings
265+
pydantic-core==2.27.1
266+
# via pydantic
267+
pydantic-settings[yaml]==2.6.1
268+
# via django-setup-configuration
257269
pyjwt==2.9.0
258270
# via
259271
# commonground-api-common
@@ -271,7 +283,9 @@ python-dateutil==2.9.0.post0
271283
python-decouple==3.8
272284
# via open-api-framework
273285
python-dotenv==1.0.1
274-
# via open-api-framework
286+
# via
287+
# open-api-framework
288+
# pydantic-settings
275289
pytz==2024.1
276290
# via
277291
# drf-yasg
@@ -281,6 +295,7 @@ pyyaml==6.0.1
281295
# drf-spectacular
282296
# drf-yasg
283297
# oyaml
298+
# pydantic-settings
284299
qrcode==7.4.2
285300
# via django-two-factor-auth
286301
redis==5.0.8
@@ -321,6 +336,8 @@ tornado==6.4.1
321336
typing-extensions==4.12.2
322337
# via
323338
# mozilla-django-oidc-db
339+
# pydantic
340+
# pydantic-core
324341
# qrcode
325342
# zgw-consumers
326343
tzdata==2024.1

requirements/ci.txt

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ amqp==5.2.0
1010
# via
1111
# -r requirements/base.txt
1212
# kombu
13+
annotated-types==0.7.0
14+
# via
15+
# -r requirements/base.txt
16+
# pydantic
1317
ape-pie==0.2.0
1418
# via
1519
# -r requirements/base.txt
@@ -243,7 +247,7 @@ django-sessionprofile==3.0.0
243247
# via
244248
# -r requirements/base.txt
245249
# open-api-framework
246-
django-setup-configuration==0.3.0
250+
django-setup-configuration==0.4.0
247251
# via
248252
# -r requirements/base.txt
249253
# open-api-framework
@@ -479,6 +483,19 @@ pycparser==2.22
479483
# via
480484
# -r requirements/base.txt
481485
# cffi
486+
pydantic==2.10.2
487+
# via
488+
# -r requirements/base.txt
489+
# django-setup-configuration
490+
# pydantic-settings
491+
pydantic-core==2.27.1
492+
# via
493+
# -r requirements/base.txt
494+
# pydantic
495+
pydantic-settings[yaml]==2.6.1
496+
# via
497+
# -r requirements/base.txt
498+
# django-setup-configuration
482499
pyflakes==3.2.0
483500
# via flake8
484501
pygments==2.18.0
@@ -520,6 +537,7 @@ python-dotenv==1.0.1
520537
# via
521538
# -r requirements/base.txt
522539
# open-api-framework
540+
# pydantic-settings
523541
pytz==2024.1
524542
# via
525543
# -r requirements/base.txt
@@ -531,6 +549,7 @@ pyyaml==6.0.1
531549
# drf-spectacular
532550
# drf-yasg
533551
# oyaml
552+
# pydantic-settings
534553
# vcrpy
535554
qrcode==7.4.2
536555
# via
@@ -630,6 +649,8 @@ typing-extensions==4.12.2
630649
# -r requirements/base.txt
631650
# faker
632651
# mozilla-django-oidc-db
652+
# pydantic
653+
# pydantic-core
633654
# qrcode
634655
# zgw-consumers
635656
tzdata==2024.1

requirements/dev.txt

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ amqp==5.2.0
1010
# via
1111
# -r requirements/base.txt
1212
# kombu
13+
annotated-types==0.7.0
14+
# via
15+
# -r requirements/base.txt
16+
# pydantic
1317
ape-pie==0.2.0
1418
# via
1519
# -r requirements/base.txt
@@ -250,7 +254,7 @@ django-sessionprofile==3.0.0
250254
# via
251255
# -r requirements/base.txt
252256
# open-api-framework
253-
django-setup-configuration==0.3.0
257+
django-setup-configuration==0.4.0
254258
# via
255259
# -r requirements/base.txt
256260
# open-api-framework
@@ -488,6 +492,19 @@ pycparser==2.22
488492
# via
489493
# -r requirements/base.txt
490494
# cffi
495+
pydantic==2.10.2
496+
# via
497+
# -r requirements/base.txt
498+
# django-setup-configuration
499+
# pydantic-settings
500+
pydantic-core==2.27.1
501+
# via
502+
# -r requirements/base.txt
503+
# pydantic
504+
pydantic-settings[yaml]==2.6.1
505+
# via
506+
# -r requirements/base.txt
507+
# django-setup-configuration
491508
pyflakes==3.2.0
492509
# via flake8
493510
pygments==2.18.0
@@ -531,6 +548,7 @@ python-dotenv==1.0.1
531548
# via
532549
# -r requirements/base.txt
533550
# open-api-framework
551+
# pydantic-settings
534552
pytz==2024.1
535553
# via
536554
# -r requirements/base.txt
@@ -542,6 +560,7 @@ pyyaml==6.0.1
542560
# drf-spectacular
543561
# drf-yasg
544562
# oyaml
563+
# pydantic-settings
545564
# vcrpy
546565
qrcode==7.4.2
547566
# via
@@ -643,6 +662,8 @@ typing-extensions==4.12.2
643662
# -r requirements/base.txt
644663
# faker
645664
# mozilla-django-oidc-db
665+
# pydantic
666+
# pydantic-core
646667
# qrcode
647668
# zgw-consumers
648669
tzdata==2024.1

src/openklant/components/token/admin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@admin.register(TokenAuth)
77
class TokenAuthAdmin(admin.ModelAdmin):
88
list_display = (
9-
"token",
9+
"identifier",
1010
"contact_person",
1111
"organization",
1212
"administration",

0 commit comments

Comments
 (0)