feat(Cert): now has validity check

This commit is contained in:
Philipp Kunz 2019-02-06 14:37:00 +01:00
parent 86929251ba
commit 81a15da2d0
2 changed files with 29 additions and 2 deletions

View File

@ -5,7 +5,6 @@ import * as interfaces from './interfaces';
import { CertManager } from './smartacme.classes.certmanager'; import { CertManager } from './smartacme.classes.certmanager';
import { Collection, svDb, unI } from '@pushrocks/smartdata'; import { Collection, svDb, unI } from '@pushrocks/smartdata';
import { ICert } from './interfaces';
@plugins.smartdata.Collection(() => { @plugins.smartdata.Collection(() => {
return CertManager.activeDB; return CertManager.activeDB;
@ -29,7 +28,26 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements inte
@svDb() @svDb()
public csr: string; public csr: string;
constructor(optionsArg: ICert) {
/**
* computed value for when the certificate is still valid
*/
get validUntil (): number {
return this.created + plugins.smarttime.getMilliSecondsFromUnits({
days: 90
});
}
get isStillValid (): boolean {
const shouldBeValitAtLeastUntil = Date.now() + plugins.smarttime.getMilliSecondsFromUnits({
days: 10
});
return this.validUntil >= shouldBeValitAtLeastUntil;
}
constructor(optionsArg: interfaces.ICert) {
super(); super();
if (optionsArg) { if (optionsArg) {
Object.keys(optionsArg).forEach(key => { Object.keys(optionsArg).forEach(key => {

View File

@ -1,6 +1,15 @@
import * as plugins from './smartacme.plugins'; import * as plugins from './smartacme.plugins';
import * as interfaces from './interfaces';
/**
* certmatcher is responsible for matching certificates
*/
export class CertMatcher { export class CertMatcher {
/**
* 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 { public getCertificateDomainNameByDomainName(domainNameArg: string): string {
const originalDomain = new plugins.smartstring.Domain(domainNameArg); const originalDomain = new plugins.smartstring.Domain(domainNameArg);
if (!originalDomain.level4) { if (!originalDomain.level4) {