-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook-dns.js
71 lines (58 loc) · 1.78 KB
/
hook-dns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
// Require the base Hook class
const Hook = require('./hook');
/**
* HookDns class
* Dehydrated hook for 'dns-01' challenge type
*/
class HookDns extends Hook {
/**
* Deploy challenge as DNS record
*/
deployChallenge() {
this.debug('Deploying challenge...');
// Retrieve the challenge record set from Route53
this.getChallengeRecordSet(recordSet => {
// Upsert (update or insert) the record set
recordSet.upsert(() => {
this.log('Challenge deployed.');
});
});
}
/**
* Clean challenge from DNS
*/
cleanChallenge() {
this.debug('Cleaning challenge...');
// Retrieve the challenge record set from Route53
this.getChallengeRecordSet(recordSet => {
// Delete the record set
recordSet.delete(() => {
this.debug('Challenge cleaned.');
});
});
}
/**
* Get the challenge record set for this hook execution
*/
getChallengeRecordSet(callback) {
// Get the hosted zone for this domain
this.getHostedZone(this.domain, zone => {
// Create a new RecordSet object (can be used to create/update & delete)
const recordSet = zone.newRecordSet({
Name: `_acme-challenge.${this.domain}.`, // Subdomain expected by ACME CA
Type: 'TXT', // DNS challenge is a TXT record
TTL: 0, // Set TTL to 0
ResourceRecords: [ // Define the records (values) for this record set
{
Value: `"${this.challenge}"` // The value is simply the challenge string
}
]
});
// Return the callback with the created record set
return callback(recordSet);
});
}
}
// Export the HookDns class
module.exports = HookDns;