smartacme/ts/smartacme.classes.certmanager.ts

94 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2019-01-08 19:45:35 +00:00
import * as plugins from './smartacme.plugins';
import { Cert } from './smartacme.classes.cert';
2019-01-08 23:01:01 +00:00
import { SmartAcme } from './smartacme.classes.smartacme';
import * as interfaces from './interfaces';
2019-01-12 12:44:18 +00:00
import { ICert } from './interfaces';
2019-01-08 19:45:35 +00:00
export class CertManager {
// =========
// STATIC
// =========
public static activeDB: plugins.smartdata.SmartdataDb;
// =========
// INSTANCE
// =========
private mongoDescriptor: plugins.smartdata.IMongoDescriptor;
public smartdataDb: plugins.smartdata.SmartdataDb;
2019-01-08 23:01:01 +00:00
public pendingMap: plugins.lik.Stringmap;
constructor(smartAcmeArg: SmartAcme,optionsArg: {
2019-01-08 19:45:35 +00:00
mongoDescriptor: plugins.smartdata.IMongoDescriptor;
}) {
this.mongoDescriptor = optionsArg.mongoDescriptor;
}
public async init () {
2019-01-08 23:01:01 +00:00
// Smartdata DB
2019-01-08 19:45:35 +00:00
this.smartdataDb = new plugins.smartdata.SmartdataDb(this.mongoDescriptor);
await this.smartdataDb.init();
CertManager.activeDB = this.smartdataDb;
2019-01-08 23:01:01 +00:00
// Pending Map
this.pendingMap = new plugins.lik.Stringmap();
2019-01-08 19:45:35 +00:00
};
/**
* retrieves a certificate
* @returns the Cert class or null
* @param domainName the domain Name to retrieve the vcertificate for
*/
public async retrieveCertificate(domainName: string): Promise<Cert> {
2019-01-08 23:01:01 +00:00
await this.checkCerts();
2019-01-08 19:45:35 +00:00
const existingCertificate: Cert = await Cert.getInstance({
2019-01-12 23:06:00 +00:00
domainName
2019-01-08 19:45:35 +00:00
});
if(existingCertificate) {
return existingCertificate;
} else {
return null;
}
}
/**
* stores the certificate with the
* @param publicKeyArg
* @param privateKeyArg
* @param csrArg
*/
2019-01-12 12:44:18 +00:00
public async storeCertificate(optionsArg: ICert) {
const cert = new Cert(optionsArg);
2019-01-08 19:45:35 +00:00
cert.save();
};
2019-01-08 23:01:01 +00:00
public async deleteCertificate(domainNameArg: string) {
2019-01-08 19:45:35 +00:00
2019-01-08 23:01:01 +00:00
}
public async getCertificateStatus(domainNameArg: string): Promise<interfaces.TCertStatus> {
const isPending = this.pendingMap.checkString('domainNameArg');
if (isPending) {
return 'pending';
}
// otherwise lets continue
const existingCertificate = this.retrieveCertificate(domainNameArg);
if (existingCertificate) {
return 'existing';
}
return 'nonexisting';
}
2019-01-08 19:45:35 +00:00
/**
* checks all certs for expiration
*/
2019-01-08 23:01:01 +00:00
private async checkCerts() {};
2019-01-08 19:45:35 +00:00
}