BREAKING CHANGE(SmartAcme): Refactor challenge handling by removing legacy setChallenge/removeChallenge in favor of pluggable challengeHandlers and update documentation and tests accordingly
This commit is contained in:
40
ts/handlers/Dns01Handler.ts
Normal file
40
ts/handlers/Dns01Handler.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as plugins from '../smartacme.plugins.js';
|
||||
import type { IChallengeHandler } from './IChallengeHandler.js';
|
||||
|
||||
/**
|
||||
* DNS-01 challenge handler using CloudflareAccount and Smartdns.
|
||||
*/
|
||||
export class Dns01Handler implements IChallengeHandler<plugins.tsclass.network.IDnsChallenge> {
|
||||
private cf: any;
|
||||
private smartdns: plugins.smartdnsClient.Smartdns;
|
||||
|
||||
constructor(
|
||||
cloudflareAccount: any,
|
||||
smartdnsInstance?: plugins.smartdnsClient.Smartdns,
|
||||
) {
|
||||
this.cf = cloudflareAccount;
|
||||
this.smartdns = smartdnsInstance ?? new plugins.smartdnsClient.Smartdns({});
|
||||
}
|
||||
|
||||
public getSupportedTypes(): string[] {
|
||||
return ['dns-01'];
|
||||
}
|
||||
|
||||
public async prepare(ch: plugins.tsclass.network.IDnsChallenge): Promise<void> {
|
||||
// set DNS TXT record
|
||||
await this.cf.convenience.acmeSetDnsChallenge(ch);
|
||||
// wait for DNS propagation
|
||||
await this.smartdns.checkUntilAvailable(
|
||||
ch.hostName,
|
||||
'TXT',
|
||||
ch.challenge,
|
||||
100,
|
||||
5000,
|
||||
);
|
||||
}
|
||||
|
||||
public async cleanup(ch: plugins.tsclass.network.IDnsChallenge): Promise<void> {
|
||||
// remove DNS TXT record
|
||||
await this.cf.convenience.acmeRemoveDnsChallenge(ch);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user