Files
cloudly/ts/connector.letsencrypt/connector.ts

51 lines
1.4 KiB
TypeScript
Raw Normal View History

import * as plugins from '../plugins.js';
import { Cloudly } from '../classes.cloudly.js';
2024-04-20 12:21:41 +02:00
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() {
// Create DNS-01 challenge handler using Cloudflare
const dnsHandler = new plugins.smartacme.handlers.Dns01Handler(
this.cloudlyRef.cloudflareConnector.cloudflare
);
// Create MongoDB certificate manager
const certManager = new plugins.smartacme.certmanagers.MongoCertManager(
this.cloudlyRef.config.data.mongoDescriptor
);
2024-04-20 12:21:41 +02:00
this.smartacme = new plugins.smartacme.SmartAcme({
accountEmail: this.cloudlyRef.config.data.letsEncryptEmail,
accountPrivateKey: this.cloudlyRef.config.data.letsEncryptPrivateKey,
environment: this.cloudlyRef.config.data.environment,
certManager: certManager,
challengeHandlers: [dnsHandler],
2024-04-20 12:21:41 +02:00
});
await this.smartacme.start().catch((err) => {
console.error('error in init', err);
console.log(`trying again in a few minutes`);
});
2024-04-20 12:21:41 +02:00
}
/**
* stops the instance
*/
public async stop() {
await this.smartacme.stop();
}
}