From 81a15da2d0660a45468685e0266406ff97c2e15a Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 6 Feb 2019 14:37:00 +0100 Subject: [PATCH] feat(Cert): now has validity check --- ts/smartacme.classes.cert.ts | 22 ++++++++++++++++++++-- ts/smartacme.classes.certmatcher.ts | 9 +++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ts/smartacme.classes.cert.ts b/ts/smartacme.classes.cert.ts index 2662813..e285ea8 100644 --- a/ts/smartacme.classes.cert.ts +++ b/ts/smartacme.classes.cert.ts @@ -5,7 +5,6 @@ import * as interfaces from './interfaces'; import { CertManager } from './smartacme.classes.certmanager'; import { Collection, svDb, unI } from '@pushrocks/smartdata'; -import { ICert } from './interfaces'; @plugins.smartdata.Collection(() => { return CertManager.activeDB; @@ -29,7 +28,26 @@ export class Cert extends plugins.smartdata.SmartDataDbDoc implements inte @svDb() 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(); if (optionsArg) { Object.keys(optionsArg).forEach(key => { diff --git a/ts/smartacme.classes.certmatcher.ts b/ts/smartacme.classes.certmatcher.ts index d1e3d0a..fb260cd 100644 --- a/ts/smartacme.classes.certmatcher.ts +++ b/ts/smartacme.classes.certmatcher.ts @@ -1,6 +1,15 @@ import * as plugins from './smartacme.plugins'; +import * as interfaces from './interfaces'; +/** + * certmatcher is responsible for matching certificates + */ 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 { const originalDomain = new plugins.smartstring.Domain(domainNameArg); if (!originalDomain.level4) {