From 3d9d3d89ef9aebe211f8590c52af4b502f668ba5 Mon Sep 17 00:00:00 2001 From: Andy Beverley Date: Thu, 8 Aug 2024 17:01:24 +0100 Subject: [PATCH] Allow multiple locations for same certificate --- lib/Brass/Schema/Result/Cert.pm | 41 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/Brass/Schema/Result/Cert.pm b/lib/Brass/Schema/Result/Cert.pm index 08cc941..491e96e 100644 --- a/lib/Brass/Schema/Result/Cert.pm +++ b/lib/Brass/Schema/Result/Cert.pm @@ -71,27 +71,28 @@ sub delete_cert sub as_hash_single { my $self = shift; - # This should only be called as part of a query that returns only one - # location and use - error __"More locations than expected for this certificate" - if $self->cert_locations > 1; - error __"No locations defined for this certificate" - if !$self->cert_locations; - my $location = $self->cert_locations->next; - - error __"More uses than expected for this certificate" - if $location->cert_location_uses > 1; - error __"No use defined for this certificate" - if !$location->cert_location_uses; - my $use = $location->cert_location_uses->next->use; - my $hash = $self->_as_hash; - $hash->{use} = $use->name, - $hash->{filename_cert} = $location->filename_cert; - $hash->{filename_key} = $location->filename_key; - $hash->{filename_ca} = $location->filename_ca; - $hash->{file_user} = $location->file_user; - $hash->{file_group} = $location->file_group; + + foreach my $location ($self->cert_locations) + { + error __"More uses than expected for this certificate" + if $location->cert_location_uses > 1; + error __"No use defined for this certificate" + if !$location->cert_location_uses; + + my $use = $location->cert_location_uses->next->use; + + $hash->{locations} ||= []; + + push @{$hash->{locations}}, { + use => $use->name, + filename_cert => $location->filename_cert, + filename_key => $location->filename_key, + filename_ca => $location->filename_ca, + file_user => $location->file_user, + file_group => $location->file_group, + } + } $hash; }