Skip to content

Commit

Permalink
🐛 Allow multiple service providers.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeribekker committed Mar 5, 2024
1 parent b88c7eb commit ba2027e
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions digid_eherkenning/management/commands/show_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,40 @@ def handle(self, **options):
# etree.parse didn't like a URL directly.
tree = etree.fromstring(response.content)

service_provider = tree.xpath(
service_providers = tree.xpath(
f"esc:ServiceProvider[esc:ServiceProviderID/text()='{oin}']",
namespaces=NAMESPACES,
)

if len(service_provider) > 1:
self.stderr.write("Found multiple service providers for this OIN.")
return
elif len(service_provider) < 1:
if len(service_providers) < 1:
self.stderr.write("Found no service providers for this OIN.")
return

service_provider = service_provider[0]
service_definitions = service_provider.xpath(
"esc:ServiceDefinition", namespaces=NAMESPACES
)

org_name = service_provider.xpath(
"esc:OrganizationDisplayName[@xml:lang='nl']/text()", namespaces=NAMESPACES
)[0]
for service_provider in service_providers:
service_definitions = service_provider.xpath(
"esc:ServiceDefinition", namespaces=NAMESPACES
)

self.stdout.write(f"Service provider organization: {org_name}")
for sd in service_definitions:
sd_uuid = sd.xpath("esc:ServiceUUID/text()", namespaces=NAMESPACES)[0]
sd_name = sd.xpath(
"esc:ServiceName[@xml:lang='nl']/text()", namespaces=NAMESPACES
org_name = service_provider.xpath(
"esc:OrganizationDisplayName[@xml:lang='nl']/text()", namespaces=NAMESPACES
)[0]
sd_description = sd.xpath(
"esc:ServiceDescription[@xml:lang='nl']/text()", namespaces=NAMESPACES
)[0]

self.stdout.write(f"+-- Service definition: {sd_name} ({sd_description})")

service_instance_ids = service_provider.xpath(
f"esc:ServiceInstance[esc:InstanceOfService[text()='{sd_uuid}']]/esc:ServiceID/text()",
namespaces=NAMESPACES,
)

for si in service_instance_ids:
self.stdout.write(f" +-- Service ID: {si}")
self.stdout.write(f"Service provider organization: {org_name}")
for sd in service_definitions:
sd_uuid = sd.xpath("esc:ServiceUUID/text()", namespaces=NAMESPACES)[0]
sd_name = sd.xpath(
"esc:ServiceName[@xml:lang='nl']/text()", namespaces=NAMESPACES
)[0]
sd_description = sd.xpath(
"esc:ServiceDescription[@xml:lang='nl']/text()", namespaces=NAMESPACES
)[0]

self.stdout.write(f"+-- Service definition: {sd_name} ({sd_description})")

service_instance_ids = service_provider.xpath(
f"esc:ServiceInstance[esc:InstanceOfService[text()='{sd_uuid}']]/esc:ServiceID/text()",
namespaces=NAMESPACES,
)

for si in service_instance_ids:
self.stdout.write(f" +-- Service ID: {si}")

0 comments on commit ba2027e

Please sign in to comment.