Skip to content

Commit 135f8a3

Browse files
authored
Merge pull request #524 from maykinmedia/feature/458-add-django-config-zgw
[#458] Add django setup configuration and ZGW steps
2 parents 7929213 + 95973cd commit 135f8a3

File tree

15 files changed

+287
-3
lines changed

15 files changed

+287
-3
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ COPY ./backend/bin/celery_worker.sh /celery_worker.sh
7171
COPY ./backend/bin/celery_beat.sh /celery_beat.sh
7272
COPY ./backend/bin/celery_flower.sh /celery_flower.sh
7373
COPY ./backend/bin/check_celery_worker_liveness.py /check_celery_worker_liveness.py
74+
COPY ./backend/bin/setup_configuration.sh /setup_configuration.sh
7475
COPY ./frontend/scripts/replace-envvars.sh /replace-envvars.sh
7576

7677
RUN mkdir -p /app/log /app/media /app/src/openarchiefbeheer/static/

backend/bin/setup_configuration.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
# Waiting for database to be up
4+
until pg_isready; do
5+
>&2 echo "Waiting for database connection..."
6+
sleep 1
7+
done
8+
9+
# Waiting for migrations to be done
10+
attempt_counter=0
11+
max_attempts=${CHECK_MIGRATIONS_MAX_ATTEMPT:-10}
12+
13+
while ! python src/manage.py migrate --check; do
14+
attempt_counter=$((attempt_counter + 1))
15+
16+
if [ $attempt_counter -ge $max_attempts ]; then
17+
>&2 echo "Timed out while waiting for django migrations."
18+
exit 1
19+
fi
20+
21+
>&2 echo "Attempt $attempt_counter/$max_attempts: Waiting for migrations to be done..."
22+
sleep 10
23+
done
24+
25+
# Run setup configuration
26+
python src/manage.py setup_configuration --yaml-file setup_configuration/data.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
zgw_consumers_config_enable: True
2+
zgw_consumers:
3+
services:
4+
- identifier: zaken-test
5+
label: Open Zaak - Zaken API
6+
api_root: http://localhost:8003/zaken/api/v1/
7+
api_type: zrc
8+
auth_type: zgw
9+
client_id: test-vcr
10+
secret: test-vcr
11+
- identifier: documenten-test
12+
label: Open Zaak - Documenten API
13+
api_root: http://localhost:8003/documenten/api/v1/
14+
api_type: drc
15+
auth_type: zgw
16+
client_id: test-vcr
17+
secret: test-vcr
18+
- identifier: catalogi-test
19+
label: Open Zaak - Catalogi API
20+
api_root: http://localhost:8003/catalogi/api/v1/
21+
api_type: ztc
22+
auth_type: zgw
23+
client_id: test-vcr
24+
secret: test-vcr
25+
- identifier: besluiten-test
26+
label: Open Zaak - Besluiten API
27+
api_root: http://localhost:8003/besluiten/api/v1/
28+
api_type: brc
29+
auth_type: zgw
30+
client_id: test-vcr
31+
secret: test-vcr
32+
- identifier: selectielijst
33+
label: Open Zaak (public) - Selectielijst API
34+
api_root: https://selectielijst.openzaak.nl/api/v1/
35+
api_type: orc
36+
auth_type: no_auth
37+
38+
api_configuration_enabled: True
39+
api_configuration:
40+
selectielijst_service_identifier: selectielijst

backend/requirements/base.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ django-timeline-logger
1616
django-solo
1717
mozilla-django-oidc-db
1818
django-privates
19+
django-setup-configuration
1920

2021
# API libraries
2122
djangorestframework
@@ -35,7 +36,7 @@ elastic-apm # Elastic APM integration
3536
celery
3637

3738
# Additional libraries
38-
zgw-consumers
39+
zgw-consumers[setup-configuration]
3940
furl
4041
python-slugify
4142
XlsxWriter

backend/requirements/base.txt

+23-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# ./bin/compile_dependencies.sh
33
amqp==5.2.0
44
# via kombu
5+
annotated-types==0.7.0
6+
# via pydantic
57
ape-pie==0.1.0
68
# via zgw-consumers
79
asgiref==3.8.1
@@ -71,6 +73,7 @@ django==4.2.16
7173
# django-relativedelta
7274
# django-rosetta
7375
# django-sendfile2
76+
# django-setup-configuration
7477
# django-simple-certmanager
7578
# django-solo
7679
# django-timeline-logger
@@ -116,6 +119,10 @@ django-rosetta==0.10.0
116119
# via -r requirements/base.in
117120
django-sendfile2==0.7.1
118121
# via django-privates
122+
django-setup-configuration==0.4.0
123+
# via
124+
# -r requirements/base.in
125+
# zgw-consumers
119126
django-simple-certmanager==2.0.0
120127
# via zgw-consumers
121128
django-solo==2.2.0
@@ -185,6 +192,14 @@ psycopg2==2.9.9
185192
# via -r requirements/base.in
186193
pycparser==2.22
187194
# via cffi
195+
pydantic==2.9.2
196+
# via
197+
# django-setup-configuration
198+
# pydantic-settings
199+
pydantic-core==2.23.4
200+
# via pydantic
201+
pydantic-settings==2.6.1
202+
# via django-setup-configuration
188203
pyjwt==2.8.0
189204
# via zgw-consumers
190205
pyopenssl==24.2.1
@@ -200,11 +215,15 @@ python-dateutil==2.9.0.post0
200215
python-decouple==3.8
201216
# via -r requirements/base.in
202217
python-dotenv==1.0.1
203-
# via -r requirements/base.in
218+
# via
219+
# -r requirements/base.in
220+
# pydantic-settings
204221
python-slugify==8.0.4
205222
# via -r requirements/base.in
206223
pyyaml==6.0.1
207-
# via drf-spectacular
224+
# via
225+
# drf-spectacular
226+
# pydantic-settings
208227
qrcode==7.4.2
209228
# via django-two-factor-auth
210229
redis==5.0.4
@@ -237,6 +256,8 @@ text-unidecode==1.3
237256
typing-extensions==4.11.0
238257
# via
239258
# mozilla-django-oidc-db
259+
# pydantic
260+
# pydantic-core
240261
# qrcode
241262
# zgw-consumers
242263
tzdata==2024.1

backend/requirements/ci.txt

+30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ amqp==5.2.0
77
# -c requirements/base.txt
88
# -r requirements/base.txt
99
# kombu
10+
annotated-types==0.7.0
11+
# via
12+
# -c requirements/base.txt
13+
# -r requirements/base.txt
14+
# pydantic
1015
ape-pie==0.1.0
1116
# via
1217
# -c requirements/base.txt
@@ -134,6 +139,7 @@ django==4.2.16
134139
# django-relativedelta
135140
# django-rosetta
136141
# django-sendfile2
142+
# django-setup-configuration
137143
# django-simple-certmanager
138144
# django-solo
139145
# django-timeline-logger
@@ -220,6 +226,10 @@ django-sendfile2==0.7.1
220226
# -c requirements/base.txt
221227
# -r requirements/base.txt
222228
# django-privates
229+
django-setup-configuration==0.4.0
230+
# via
231+
# -c requirements/base.txt
232+
# -r requirements/base.txt
223233
django-simple-certmanager==2.0.0
224234
# via
225235
# -c requirements/base.txt
@@ -423,6 +433,22 @@ pycparser==2.22
423433
# -c requirements/base.txt
424434
# -r requirements/base.txt
425435
# cffi
436+
pydantic==2.9.2
437+
# via
438+
# -c requirements/base.txt
439+
# -r requirements/base.txt
440+
# django-setup-configuration
441+
# pydantic-settings
442+
pydantic-core==2.23.4
443+
# via
444+
# -c requirements/base.txt
445+
# -r requirements/base.txt
446+
# pydantic
447+
pydantic-settings==2.6.1
448+
# via
449+
# -c requirements/base.txt
450+
# -r requirements/base.txt
451+
# django-setup-configuration
426452
pyee==11.1.0
427453
# via playwright
428454
pyflakes==3.2.0
@@ -474,6 +500,7 @@ python-dotenv==1.0.1
474500
# via
475501
# -c requirements/base.txt
476502
# -r requirements/base.txt
503+
# pydantic-settings
477504
python-slugify==8.0.4
478505
# via
479506
# -c requirements/base.txt
@@ -484,6 +511,7 @@ pyyaml==6.0.1
484511
# -c requirements/base.txt
485512
# -r requirements/base.txt
486513
# drf-spectacular
514+
# pydantic-settings
487515
# vcrpy
488516
qrcode==7.4.2
489517
# via
@@ -578,6 +606,8 @@ typing-extensions==4.11.0
578606
# -c requirements/base.txt
579607
# -r requirements/base.txt
580608
# mozilla-django-oidc-db
609+
# pydantic
610+
# pydantic-core
581611
# pyee
582612
# qrcode
583613
# zgw-consumers

backend/requirements/dev.txt

+30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ amqp==5.2.0
1010
# -c requirements/ci.txt
1111
# -r requirements/ci.txt
1212
# kombu
13+
annotated-types==0.7.0
14+
# via
15+
# -c requirements/ci.txt
16+
# -r requirements/ci.txt
17+
# pydantic
1318
ape-pie==0.1.0
1419
# via
1520
# -c requirements/ci.txt
@@ -166,6 +171,7 @@ django==4.2.16
166171
# django-relativedelta
167172
# django-rosetta
168173
# django-sendfile2
174+
# django-setup-configuration
169175
# django-simple-certmanager
170176
# django-solo
171177
# django-timeline-logger
@@ -258,6 +264,10 @@ django-sendfile2==0.7.1
258264
# -c requirements/ci.txt
259265
# -r requirements/ci.txt
260266
# django-privates
267+
django-setup-configuration==0.4.0
268+
# via
269+
# -c requirements/ci.txt
270+
# -r requirements/ci.txt
261271
django-simple-certmanager==2.0.0
262272
# via
263273
# -c requirements/ci.txt
@@ -536,6 +546,22 @@ pycparser==2.22
536546
# -c requirements/ci.txt
537547
# -r requirements/ci.txt
538548
# cffi
549+
pydantic==2.9.2
550+
# via
551+
# -c requirements/ci.txt
552+
# -r requirements/ci.txt
553+
# django-setup-configuration
554+
# pydantic-settings
555+
pydantic-core==2.23.4
556+
# via
557+
# -c requirements/ci.txt
558+
# -r requirements/ci.txt
559+
# pydantic
560+
pydantic-settings==2.6.1
561+
# via
562+
# -c requirements/ci.txt
563+
# -r requirements/ci.txt
564+
# django-setup-configuration
539565
pyee==11.1.0
540566
# via
541567
# -c requirements/ci.txt
@@ -610,6 +636,7 @@ python-dotenv==1.0.1
610636
# via
611637
# -c requirements/ci.txt
612638
# -r requirements/ci.txt
639+
# pydantic-settings
613640
python-slugify==8.0.4
614641
# via
615642
# -c requirements/ci.txt
@@ -620,6 +647,7 @@ pyyaml==6.0.1
620647
# -c requirements/ci.txt
621648
# -r requirements/ci.txt
622649
# drf-spectacular
650+
# pydantic-settings
623651
# vcrpy
624652
qrcode==7.4.2
625653
# via
@@ -760,6 +788,8 @@ typing-extensions==4.11.0
760788
# -c requirements/ci.txt
761789
# -r requirements/ci.txt
762790
# mozilla-django-oidc-db
791+
# pydantic
792+
# pydantic-core
763793
# pyee
764794
# qrcode
765795
# zgw-consumers

backend/src/openarchiefbeheer/conf/base.py

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"mozilla_django_oidc",
133133
"mozilla_django_oidc_db",
134134
"privates",
135+
"django_setup_configuration",
135136
# Project applications.
136137
"openarchiefbeheer.accounts",
137138
"openarchiefbeheer.destruction",
@@ -645,8 +646,17 @@
645646
"OIDC_RENEW_ID_TOKEN_EXPIRY_SECONDS", default=60 * 15
646647
)
647648

