BREAKING CHANGE(SmartAcme (Cert Management)): Refactor certificate management and challenge handling API to use a unified certManager interface, remove legacy storage, and update challenge workflows.
This commit is contained in:
@ -1,64 +1,39 @@
|
||||
import * as plugins from './smartacme.plugins.js';
|
||||
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
import { SmartacmeCertManager } from './smartacme.classes.certmanager.js';
|
||||
|
||||
import { Collection, svDb, unI } from '@push.rocks/smartdata';
|
||||
|
||||
@plugins.smartdata.Collection(() => {
|
||||
return SmartacmeCertManager.activeDB;
|
||||
})
|
||||
export class SmartacmeCert
|
||||
extends plugins.smartdata.SmartDataDbDoc<SmartacmeCert, plugins.tsclass.network.ICert>
|
||||
implements plugins.tsclass.network.ICert
|
||||
{
|
||||
@unI()
|
||||
/**
|
||||
* Plain certificate record.
|
||||
*/
|
||||
export class SmartacmeCert {
|
||||
public id: string;
|
||||
|
||||
@svDb()
|
||||
public domainName: string;
|
||||
|
||||
@svDb()
|
||||
public created: number;
|
||||
|
||||
@svDb()
|
||||
public privateKey: string;
|
||||
|
||||
@svDb()
|
||||
public publicKey: string;
|
||||
|
||||
@svDb()
|
||||
public csr: string;
|
||||
|
||||
@svDb()
|
||||
public validUntil: number;
|
||||
|
||||
constructor(data: Partial<SmartacmeCert> = {}) {
|
||||
this.id = data.id || '';
|
||||
this.domainName = data.domainName || '';
|
||||
this.created = data.created || Date.now();
|
||||
this.privateKey = data.privateKey || '';
|
||||
this.publicKey = data.publicKey || '';
|
||||
this.csr = data.csr || '';
|
||||
this.validUntil = data.validUntil || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if certificate is still valid.
|
||||
*/
|
||||
public isStillValid(): boolean {
|
||||
return this.validUntil >= Date.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if certificate needs renewal (e.g., expires in <10 days).
|
||||
*/
|
||||
public shouldBeRenewed(): boolean {
|
||||
const shouldBeValidAtLeastUntil =
|
||||
Date.now() +
|
||||
plugins.smarttime.getMilliSecondsFromUnits({
|
||||
days: 10,
|
||||
});
|
||||
return !(this.validUntil >= shouldBeValidAtLeastUntil);
|
||||
}
|
||||
|
||||
public update(certDataArg: plugins.tsclass.network.ICert) {
|
||||
Object.keys(certDataArg).forEach((key) => {
|
||||
this[key] = certDataArg[key];
|
||||
});
|
||||
}
|
||||
|
||||
constructor(optionsArg: plugins.tsclass.network.ICert) {
|
||||
super();
|
||||
if (optionsArg) {
|
||||
Object.keys(optionsArg).forEach((key) => {
|
||||
this[key] = optionsArg[key];
|
||||
});
|
||||
}
|
||||
const threshold = Date.now() + plugins.smarttime.getMilliSecondsFromUnits({ days: 10 });
|
||||
return this.validUntil < threshold;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user