2019-01-08 20:45:35 +01:00
|
|
|
import * as plugins from './smartacme.plugins';
|
2019-01-09 00:01:01 +01:00
|
|
|
|
|
|
|
import * as interfaces from './interfaces';
|
|
|
|
|
2019-01-08 20:45:35 +01:00
|
|
|
import { CertManager } from './smartacme.classes.certmanager';
|
|
|
|
|
|
|
|
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
|
|
|
|
|
|
|
@plugins.smartdata.Collection(() => {
|
|
|
|
return CertManager.activeDB;
|
|
|
|
})
|
2019-01-09 00:01:01 +01:00
|
|
|
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert> implements interfaces.ICert {
|
2019-01-08 20:45:35 +01:00
|
|
|
@unI()
|
2019-01-16 22:34:38 +01:00
|
|
|
public id: string;
|
2019-01-08 20:45:35 +01:00
|
|
|
|
|
|
|
@svDb()
|
2019-01-09 00:01:01 +01:00
|
|
|
public domainName: string;
|
2019-01-08 20:45:35 +01:00
|
|
|
|
|
|
|
@svDb()
|
2019-01-09 00:01:01 +01:00
|
|
|
public created: number;
|
2019-01-08 20:45:35 +01:00
|
|
|
|
|
|
|
@svDb()
|
2019-01-09 00:01:01 +01:00
|
|
|
public privateKey: string;
|
2019-02-06 09:47:33 +01:00
|
|
|
|
2019-01-08 20:45:35 +01:00
|
|
|
@svDb()
|
2019-01-09 00:01:01 +01:00
|
|
|
public publicKey: string;
|
2019-02-06 09:47:33 +01:00
|
|
|
|
2019-01-08 20:45:35 +01:00
|
|
|
@svDb()
|
2019-01-09 00:01:01 +01:00
|
|
|
public csr: string;
|
2019-01-08 20:45:35 +01:00
|
|
|
|
2019-02-06 14:37:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2019-01-08 20:45:35 +01:00
|
|
|
super();
|
2019-01-13 00:50:43 +01:00
|
|
|
if (optionsArg) {
|
|
|
|
Object.keys(optionsArg).forEach(key => {
|
|
|
|
this[key] = optionsArg[key];
|
|
|
|
});
|
|
|
|
}
|
2019-01-08 20:45:35 +01:00
|
|
|
}
|
|
|
|
}
|