-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [#485] Merge closed branch * [#485] Add SitesConfigurationStep and TokenAuthConfigurationStep in settings * [#485] Black and isort * [#485] Create Step and Model * [#485] Fix requirements * [#485] Fix yaml file * [#485] Update namespace * [#485] Fix tests * [#485] Update generate tokens * [#485] Fix docs * [#485] Add missing field in docs * [#485] Add validate_no_empty for identifier * [#485] Open-api-framework new realease * [#485] Run bin/generate_envvar_docs.sh * [#485] Update fixtures demodata * [#485] Add sites_config_enable in data.yaml
- Loading branch information
1 parent
33faf07
commit 64fa395
Showing
23 changed files
with
826 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
sites_config_enable: true | ||
sites_config: | ||
items: | ||
- domain: example.com | ||
name: Example site | ||
|
||
|
||
zgw_consumers_config_enable: true | ||
zgw_consumers: | ||
services: | ||
|
@@ -19,20 +26,36 @@ zgw_consumers: | |
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 | ||
|
||
|
||
objecttypes_config_enable: true | ||
objecttypes: | ||
items: | ||
- uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 | ||
name: Object Type 1 | ||
service_identifier: objecttypes-api | ||
|
||
|
||
tokenauth_config_enable: true | ||
tokenauth: | ||
items: | ||
- identifier: token-1 | ||
token: 18b2b74ef994314b84021d47b9422e82b685d82f | ||
contact_person: Person 1 | ||
email: [email protected] | ||
organization: Organization 1 | ||
application: Application 1 | ||
administration: Administration 1 | ||
is_superuser: true | ||
|
||
|
||
oidc_db_config_enable: true | ||
oidc_db_config_admin_auth: | ||
items: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,28 @@ created. An example of a configuration could be seen below: | |
Tokens configuration | ||
-------------------- | ||
Create or update the (single) YAML configuration file with your settings: | ||
|
||
.. code-block:: yaml | ||
... | ||
tokenauth_config_enable: true | ||
tokenauth: | ||
items: | ||
- identifier: token-1 | ||
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067 | ||
contact_person: Person 1 | ||
email: [email protected] | ||
organization: Organization XYZ # optional | ||
application: Application XYZ # optional | ||
administration: Administration XYZ # optional | ||
is_superuser: true # optional | ||
- identifier: token-2 | ||
token: 7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799 | ||
contact_person: Person 2 | ||
email: [email protected] | ||
... | ||
Mozilla-django-oidc-db | ||
---------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django_setup_configuration.models import ConfigurationModel | ||
|
||
from objects.token.models import TokenAuth | ||
|
||
|
||
class TokenAuthConfigurationModel(ConfigurationModel): | ||
class Meta: | ||
django_model_refs = { | ||
TokenAuth: ( | ||
"identifier", | ||
"token", | ||
"contact_person", | ||
"email", | ||
"organization", | ||
"application", | ||
"administration", | ||
"is_superuser", | ||
) | ||
} | ||
|
||
|
||
class TokenAuthGroupConfigurationModel(ConfigurationModel): | ||
items: list[TokenAuthConfigurationModel] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import logging | ||
|
||
from django.core.exceptions import ValidationError | ||
from django.db import IntegrityError | ||
|
||
from django_setup_configuration.configuration import BaseConfigurationStep | ||
from django_setup_configuration.exceptions import ConfigurationRunFailed | ||
|
||
from objects.setup_configuration.models.token_auth import ( | ||
TokenAuthGroupConfigurationModel, | ||
) | ||
from objects.token.models import TokenAuth | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TokenAuthConfigurationStep( | ||
BaseConfigurationStep[TokenAuthGroupConfigurationModel] | ||
): | ||
""" | ||
Configure tokens for other applications to access Objects API | ||
""" | ||
|
||
namespace = "tokenauth" | ||
enable_setting = "tokenauth_config_enable" | ||
|
||
verbose_name = "Configuration to set up authentication tokens for objects" | ||
config_model = TokenAuthGroupConfigurationModel | ||
|
||
def execute(self, model: TokenAuthGroupConfigurationModel) -> None: | ||
if len(model.items) == 0: | ||
logger.warning("No tokens provided for configuration") | ||
|
||
for item in model.items: | ||
logger.info(f"Configuring {item.identifier}") | ||
|
||
model_kwargs = { | ||
"identifier": item.identifier, | ||
"token": item.token, | ||
"contact_person": item.contact_person, | ||
"email": item.email, | ||
"organization": item.organization, | ||
"application": item.application, | ||
"administration": item.administration, | ||
"is_superuser": item.is_superuser, | ||
} | ||
|
||
token_instance = TokenAuth(**model_kwargs) | ||
|
||
try: | ||
token_instance.full_clean(exclude=("id",), validate_unique=False) | ||
except ValidationError as exception: | ||
exception_message = ( | ||
f"Validation error(s) occured for {item.identifier}." | ||
) | ||
raise ConfigurationRunFailed(exception_message) from exception | ||
|
||
logger.debug(f"No validation errors found for {item.identifier}") | ||
|
||
try: | ||
logger.debug(f"Saving {item.identifier}") | ||
|
||
TokenAuth.objects.update_or_create( | ||
identifier=item.identifier, | ||
defaults={ | ||
key: value | ||
for key, value in model_kwargs.items() | ||
if key != "identifier" | ||
}, | ||
) | ||
except IntegrityError as exception: | ||
exception_message = f"Failed configuring token {item.identifier}." | ||
raise ConfigurationRunFailed(exception_message) from exception | ||
|
||
logger.info(f"Configured {item.identifier}") |
3 changes: 3 additions & 0 deletions
3
src/objects/setup_configuration/tests/files/token_auth/invalid_setup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tokenauth_config_enable: true | ||
tokenauth: | ||
items: |
20 changes: 20 additions & 0 deletions
20
src/objects/setup_configuration/tests/files/token_auth/valid_setup_complete.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
tokenauth_config_enable: true | ||
tokenauth: | ||
items: | ||
- identifier: token-1 | ||
token: 18b2b74ef994314b84021d47b9422e82b685d82f | ||
contact_person: Person 1 | ||
email: [email protected] | ||
organization: Organization 1 | ||
application: Application 1 | ||
administration: Administration 1 | ||
is_superuser: True | ||
|
||
- identifier: token-2 | ||
token: e882642bd0ec2482adcdc97258c2e6f98cb06d85 | ||
contact_person: Person 2 | ||
email: [email protected] | ||
organization: Organization 2 | ||
application: Application 2 | ||
administration: Administration 2 | ||
is_superuser: True |
12 changes: 12 additions & 0 deletions
12
src/objects/setup_configuration/tests/files/token_auth/valid_setup_default.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
tokenauth_config_enable: true | ||
tokenauth: | ||
items: | ||
- identifier: token-1 | ||
token: 18b2b74ef994314b84021d47b9422e82b685d82f | ||
contact_person: Person 1 | ||
email: [email protected] | ||
|
||
- identifier: token-2 | ||
token: e882642bd0ec2482adcdc97258c2e6f98cb06d85 | ||
contact_person: Person 2 | ||
email: [email protected] |
Oops, something went wrong.