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

Offer metadata as file for download #77

Merged
merged 1 commit into from
Jul 17, 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
3 changes: 3 additions & 0 deletions digid_eherkenning/metadata_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
MetadataView.as_view(
config_model=DigidConfiguration,
metadata_generator=generate_digid_metadata,
filename="digid-metadata.xml",
),
name="digid",
),
Expand All @@ -24,6 +25,7 @@
MetadataView.as_view(
config_model=EherkenningConfiguration,
metadata_generator=generate_eherkenning_metadata,
filename="eh-metadata.xml",
),
name="eherkenning",
),
Expand All @@ -32,6 +34,7 @@
MetadataView.as_view(
config_model=EherkenningConfiguration,
metadata_generator=generate_dienst_catalogus_metadata,
filename="dienstcatalogus.xml",
),
name="eh-dienstcatalogus",
),
Expand Down
2 changes: 1 addition & 1 deletion digid_eherkenning/saml2/digid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def generate_digid_metadata() -> bytes:
client.saml2_setting_kwargs = {"sp_validation_only": True}
metadata = client.create_metadata()
return (
b"<?xml version='1.0' encoding='UTF-8'?>" + metadata
b'<?xml version="1.0" encoding="UTF-8"?>\n' + metadata
if not metadata.startswith(b"<?xml")
else metadata
)
Expand Down
2 changes: 1 addition & 1 deletion digid_eherkenning/saml2/eherkenning.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def generate_eherkenning_metadata():
client.saml2_setting_kwargs = {"sp_validation_only": True}
metadata = client.create_metadata()
return (
b'<?xml version="1.0" encoding="UTF-8"?>' + metadata
b'<?xml version="1.0" encoding="UTF-8"?>\n' + metadata
if not metadata.startswith(b"<?xml")
else metadata
)
Expand Down
11 changes: 10 additions & 1 deletion digid_eherkenning/views/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class MetadataView(View):
config_model: Type[BaseConfiguration] = BaseConfiguration
metadata_generator: Callable[[], bytes] = lambda: b""
filename: str = "metadata.xml"

def get(self, request: HttpRequest) -> HttpResponseBase:
config = self.config_model.get_solo()
Expand Down Expand Up @@ -43,7 +44,15 @@ def get(self, request: HttpRequest) -> HttpResponseBase:
},
)
return self._get_generic_error_response()
return HttpResponse(metadata, content_type="text/xml")
# RFC 6266, 4.1, and RFC 2616 Section 2.2
sanitized_filename = self.filename.replace('"', r"\"")
return HttpResponse(
metadata,
content_type="text/xml",
headers={
"Content-Disposition": f'attachment; filename="{sanitized_filename}"',
},
)

@staticmethod
def _get_generic_error_response() -> HttpResponseBadRequest:
Expand Down