BREAKING CHANGE(certs): accept a second eventComms argument in certProvisionFunction, add cert provisioning event types, and emit certificate lifecycle events
This commit is contained in:
@@ -14,7 +14,7 @@ import { generateDefaultCertificate } from './utils/default-cert-generator.js';
|
||||
import { Mutex } from './utils/mutex.js';
|
||||
|
||||
// Types
|
||||
import type { ISmartProxyOptions, TSmartProxyCertProvisionObject, IAcmeOptions } from './models/interfaces.js';
|
||||
import type { ISmartProxyOptions, TSmartProxyCertProvisionObject, IAcmeOptions, ICertProvisionEventComms, ICertificateIssuedEvent, ICertificateFailedEvent } from './models/interfaces.js';
|
||||
import type { IRouteConfig } from './models/route-types.js';
|
||||
import type { IMetrics } from './models/metrics-types.js';
|
||||
|
||||
@@ -420,8 +420,21 @@ export class SmartProxy extends plugins.EventEmitter {
|
||||
for (const domain of certDomains) {
|
||||
if (provisionedDomains.has(domain)) continue;
|
||||
provisionedDomains.add(domain);
|
||||
|
||||
// Build eventComms channel for this domain
|
||||
let expiryDate: string | undefined;
|
||||
let source = 'certProvisionFunction';
|
||||
|
||||
const eventComms: ICertProvisionEventComms = {
|
||||
log: (msg) => logger.log('info', `[certProvision ${domain}] ${msg}`, { component: 'smart-proxy' }),
|
||||
warn: (msg) => logger.log('warn', `[certProvision ${domain}] ${msg}`, { component: 'smart-proxy' }),
|
||||
error: (msg) => logger.log('error', `[certProvision ${domain}] ${msg}`, { component: 'smart-proxy' }),
|
||||
setExpiryDate: (date) => { expiryDate = date.toISOString(); },
|
||||
setSource: (s) => { source = s; },
|
||||
};
|
||||
|
||||
try {
|
||||
const result: TSmartProxyCertProvisionObject = await provisionFn(domain);
|
||||
const result: TSmartProxyCertProvisionObject = await provisionFn(domain, eventComms);
|
||||
|
||||
if (result === 'http01') {
|
||||
// Callback wants HTTP-01 for this domain — trigger Rust ACME explicitly
|
||||
@@ -455,10 +468,24 @@ export class SmartProxy extends plugins.EventEmitter {
|
||||
logger.log('warn', `certStore.save() failed for ${domain}: ${storeErr.message}`, { component: 'smart-proxy' });
|
||||
}
|
||||
}
|
||||
|
||||
// Emit certificate-issued event
|
||||
this.emit('certificate-issued', {
|
||||
domain,
|
||||
expiryDate: expiryDate || (certObj.validUntil ? new Date(certObj.validUntil).toISOString() : undefined),
|
||||
source,
|
||||
} satisfies ICertificateIssuedEvent);
|
||||
}
|
||||
} catch (err: any) {
|
||||
logger.log('warn', `certProvisionFunction failed for ${domain}: ${err.message}`, { component: 'smart-proxy' });
|
||||
|
||||
// Emit certificate-failed event
|
||||
this.emit('certificate-failed', {
|
||||
domain,
|
||||
error: err.message,
|
||||
source,
|
||||
} satisfies ICertificateFailedEvent);
|
||||
|
||||
// Fallback to ACME if enabled and route has a name
|
||||
if (this.settings.certProvisionFallbackToAcme !== false && route.name) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user