2016-10-23 22:35:00 +00:00
|
|
|
import * as q from 'q'
|
2017-01-01 04:18:50 +00:00
|
|
|
import { GitRepo } from 'smartgit'
|
2016-10-23 22:35:00 +00:00
|
|
|
|
|
|
|
import * as plugins from './cert.plugins'
|
|
|
|
import * as paths from './cert.paths'
|
|
|
|
|
|
|
|
import { Cert } from './cert.classes.cert'
|
|
|
|
import { Certificate } from './cert.classes.certificate'
|
|
|
|
|
|
|
|
export interface ICertRepoConstructorOptions {
|
|
|
|
sslDirPath: string
|
2017-01-01 04:18:50 +00:00
|
|
|
remoteGitUrl: string
|
2016-10-23 22:35:00 +00:00
|
|
|
certInstance: Cert
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CertRepo {
|
|
|
|
private _sslDirPath: string
|
2017-01-01 04:18:50 +00:00
|
|
|
private _remoteGitUrl: string
|
|
|
|
private gitRepo: GitRepo
|
2016-10-23 22:35:00 +00:00
|
|
|
private _certInstance: Cert
|
|
|
|
constructor(optionsArg: ICertRepoConstructorOptions) {
|
|
|
|
this._sslDirPath = optionsArg.sslDirPath
|
2017-01-01 04:18:50 +00:00
|
|
|
this._remoteGitUrl = optionsArg.remoteGitUrl
|
2016-10-23 22:35:00 +00:00
|
|
|
this._certInstance = optionsArg.certInstance
|
|
|
|
|
|
|
|
// setup sslDir
|
2017-01-01 04:18:50 +00:00
|
|
|
if (!this._sslDirPath) {
|
2016-10-23 22:35:00 +00:00
|
|
|
this._sslDirPath = paths.defaultSslDir
|
|
|
|
}
|
2017-01-01 04:18:50 +00:00
|
|
|
}
|
2016-10-23 22:35:00 +00:00
|
|
|
|
2017-01-01 04:18:50 +00:00
|
|
|
/**
|
|
|
|
* setup the Cert instance
|
|
|
|
*/
|
|
|
|
setup() {
|
2016-10-23 22:35:00 +00:00
|
|
|
// setup Git
|
2017-01-01 04:18:50 +00:00
|
|
|
let done = q.defer()
|
|
|
|
if (this._remoteGitUrl) {
|
|
|
|
plugins.smartfile.fs.ensureEmptyDirSync(paths.defaultSslDir)
|
|
|
|
plugins.smartgit.createRepoFromClone(this._remoteGitUrl, paths.defaultSslDir)
|
|
|
|
.then(gitRepoArg => {
|
|
|
|
this.gitRepo = gitRepoArg
|
|
|
|
done.resolve()
|
|
|
|
})
|
2016-10-23 22:35:00 +00:00
|
|
|
}
|
2017-01-01 04:18:50 +00:00
|
|
|
return done.promise
|
2016-10-23 22:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* syncs an objectmap of Certificates with repo
|
|
|
|
*/
|
|
|
|
syncFs() {
|
|
|
|
let done = q.defer()
|
|
|
|
done.resolve()
|
|
|
|
return done.promise
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pulls already requested certificates from git origin
|
|
|
|
*/
|
|
|
|
sslGitOriginPull = () => {
|
2017-01-01 04:18:50 +00:00
|
|
|
if (this.gitRepo) {
|
|
|
|
this.gitRepo.pull('origin', 'master')
|
2016-10-23 22:35:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pushes all new requested certificates to git origin
|
|
|
|
*/
|
|
|
|
sslGitOriginAddCommitPush = () => {
|
2017-01-01 04:18:50 +00:00
|
|
|
if (this._remoteGitUrl) {
|
|
|
|
this.gitRepo.addAll()
|
|
|
|
this.gitRepo.commit('added new SSL certificates and deleted obsolete ones.')
|
|
|
|
this.gitRepo.push('origin', 'master')
|
2016-10-23 22:35:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|