50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import * as plugins from '../plugins.js';
|
|
import { Cloudly } from '../classes.cloudly.js';
|
|
|
|
export class LetsencryptConnector {
|
|
private cloudlyRef: Cloudly;
|
|
private smartacme: plugins.smartacme.SmartAcme;
|
|
|
|
constructor(cloudlyArg: Cloudly) {
|
|
this.cloudlyRef = cloudlyArg;
|
|
}
|
|
|
|
public async getCertificateForDomain(domainName: string) {
|
|
const cert = await this.smartacme.getCertificateForDomain(domainName);
|
|
return cert;
|
|
}
|
|
|
|
/**
|
|
* inits letsencrypt
|
|
*/
|
|
public async init() {
|
|
this.smartacme = new plugins.smartacme.SmartAcme({
|
|
accountEmail: this.cloudlyRef.config.data.letsEncryptEmail,
|
|
accountPrivateKey: this.cloudlyRef.config.data.letsEncryptPrivateKey,
|
|
environment: this.cloudlyRef.config.data.environment,
|
|
setChallenge: async (dnsChallenge) => {
|
|
await this.cloudlyRef.cloudflareConnector.cloudflare.convenience.acmeSetDnsChallenge(
|
|
dnsChallenge,
|
|
);
|
|
},
|
|
removeChallenge: async (dnsChallenge) => {
|
|
await this.cloudlyRef.cloudflareConnector.cloudflare.convenience.acmeRemoveDnsChallenge(
|
|
dnsChallenge,
|
|
);
|
|
},
|
|
mongoDescriptor: this.cloudlyRef.config.data.mongoDescriptor,
|
|
});
|
|
await this.smartacme.start().catch((err) => {
|
|
console.error('error in init', err);
|
|
console.log(`trying again in a few minutes`);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* stops the instance
|
|
*/
|
|
public async stop() {
|
|
await this.smartacme.stop();
|
|
}
|
|
}
|