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

[#484] Notification channel setup config #491

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 9 additions & 5 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/bin/bash

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

#set -e
${SCRIPTPATH}/wait_for_db.sh
set -e

src/manage.py migrate
src/manage.py setup_configuration --no-selftest
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
46 changes: 20 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,17 @@ services:
build: &web_build
context: .
environment: &web_env
- DJANGO_SETTINGS_MODULE=objects.conf.docker
- SECRET_KEY=${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
- IS_HTTPS=no
- ALLOWED_HOSTS=*
- CACHE_DEFAULT=redis:6379/0
- CACHE_AXES=redis:6379/0
- CELERY_BROKER_URL=redis://redis:6379/1
- CELERY_RESULT_BACKEND=redis://redis:6379/1
- CELERY_LOGLEVEL=DEBUG
- DISABLE_2FA=${DISABLE_2FA:-yes}
- SUBPATH=${SUBPATH}
# setup_configuration env vars
- SITES_CONFIG_ENABLE=yes
- OBJECTS_DOMAIN=web:8000
- OBJECTS_ORGANIZATION=Objects
- OBJECTS_OBJECTTYPES_CONFIG_ENABLE=false
# - OBJECTTYPES_API_ROOT=https://objecttypes.example.com/api/v2/
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
- DEMO_CONFIG_ENABLE=yes
- DEMO_TOKEN=demo-random-string
- DEMO_PERSON=Demo
- [email protected]
DJANGO_SETTINGS_MODULE: objects.conf.docker
SECRET_KEY: ${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
IS_HTTPS: no
ALLOWED_HOSTS: '*'
CACHE_DEFAULT: redis:6379/0
CACHE_AXES: redis:6379/0
CELERY_BROKER_URL: redis://redis:6379/1
CELERY_RESULT_BACKEND: redis://redis:6379/1
CELERY_LOGLEVEL: DEBUG
DISABLE_2FA: ${DISABLE_2FA:-yes}
SUBPATH: ${SUBPATH}
healthcheck:
test: ["CMD", "python", "-c", "import requests; exit(requests.head('http://localhost:8000/admin/').status_code not in [200, 302])"]
interval: 30s
Expand All @@ -46,7 +35,7 @@ services:
# This should allow for enough time for migrations to run before the max
# retries have passed. This healthcheck in turn allows other containers
# to wait for the database migrations.
start_period: 30s
start_period: 30s
ports:
- 8000:8000
depends_on:
Expand All @@ -58,12 +47,17 @@ services:
web-init:
image: maykinmedia/objects-api:latest
build: *web_build
environment: *web_env
environment:
<<: *web_env
#
# Django-setup-configuration
RUN_SETUP_CONFIG: ${RUN_SETUP_CONFIG:-true}
command: /setup_configuration.sh
depends_on:
- db
- redis
volumes: *web_volumes
volumes:
- ./docker/setup_configuration:/app/setup_configuration

celery:
image: maykinmedia/objects-api:latest
Expand All @@ -75,7 +69,7 @@ services:
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
start_period: 10s
depends_on:
web:
condition: service_healthy
Expand Down
18 changes: 18 additions & 0 deletions docker/setup_configuration/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
zgw_consumers_config_enable: true
zgw_consumers:
services:
- identifier: notifications-api
label: Notificaties API
api_root: http://notificaties.local/api/v1/
api_connection_check_path: notificaties
api_type: nrc
auth_type: api_key
header_key: Authorization
header_value: Token ba9d233e95e04c4a8a661a27daffe7c9bd019067

notifications_config_enable: true
notifications_config:
notifications_api_service_identifier: notifications-api
notification_delivery_max_retries: 1
notification_delivery_retry_backoff: 2
notification_delivery_retry_backoff_max: 3
118 changes: 34 additions & 84 deletions docs/installation/config_cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ Configuration (CLI)
After deploying Objecttypes API and Objects API, they need to be configured to be fully functional. The
command line tool `setup_configuration`_ assist with this configuration:

* It uses environment variables for all configuration choices, therefore you can integrate this with your
infrastructure tooling such as init containers and/or Kubernetes Jobs.
* The command can self-test the configuration to detect problems early on

You can get the full command documentation with:

.. code-block:: bash
Expand All @@ -28,86 +24,55 @@ Preparation
===========

The command executes the list of pluggable configuration steps, and each step
required specific environment variables, that should be prepared.
Here is the description of all available configuration steps and the environment variables,
use by each step for both APIs.

requires specific configuration information, that should be prepared.
Here is the description of all available configuration steps and the configuration
format, use by each step.

Objects API
===========

Sites configuration
-------------------
Objecttypes connection configuration
------------------------------------

Configure the domain where Objects API is hosted

* ``SITES_CONFIG_ENABLE``: enable Site configuration. Defaults to ``False``.
* ``OBJECTS_DOMAIN``: a ``[host]:[port]`` or ``[host]`` value. Required.
* ``OBJECTS_ORGANIZATION``: name of Objects API organization. Required.
Tokens configuration
-------------------

Objecttypes configuration
Notifications configuration
-------------------------

Objects API uses Objecttypes API to validate data against JSON schemas, therefore
it should be able to request Objecttypes API.

* ``OBJECTS_OBJECTTYPES_CONFIG_ENABLE``: enable Objecttypes configuration. Defaults
to ``False``.
* ``OBJECTTYPES_API_ROOT``: full URL to the Objecttypes API root, for example
``https://objecttypes.gemeente.local/api/v1/``. Required.
* ``OBJECTTYPES_API_OAS``: full URL to the Objecttypes OpenAPI specification.
* ``OBJECTS_OBJECTTYPES_TOKEN``: authorization token. Required.
* ``OBJECTS_OBJECTTYPES_PERSON``: Objects API contact person. Required.
* ``OBJECTS_OBJECTTYPES_EMAIL``: Objects API contact email. Required.

Demo user configuration
-----------------------

Demo user can be created to check if Objects API work. It has superuser permissions,
so its creation is not recommended on production environment.

* ``DEMO_CONFIG_ENABLE``: enable demo user configuration. Defaults to ``False``.
* ``DEMO_PERSON``: demo user contact person. Required.
* ``DEMO_EMAIL``: demo user email. Required.
* ``DEMO_TOKEN``: demo token. Required.


Objecttypes API
===============

ObjectTypes API has similar configuration steps as the Objects API.
Mozilla-django-oidc-db
----------------------

Sites configuration
-------------------

Configure the domain where Objects API is hosted

* ``SITES_CONFIG_ENABLE``: enable Site configuration. Defaults to ``False``.
* ``OBJECTTYPES_DOMAIN``: a ``[host]:[port]`` or ``[host]`` value. Required.
* ``OBJECTTYPES_ORGANIZATION``: name of Objecttypes API organization. Required.

Objects configuration
---------------------

Objects API uses Objecttypes API to validate data against JSON schemas, therefore
it should be able to request Objecttypes API.
Notifications configuration
-------------------------

* ``OBJECTS_OBJECTTYPES_CONFIG_ENABLE``: enable Objecttypes configuration. Defaults
to ``False``.
* ``OBJECTTYPES_API_ROOT``: full URL to the Objecttypes API root, for example
``https://objecttypes.gemeente.local/api/v1/``. Required.
* ``OBJECTTYPES_API_OAS``: full URL to the Objecttypes OpenAPI specification.
* ``OBJECTS_OBJECTTYPES_TOKEN``: authorization token. Required.
To configure sending notifications for the application ensure there is a ``services``
item present that matches the ``notifications_api_service_identifier`` in the
``notifications_config`` namespace:

Demo user configuration
-----------------------
.. code-block:: yaml
...

The similar configuration as in Objects API.
zgw_consumers_config_enable: true
zgw_consumers:
services:
- identifier: notifications-api
label: Notificaties API
api_root: http://notificaties.local/api/v1/
api_connection_check_path: notificaties
api_type: nrc
auth_type: api_key

* ``DEMO_CONFIG_ENABLE``: enable demo user configuration. Defaults to ``False``.
* ``DEMO_PERSON``: demo user contact person. Required.
* ``DEMO_EMAIL``: demo user email. Required.
* ``DEMO_TOKEN``: demo token. Required.
notifications_config_enable: true
notifications_config:
notifications_api_service_identifier: notifications-api
notification_delivery_max_retries: 1
notification_delivery_retry_backoff: 2
notification_delivery_retry_backoff_max: 3
....


Execution
Expand All @@ -119,19 +84,4 @@ tested.

.. code-block:: bash

src/manage.py setup_configuration


You can skip the self-tests by using the ``--no-selftest`` flag.

.. code-block:: bash

src/manage.py setup_configuration --no-self-test


``setup_configuration`` command checks if the configuration already exists before changing it.
If you want to change some of the values of the existing configuration you can use ``--overwrite`` flag.

.. code-block:: bash

src/manage.py setup_configuration --overwrite
src/manage.py setup_configuration --yaml-file /path/to/config.yaml
3 changes: 2 additions & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ jsonschema
furl

# Common ground libraries
notifications-api-common
notifications-api-common[setup-configuration]
zgw-consumers[setup-configuration]
30 changes: 25 additions & 5 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,11 @@ django-sendfile2==0.7.0
# via django-privates
django-sessionprofile==3.0.0
# via open-api-framework
django-setup-configuration==0.1.0
# via open-api-framework
django-setup-configuration==0.4.0
# via
# notifications-api-common
# open-api-framework
# zgw-consumers
django-simple-certmanager==1.4.1
# via zgw-consumers
django-solo==2.2.0
Expand Down Expand Up @@ -202,6 +207,7 @@ furl==2.1.3
# via
# -r requirements/base.in
# ape-pie
# notifications-api-common
glom==23.5.0
# via
# -r requirements/base.in
Expand Down Expand Up @@ -238,7 +244,7 @@ mozilla-django-oidc==4.0.0
# via mozilla-django-oidc-db
mozilla-django-oidc-db==0.19.0
# via open-api-framework
notifications-api-common==0.3.1
notifications-api-common[setup-configuration]==0.4.0
# via
# -r requirements/base.in
# commonground-api-common
Expand All @@ -260,6 +266,14 @@ psycopg2==2.9.9
# via open-api-framework
pycparser==2.20
# via cffi
pydantic==2.9.2
# via
# django-setup-configuration
# pydantic-settings
pydantic-core==2.23.4
# via pydantic
pydantic-settings[yaml]==2.6.1
# via django-setup-configuration
pyjwt==2.4.0
# via
# commonground-api-common
Expand All @@ -278,7 +292,9 @@ python-dateutil==2.9.0.post0
python-decouple==3.8
# via open-api-framework
python-dotenv==1.0.0
# via open-api-framework
# via
# open-api-framework
# pydantic-settings
pytz==2024.1
# via
# drf-yasg
Expand All @@ -288,6 +304,7 @@ pyyaml==6.0.1
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
qrcode==6.1
# via django-two-factor-auth
redis==3.5.3
Expand Down Expand Up @@ -321,6 +338,8 @@ tornado==6.4.1
typing-extensions==4.9.0
# via
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# zgw-consumers
tzdata==2024.1
# via celery
Expand Down Expand Up @@ -349,8 +368,9 @@ webencodings==0.5.1
# via bleach
wrapt==1.14.1
# via elastic-apm
zgw-consumers==0.35.1
zgw-consumers[setup-configuration]==0.36.1
# via
# -r requirements/base.in
# commonground-api-common
# notifications-api-common
# open-api-framework
Expand Down
Loading
Loading