From 25bde4f0899489bc0dcee2afceea53cb5d0c7914 Mon Sep 17 00:00:00 2001 From: Sorah Fukumori Date: Sat, 19 May 2018 10:57:18 +0900 Subject: [PATCH] route53: Support multiple RR for the single name ACME server may need multiple authorizations for the single name. In dns-01 challenge type, the expected workflow is to create multiple TXT records. Closes https://github.com/sorah/acmesmith/issues/31 --- lib/acmesmith/challenge_responders/route53.rb | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/acmesmith/challenge_responders/route53.rb b/lib/acmesmith/challenge_responders/route53.rb index b26b917..365ae74 100644 --- a/lib/acmesmith/challenge_responders/route53.rb +++ b/lib/acmesmith/challenge_responders/route53.rb @@ -55,7 +55,9 @@ def request_changing_rrset(zone_and_batches, comment: nil) puts " * #{zone_id}:" change_batch.fetch(:changes).each do |b| rrset = b.fetch(:resource_record_set) - puts " - #{b.fetch(:action)}: #{rrset.fetch(:name)} #{rrset.fetch(:ttl)} #{rrset.fetch(:type)} #{rrset.dig(:resource_records, 0, :value)}" + rrset.fetch(:resource_records).each do |rr| + puts " - #{b.fetch(:action)}: #{rrset.fetch(:name)} #{rrset.fetch(:ttl)} #{rrset.fetch(:type)} #{rr.fetch(:value)}" + end end print " ... " @@ -98,14 +100,29 @@ def wait_for_sync(change_ids) end def change_batch_for_challenges(domain_and_challenges, comment: nil, action: 'UPSERT') - { - comment: "ACME challenge response #{comment}", - changes: domain_and_challenges.map do |d,c| + changes = domain_and_challenges + .map do |d, c| + rrset_for_challenge(d, c) + end + .group_by do |_| + # Reduce changes by name. ACME server may require multiple challenge responses for the same identifier + _.fetch(:name) + end + .map do |name, cs| + cs.inject { |result, change| + result.merge(resource_records: result.fetch(:resource_records, []) + change.fetch(:resource_records)) + } + end + .map do |change| { action: action, - resource_record_set: rrset_for_challenge(d,c), + resource_record_set: change, } - end, + end + + { + comment: "ACME challenge response #{comment}", + changes: changes, } end