smartcert/ts/cert.classes.cert.ts

99 lines
2.5 KiB
TypeScript
Raw Normal View History

2016-10-22 14:21:25 +00:00
import * as q from 'q'
2016-10-23 22:35:00 +00:00
import { Stringmap, Objectmap } from 'lik'
2016-10-22 14:21:25 +00:00
import * as plugins from './cert.plugins'
import * as paths from './cert.paths'
2016-10-23 22:35:00 +00:00
// classes
import { Certificate } from './cert.classes.certificate'
import { CertRepo } from './cert.classes.certrepo'
import { Letsencrypt, TLeEnv } from './cert.classes.letsencrypt'
import { ChallengeHandler } from './cert.classes.challengehandler'
export interface ICertConstructorOptions {
cfEmail: string,
cfKey: string,
2016-10-23 22:35:00 +00:00
sslDirPath?: string,
gitOriginRepo?: string,
2016-10-23 22:35:00 +00:00
leEnv?: TLeEnv
2016-10-22 14:21:25 +00:00
}
export class Cert {
2016-10-23 22:35:00 +00:00
domainStringRequestMap = new Stringmap()
certificateMap = new Objectmap<Certificate>()
letsencrypt: Letsencrypt
private _challengeHandler: ChallengeHandler
private _certRepo: CertRepo
/**
* Constructor for Cert object
*/
constructor(optionsArg: ICertConstructorOptions) {
2016-10-23 22:35:00 +00:00
// set up challengehandler
this._challengeHandler = new ChallengeHandler({
cfEmail: optionsArg.cfEmail,
cfKey: optionsArg.cfKey
})
2016-10-23 22:35:00 +00:00
// setup Letsencrypt
this.letsencrypt = new Letsencrypt({
leEnv: optionsArg.leEnv,
sslDir: optionsArg.sslDirPath,
challengeHandler: this._challengeHandler
})
2017-01-01 04:18:50 +00:00
this._certRepo = new CertRepo({
2016-10-23 22:35:00 +00:00
sslDirPath: optionsArg.sslDirPath,
2017-01-01 04:18:50 +00:00
remoteGitUrl: optionsArg.gitOriginRepo,
2016-10-23 22:35:00 +00:00
certInstance: this
2017-01-01 04:18:50 +00:00
})
}
/**
* setup the Cert instanceof
* @executes ASYNC
* @return Promise
*/
setup() {
return this._certRepo.setup()
2016-10-22 14:21:25 +00:00
}
/**
2016-10-23 22:35:00 +00:00
* adds a Certificate for a given domain
*/
2016-10-23 22:35:00 +00:00
addCertificate(domainNameArg: string, optionsArg: { force: boolean } = { force: false }) {
2016-10-22 14:21:25 +00:00
let done = q.defer()
2016-10-23 22:35:00 +00:00
let certificateForDomain = this.certificateMap.find((certificate) => {
return certificate.domainName === domainNameArg
})
if (certificateForDomain instanceof Certificate) {
certificateForDomain.renew()
.then(done.resolve)
} else {
2016-10-23 22:35:00 +00:00
certificateForDomain = new Certificate({
certInstance: this,
domainName: domainNameArg
})
certificateForDomain.renew()
.then(done.resolve)
2016-10-22 14:21:25 +00:00
}
return done.promise
}
2016-10-23 22:35:00 +00:00
/**
* cleans up old certificates
*/
cleanOldCertificates() {
2016-10-22 14:21:25 +00:00
}
2016-10-23 22:35:00 +00:00
/**
* executes the current batch of jobs
*/
deploy() {
2016-10-22 14:21:25 +00:00
}
}