-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#45] Automated metadata file retrieval and parsing
Refactored base configuration model in order to provide a url and do all the fetching and parsing based on this. The urls are cached for a day and the xml file is updated via a command.
- Loading branch information
Showing
12 changed files
with
624 additions
and
7 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
42 changes: 42 additions & 0 deletions
42
digid_eherkenning/management/commands/update_stored_metadata.py
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,42 @@ | ||
from django.core.cache import cache | ||
from django.core.management import BaseCommand, CommandError | ||
|
||
from digid_eherkenning.models.digid import DigidConfiguration | ||
from digid_eherkenning.models.eherkenning import EherkenningConfiguration | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Updates the stored metadata file and repopulates the db fields." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--digid", | ||
action="store_true", | ||
help="Update the DigiD configuration metadata.", | ||
) | ||
parser.add_argument( | ||
"--eherkenning", | ||
action="store_true", | ||
help="Update the Eherkenning configuration metadata.", | ||
) | ||
|
||
def handle(self, **options): | ||
if options["digid"]: | ||
config = DigidConfiguration.get_solo() | ||
elif options["eherkenning"]: | ||
config = EherkenningConfiguration.get_solo() | ||
else: | ||
raise CommandError( | ||
"A required argument is missing. Please provide either digid or eherkenning." | ||
) | ||
|
||
# delete the cache for the urls in order to trigger fetching and parsing xml again | ||
if config.metadata_file_source and cache.get(config._meta.object_name): | ||
cache.delete(config._meta.object_name) | ||
config.save() | ||
|
||
self.stdout.write(self.style.SUCCESS("Update was successful")) | ||
else: | ||
self.stdout.write( | ||
self.style.WARNING("Update failed, no metadata file source found") | ||
) |
83 changes: 83 additions & 0 deletions
83
digid_eherkenning/migrations/0006_digidconfiguration_metadata_file_source_and_more.py
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,83 @@ | ||
# Generated by Django 4.2.6 on 2023-10-12 14:36 | ||
|
||
from django.db import migrations, models | ||
import privates.fields | ||
import privates.storages | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
( | ||
"digid_eherkenning", | ||
"0005_alter_eherkenningconfiguration_eh_service_instance_uuid_and_more", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="digidconfiguration", | ||
name="metadata_file_source", | ||
field=models.URLField( | ||
default="", | ||
help_text="The URL-source where the XML metadata file can be retrieved from.", | ||
max_length=255, | ||
verbose_name="metadata file(XML) URL", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="eherkenningconfiguration", | ||
name="metadata_file_source", | ||
field=models.URLField( | ||
default="", | ||
help_text="The URL-source where the XML metadata file can be retrieved from.", | ||
max_length=255, | ||
verbose_name="metadata file(XML) URL", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="digidconfiguration", | ||
name="idp_metadata_file", | ||
field=privates.fields.PrivateMediaFileField( | ||
blank=True, | ||
help_text="The metadata file of the identity provider. This is auto populated by the retrieved metadata XML file.", | ||
null=True, | ||
storage=privates.storages.PrivateMediaFileSystemStorage(), | ||
upload_to="", | ||
verbose_name="identity provider metadata", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="digidconfiguration", | ||
name="idp_service_entity_id", | ||
field=models.CharField( | ||
blank=True, | ||
help_text="Example value: 'https://was-preprod1.digid.nl/saml/idp/metadata'. Note that this must match the 'entityID' attribute on the 'md:EntityDescriptor' node found in the Identity Provider's metadata. This is auto populated by the retrieved metadata XML file.", | ||
max_length=255, | ||
null=True, | ||
verbose_name="identity provider service entity ID", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="eherkenningconfiguration", | ||
name="idp_metadata_file", | ||
field=privates.fields.PrivateMediaFileField( | ||
blank=True, | ||
help_text="The metadata file of the identity provider. This is auto populated by the retrieved metadata XML file.", | ||
null=True, | ||
storage=privates.storages.PrivateMediaFileSystemStorage(), | ||
upload_to="", | ||
verbose_name="identity provider metadata", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="eherkenningconfiguration", | ||
name="idp_service_entity_id", | ||
field=models.CharField( | ||
blank=True, | ||
help_text="Example value: 'https://was-preprod1.digid.nl/saml/idp/metadata'. Note that this must match the 'entityID' attribute on the 'md:EntityDescriptor' node found in the Identity Provider's metadata. This is auto populated by the retrieved metadata XML file.", | ||
max_length=255, | ||
null=True, | ||
verbose_name="identity provider service entity ID", | ||
), | ||
), | ||
] |
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
Oops, something went wrong.