27 lines
971 B
TypeScript
27 lines
971 B
TypeScript
import * as plugins from './smartacme.plugins.js';
|
|
import * as interfaces from './interfaces/index.js';
|
|
|
|
/**
|
|
* certmatcher is responsible for matching certificates
|
|
*/
|
|
export class SmartacmeCertMatcher {
|
|
/**
|
|
* creates a domainName for the certificate that will include the broadest scope
|
|
* for wild card certificates
|
|
* @param domainNameArg the domainNameArg to create the scope from
|
|
*/
|
|
public getCertificateDomainNameByDomainName(domainNameArg: string): string | undefined {
|
|
// Handle wildcard domains by stripping the '*.' prefix.
|
|
if (domainNameArg.startsWith('*.')) {
|
|
return domainNameArg.slice(2);
|
|
}
|
|
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
|
|
// For domains with up to 3 levels (no level4), return base domain.
|
|
if (!originalDomain.level4) {
|
|
return `${originalDomain.level2}.${originalDomain.level1}`;
|
|
}
|
|
// Deeper domains (4+ levels) are not supported.
|
|
return undefined;
|
|
}
|
|
}
|