2019-01-08 19:45:35 +00:00
|
|
|
import * as plugins from './smartacme.plugins';
|
2019-01-08 23:01:01 +00:00
|
|
|
|
|
|
|
import * as interfaces from './interfaces';
|
|
|
|
|
2019-01-08 19:45:35 +00:00
|
|
|
import { CertManager } from './smartacme.classes.certmanager';
|
|
|
|
|
|
|
|
import { Collection, svDb, unI } from '@pushrocks/smartdata';
|
|
|
|
|
|
|
|
@plugins.smartdata.Collection(() => {
|
|
|
|
return CertManager.activeDB;
|
|
|
|
})
|
2020-02-21 10:48:08 +00:00
|
|
|
export class Cert extends plugins.smartdata.SmartDataDbDoc<Cert, plugins.tsclass.network.ICert>
|
|
|
|
implements plugins.tsclass.network.ICert {
|
2019-01-08 19:45:35 +00:00
|
|
|
@unI()
|
2019-01-16 21:34:38 +00:00
|
|
|
public id: string;
|
2019-01-08 19:45:35 +00:00
|
|
|
|
|
|
|
@svDb()
|
2019-01-08 23:01:01 +00:00
|
|
|
public domainName: string;
|
2019-01-08 19:45:35 +00:00
|
|
|
|
|
|
|
@svDb()
|
2019-01-08 23:01:01 +00:00
|
|
|
public created: number;
|
2019-01-08 19:45:35 +00:00
|
|
|
|
|
|
|
@svDb()
|
2019-01-08 23:01:01 +00:00
|
|
|
public privateKey: string;
|
2019-02-06 08:47:33 +00:00
|
|
|
|
2019-01-08 19:45:35 +00:00
|
|
|
@svDb()
|
2019-01-08 23:01:01 +00:00
|
|
|
public publicKey: string;
|
2019-02-06 08:47:33 +00:00
|
|
|
|
2019-01-08 19:45:35 +00:00
|
|
|
@svDb()
|
2019-01-08 23:01:01 +00:00
|
|
|
public csr: string;
|
2019-01-08 19:45:35 +00:00
|
|
|
|
2020-02-10 20:13:06 +00:00
|
|
|
@svDb()
|
|
|
|
public validUntil: number;
|
|
|
|
|
|
|
|
public isStillValid(): boolean {
|
|
|
|
return this.validUntil >= Date.now();
|
2019-02-06 13:37:00 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 20:13:06 +00:00
|
|
|
public shouldBeRenewed(): boolean {
|
|
|
|
const shouldBeValidAtLeastUntil =
|
2020-02-10 11:15:47 +00:00
|
|
|
Date.now() +
|
|
|
|
plugins.smarttime.getMilliSecondsFromUnits({
|
2020-08-12 16:36:06 +00:00
|
|
|
days: 10,
|
2020-02-10 11:15:47 +00:00
|
|
|
});
|
2020-02-10 20:36:01 +00:00
|
|
|
return !(this.validUntil >= shouldBeValidAtLeastUntil);
|
2019-02-06 13:37:00 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 20:13:06 +00:00
|
|
|
public update(certDataArg: plugins.tsclass.network.ICert) {
|
2020-08-12 16:36:06 +00:00
|
|
|
Object.keys(certDataArg).forEach((key) => {
|
2020-02-10 20:13:06 +00:00
|
|
|
this[key] = certDataArg[key];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(optionsArg: plugins.tsclass.network.ICert) {
|
2019-01-08 19:45:35 +00:00
|
|
|
super();
|
2019-01-12 23:50:43 +00:00
|
|
|
if (optionsArg) {
|
2020-08-12 16:36:06 +00:00
|
|
|
Object.keys(optionsArg).forEach((key) => {
|
2019-01-12 23:50:43 +00:00
|
|
|
this[key] = optionsArg[key];
|
|
|
|
});
|
|
|
|
}
|
2019-01-08 19:45:35 +00:00
|
|
|
}
|
|
|
|
}
|