Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Wait for Route53 changes to propagate #34

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion src/acme/authorize/updateDNSChallenge.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const updateTXTRecord = require('../../aws/route53/updateTXTRecord')
const getHostedZoneId = require('../../aws/route53/getHostedZoneId')
const getChangeStatus = require('../../aws/route53/getChangeStatus')
const RSA = require('rsa-compat').RSA
const crypto = require('crypto')
const dns = require('dns')
Expand All @@ -17,6 +18,18 @@ const arrayContainsArray = (superset, subset) =>

const flatten = input => Array.prototype.concat.apply([], input)

const changePropCheck = (domain, id) => (tryCount) => {
console.log(`Attempt ${tryCount + 1} for DNS record to propagate for ${domain}`)
return getChangeStatus(id)
.then(status => {
++tryCount
return {
tryCount,
result: status === 'INSYNC'
}
})
}

const dnsPreCheck = (domain, expect) => (tryCount) => {
console.log(`Attempt ${tryCount + 1} to resolve TXT record for ${domain}`)
return resolveTxt(`_acme-challenge.${domain}`)
Expand Down Expand Up @@ -53,7 +66,8 @@ const updateDNSChallenge = (domain, dnsChallenges, acctKeyPair) => {
console.log(`Updating DNS TXT Record for ${domainName} to contain ${dnsChallengeTexts} in Route53 hosted zone ${id}`)
return updateTXTRecord(id, domainName, dnsChallengeTexts)
})
.then(updated => validateDNSChallenge(domainName, dnsChallengeTexts))
.then(updated => retry(0, changePropCheck(domainName, updated.ChangeInfo.Id)))
.then(() => validateDNSChallenge(domainName, dnsChallengeTexts))
.catch(e => {
console.error(`Couldn't write token digest to DNS record.`, e)
throw e
Expand Down
7 changes: 7 additions & 0 deletions src/aws/route53/getChangeStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const getRoute53 = require('../sdk/getRoute53')

const getChangeStatus = (id) =>
getRoute53().getChange({Id: id}).promise()
.then(data => data.Status)

module.exports = getChangeStatus