Skip to content

Commit

Permalink
Merge pull request #63 from maykinmedia/feature/setup-config-example
Browse files Browse the repository at this point in the history
📝 Update setup config docs to use example directive
  • Loading branch information
stevenbal authored Feb 6, 2025
2 parents c90d14f + 29b6c8f commit 10dc37c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx.ext.autodoc"]
extensions = [
"sphinx.ext.autodoc",
"django_setup_configuration.documentation.setup_config_example",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
52 changes: 37 additions & 15 deletions docs/setup_config.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
Setup configuration
===================

This library has an optional integration with ``django-setup-configuration``, see the
`documentation <https://django-setup-configuration.readthedocs.io/en/latest/>`_
for more information on how to run ``setup_configuration``.
To make use of this, you must install the ``setup-configuration`` dependency group:

.. code-block:: bash
pip install commonground-api-common[setup-configuration]
Loading JWTSecrets from a YAML file
***************************************************
***********************************

This library provides a ``ConfigurationStep``
(from the library ``django-setup-configuration``, see the
`documentation <https://github.com/maykinmedia/django-setup-configuration>`_
for more information on how to run ``setup_configuration``)
to configure the client credentials.
This library provides a ``ConfigurationStep`` to configure the client credentials.

To add this step to your configuration steps, add ``django_setup_configuration`` to ``INSTALLED_APPS`` and add the following setting:

Expand All @@ -24,14 +30,30 @@ The YAML file that is passed to ``setup_configuration`` must set the
``vng_api_common_credentials_config_enable`` flag to ``true`` to enable the step. Any number of ``identifier`` and
``secret`` pairs can be defined under ``vng_api_common_credentials.items``

Example file:
You can use the following example YAML and adapt it to your needs:

.. setup-config-example:: vng_api_common.contrib.setup_configuration.steps.JWTSecretsConfigurationStep


Loading Applicaties from a YAML file
************************************

This library also provides a ``ConfigurationStep`` to configure the applicaties.

To add this step to your configuration steps, add ``django_setup_configuration`` to ``INSTALLED_APPS`` and add the following setting:

.. code:: python
SETUP_CONFIGURATION_STEPS = [
...
"vng_api_common.contrib.setup_configuration.steps.ApplicatieConfigurationStep"
...
]
The YAML file that is passed to ``setup_configuration`` must set the
``vng_api_common_applicaties_config_enable`` flag to ``true`` to enable the step.
Any number of ``Applicaties`` can be defined under ``vng_api_common_applicaties.items``

.. code:: yaml
You can use the following example YAML and adapt it to your needs:

vng_api_common_credentials_config_enable: True
vng_api_common_credentials:
items:
- identifier: user-id
secret: super-secret
- identifier: user-id2
secret: super-secret2
.. setup-config-example:: vng_api_common.contrib.setup_configuration.steps.ApplicatieConfigurationStep
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ tests =
testutils =
zgw-consumers-oas
setup-configuration =
django-setup-configuration>=0.4.0
django-setup-configuration>=0.7.0
pep8 = flake8
coverage = pytest-cov
docs =
Expand Down
12 changes: 10 additions & 2 deletions vng_api_common/contrib/setup_configuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ class Meta:
"secret",
]
}
extra_kwargs = {
"identifier": {"examples": ["application-name"]},
"secret": {"examples": ["modify-this"]},
}


class JWTSecretsConfigurationModel(ConfigurationModel):
items: list[SingleJWTSecretConfigurationModel] = Field(default_factory=list)
items: list[SingleJWTSecretConfigurationModel] = Field()


class SingleApplicatieConfigurationModel(ConfigurationModel):
Expand All @@ -26,7 +30,11 @@ class Meta:
django_model_refs = {
Applicatie: ["uuid", "client_ids", "label", "heeft_alle_autorisaties"]
}
extra_kwargs = {
"client_ids": {"examples": [["open-notificaties-prod"]]},
"label": {"examples": ["Open Notificaties (productie)"]},
}


class ApplicatieConfigurationModel(ConfigurationModel):
items: list[SingleApplicatieConfigurationModel] = Field(default_factory=list)
items: list[SingleApplicatieConfigurationModel]
2 changes: 1 addition & 1 deletion vng_api_common/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ValidatieFoutSerializer(FoutSerializer):


def add_choice_values_help_text(
choices: Union[models.Choices, List[Tuple[str, str]]]
choices: Union[models.Choices, List[Tuple[str, str]]],
) -> str:
is_dj_choices = inspect.isclass(choices) and issubclass(choices, models.Choices)

Expand Down
4 changes: 2 additions & 2 deletions vng_api_common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ def _test_nrc_config(check_autorisaties_subscription=True) -> list:
nrc_client: Optional[Client] = NotificationsConfig.get_client()

if not nrc_client:
return [((_("NRC"), _("Missing"), False))]
return [(_("NRC"), _("Missing"), False)]

has_nrc_auth = nrc_client.auth is not None if nrc_client else False

if not nrc_config.notifications_api_service:
checks = [((_("NRC"), _("Missing"), False))]
checks = [(_("NRC"), _("Missing"), False)]
return checks

checks = [
Expand Down

0 comments on commit 10dc37c

Please sign in to comment.