This commit is contained in:
2017-01-01 05:18:50 +01:00
parent 7455891097
commit fd89e54295
12 changed files with 203 additions and 98 deletions

View File

@ -44,12 +44,20 @@ export class Cert {
challengeHandler: this._challengeHandler
})
// setup CertRpo
/* this._certRepo = new CertRepo({
this._certRepo = new CertRepo({
sslDirPath: optionsArg.sslDirPath,
gitOriginRepo: optionsArg.gitOriginRepo,
remoteGitUrl: optionsArg.gitOriginRepo,
certInstance: this
}) */
})
}
/**
* setup the Cert instanceof
* @executes ASYNC
* @return Promise
*/
setup() {
return this._certRepo.setup()
}
/**

View File

@ -1,4 +1,5 @@
import * as q from 'q'
import { GitRepo } from 'smartgit'
import * as plugins from './cert.plugins'
import * as paths from './cert.paths'
@ -8,30 +9,41 @@ import { Certificate } from './cert.classes.certificate'
export interface ICertRepoConstructorOptions {
sslDirPath: string
gitOriginRepo: string
remoteGitUrl: string
certInstance: Cert
}
export class CertRepo {
private _sslDirPath: string
private _gitOriginRepo: string
private _remoteGitUrl: string
private gitRepo: GitRepo
private _certInstance: Cert
constructor(optionsArg: ICertRepoConstructorOptions) {
this._sslDirPath = optionsArg.sslDirPath
this._gitOriginRepo = optionsArg.gitOriginRepo
this._remoteGitUrl = optionsArg.remoteGitUrl
this._certInstance = optionsArg.certInstance
// setup sslDir
if (!this._sslDirPath){
if (!this._sslDirPath) {
this._sslDirPath = paths.defaultSslDir
}
}
/**
* setup the Cert instance
*/
setup() {
// setup Git
if (this._gitOriginRepo) {
plugins.smartgit.init(this._sslDirPath)
plugins.smartgit.remote.add(this._sslDirPath, 'origin', this._gitOriginRepo)
this.sslGitOriginPull()
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()
})
}
return done.promise
}
/**
@ -47,8 +59,8 @@ export class CertRepo {
* Pulls already requested certificates from git origin
*/
sslGitOriginPull = () => {
if (this._gitOriginRepo) {
plugins.smartgit.pull(this._sslDirPath, 'origin', 'master')
if (this.gitRepo) {
this.gitRepo.pull('origin', 'master')
}
}
@ -56,10 +68,10 @@ export class CertRepo {
* Pushes all new requested certificates to git origin
*/
sslGitOriginAddCommitPush = () => {
if (this._gitOriginRepo) {
plugins.smartgit.add.addAll(this._sslDirPath)
plugins.smartgit.commit(this._sslDirPath, 'added new SSL certificates and deleted obsolete ones.')
plugins.smartgit.push(this._sslDirPath, 'origin', 'master')
if (this._remoteGitUrl) {
this.gitRepo.addAll()
this.gitRepo.commit('added new SSL certificates and deleted obsolete ones.')
this.gitRepo.push('origin', 'master')
}
}
}

View File

@ -15,6 +15,21 @@ export interface ILetsencryptConstructorOptions {
sslDir: string
}
let leStoreConfig = {
configDir: paths.leConfigDir,
privkeyPath: ':configDir/:hostname/privkey.pem',
fullchainPath: ':configDir/:hostname/fullchain.pem',
certPath: ':configDir/:hostname/cert.pem',
chainPath: ':configDir/:hostname/chain.pem',
workDir: ':configDir/letsencrypt/var/lib',
logsDir: ':configDir/letsencrypt/var/log',
debug: true
}
let leStoreInstance = leStore.create(leStoreConfig)
export class Letsencrypt {
leEnv: TLeEnv
challengeHandler: ChallengeHandler // this is the format we use
@ -43,14 +58,14 @@ export class Letsencrypt {
'dns-01': this._leChallengeHandler()
},
challengeType: 'dns-01',
store: leStore.create({
configDir: paths.leConfigDir,
debug: true
}),
store: leStoreInstance,
agreeToTerms: (opts, agreeCb) => {
agreeCb(null, opts.tosUrl)
},
debug: true
debug: true,
log: function (debug) {
console.info(arguments)
}
})
console.log()
}
@ -61,25 +76,33 @@ export class Letsencrypt {
registerDomain(domainNameArg: string) {
plugins.beautylog.log(`trying to register domain ${domainNameArg}`)
let done = q.defer()
console.log('test')
console.log(this._leServerUrl)
this._leInstance.register({
domains: [domainNameArg],
email: 'office@lossless.com',
agreeTos: true,
rsaKeySize: 2048,
challengeType: 'dns-01'
}).then(
results => {
plugins.beautylog.success(`Got certificates for ${domainNameArg}`)
this._leCopyToDestination(domainNameArg).then(done.resolve)
},
(err) => {
console.error('[Error]: node-letsencrypt/examples/standalone')
console.error(err.stack)
done.resolve()
plugins.smartfile.fs.ensureDirSync(plugins.path.join(paths.leConfigDir, 'live', domainNameArg))
this._leInstance.check({ domains: [domainNameArg] }).then((cert) => {
console.log(cert)
let opts = {
domains: [domainNameArg],
email: 'domains@lossless.org',
agreeTos: true,
rsaKeySize: 2048, // 2048 or higher
challengeType: 'dns-01',
duplicate: true
}
).catch(err => { console.log(err) })
if (cert) {
if (true) {
return this._leInstance.renew(opts, cert).catch((err) => {
console.log(err)
})
} else {
return cert
}
} else {
// Register Certificate manually
return this._leInstance.register(opts).catch((err) => {
console.log(err)
})
}
})
return done.promise
}
@ -126,7 +149,7 @@ export class Letsencrypt {
cb()
})
},
loopback: (defaults, domain, challenge, done) => {
loopback: (defaults, domain, token, keyAuthorization, done) => {
done()
},
test: (defaults, domain, challenge, cb) => {