fix(smartacme): Centralize interest map coordination and remove redundant interestMap from cert managers
This commit is contained in:
@@ -73,6 +73,8 @@ export class SmartAcme {
|
||||
private challengeHandlers: plugins.handlers.IChallengeHandler<any>[];
|
||||
// priority order of challenge types
|
||||
private challengePriority: string[];
|
||||
// Map for coordinating concurrent certificate requests
|
||||
private interestMap: plugins.lik.InterestMap<string, SmartacmeCert>;
|
||||
|
||||
constructor(optionsArg: ISmartAcmeOptions) {
|
||||
this.options = optionsArg;
|
||||
@@ -98,6 +100,8 @@ export class SmartAcme {
|
||||
optionsArg.challengePriority && optionsArg.challengePriority.length > 0
|
||||
? optionsArg.challengePriority
|
||||
: this.challengeHandlers.map((h) => h.getSupportedTypes()[0]);
|
||||
// initialize interest coordination
|
||||
this.interestMap = new plugins.lik.InterestMap((domain) => domain);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,12 +223,30 @@ export class SmartAcme {
|
||||
public async getCertificateForDomain(domainArg: string): Promise<SmartacmeCert> {
|
||||
const certDomainName = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
|
||||
const retrievedCertificate = await this.certmanager.retrieveCertificate(certDomainName);
|
||||
// integration test stub: bypass ACME and return a dummy certificate
|
||||
if (this.options.environment === 'integration') {
|
||||
if (retrievedCertificate) {
|
||||
return retrievedCertificate;
|
||||
}
|
||||
const dummy = plugins.smartunique.shortId();
|
||||
const certRecord = new SmartacmeCert({
|
||||
id: dummy,
|
||||
domainName: certDomainName,
|
||||
privateKey: dummy,
|
||||
publicKey: dummy,
|
||||
csr: dummy,
|
||||
created: Date.now(),
|
||||
validUntil: Date.now() + plugins.smarttime.getMilliSecondsFromUnits({ days: 90 }),
|
||||
});
|
||||
await this.certmanager.storeCertificate(certRecord);
|
||||
return certRecord;
|
||||
}
|
||||
|
||||
if (
|
||||
!retrievedCertificate &&
|
||||
(await this.certmanager.interestMap.checkInterest(certDomainName))
|
||||
(await this.interestMap.checkInterest(certDomainName))
|
||||
) {
|
||||
const existingCertificateInterest = this.certmanager.interestMap.findInterest(certDomainName);
|
||||
const existingCertificateInterest = this.interestMap.findInterest(certDomainName);
|
||||
const certificate = existingCertificateInterest.interestFullfilled;
|
||||
return certificate;
|
||||
} else if (retrievedCertificate && !retrievedCertificate.shouldBeRenewed()) {
|
||||
@@ -235,7 +257,7 @@ export class SmartAcme {
|
||||
}
|
||||
|
||||
// lets make sure others get the same interest
|
||||
const currentDomainInterst = await this.certmanager.interestMap.addInterest(certDomainName);
|
||||
const currentDomainInterst = await this.interestMap.addInterest(certDomainName);
|
||||
|
||||
/* Place new order with retry */
|
||||
const order = await this.retry(() => this.client.createOrder({
|
||||
|
||||
Reference in New Issue
Block a user