649+
#
648650
# Django privates
649651
#
650652
PRIVATE_MEDIA_ROOT = os.path.join(BASE_DIR, "private_media")
651653

652654
PRIVATE_MEDIA_URL = "/private-media/"
655+
656+
#
657+
# Django setup configuration
658+
#
659+
SETUP_CONFIGURATION_STEPS = [
660+
"zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep",
661+
"openarchiefbeheer.config.setup_configuration.steps.APIConfigConfigurationStep",
662+
]

backend/src/openarchiefbeheer/config/setup_configuration/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django_setup_configuration import ConfigurationModel
2+
from django_setup_configuration.fields import DjangoModelRef
3+
4+
from ..models import APIConfig
5+
6+
7+
class APIConfigConfigurationModel(ConfigurationModel):
8+
selectielijst_service_identifier: str = DjangoModelRef(
9+
APIConfig, "selectielijst_api_service"
10+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from django_setup_configuration import BaseConfigurationStep
2+
from django_setup_configuration.exceptions import ConfigurationRunFailed
3+
from zgw_consumers.models import Service
4+
5+
from ..models import APIConfig
6+
from .models import APIConfigConfigurationModel
7+
8+
9+
class APIConfigConfigurationStep(BaseConfigurationStep[APIConfigConfigurationModel]):
10+
"""Configure API settings"""
11+
12+
config_model = APIConfigConfigurationModel
13+
enable_setting = "api_configuration_enabled"
14+
namespace = "api_configuration"
15+
verbose_name = "API Configuration"
16+
17+
def execute(self, model: APIConfigConfigurationModel) -> None:
18+
config = APIConfig.get_solo()
19+
20+
try:
21+
config.selectielijst_api_service = Service.objects.get(
22+
slug=model.selectielijst_service_identifier
23+
)
24+
except Service.DoesNotExist:
25+
raise ConfigurationRunFailed(
26+
f"Could not find an existing `selectielijst` service with identifier `{model.selectielijst_service_identifier}`."
27+
" Make sure it is already configured, manually or by first running the configuration step of `zgw_consumers`."
28+
)
29+
30+
config.save(update_fields=["selectielijst_api_service"])

backend/src/openarchiefbeheer/config/setup_configuration/tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
api_configuration_enabled: True
2+
api_configuration:
3+
selectielijst_service_identifier: selectielijst

0 commit comments

Comments
 (0)