minor cleanup

This commit is contained in:
AJ ONeal 2016-08-09 15:53:44 -04:00
parent 03c2be409a
commit 61235c798c
1 changed files with 63 additions and 72 deletions

View File

@ -117,7 +117,7 @@ var defaults = {
, chainPath: [ ':configDir', 'live', ':hostname', 'chain.pem' ].join(path.sep) , chainPath: [ ':configDir', 'live', ':hostname', 'chain.pem' ].join(path.sep)
, rsaKeySize: 2048 , rsaKeySize: 2048
, webrootPath: [ '~', 'letsencrypt', 'srv', 'www', ':hostname', '.well-known', 'acme-challenge' ].join(path.sep) , webrootPath: [ ':workDir', 'acme-challenge' ].join(path.sep)
}; };
module.exports.create = function (configs) { module.exports.create = function (configs) {
@ -129,6 +129,9 @@ module.exports.create = function (configs) {
return configs; return configs;
} }
if (!configs.domainKeyPath) {
configs.domainKeyPath = configs.privkeyPath || defaults.privkeyPath;
}
Object.keys(defaults).forEach(function (key) { Object.keys(defaults).forEach(function (key) {
if (!(key in configs)) { if (!(key in configs)) {
configs[key] = defaults[key]; configs[key] = defaults[key];
@ -148,6 +151,12 @@ module.exports.create = function (configs) {
else { else {
return { privateKeyPem: key }; return { privateKeyPem: key };
} }
}, function (err) {
if ('ENOENT' !== err.code) {
throw err;
}
return null;
}); });
} }
, setAsync: function (keypath, keypair, format) { , setAsync: function (keypath, keypair, format) {
@ -178,11 +187,11 @@ module.exports.create = function (configs) {
return PromiseA.reject(new Error("missing options.domainKeyPath")); return PromiseA.reject(new Error("missing options.domainKeyPath"));
} }
return store.keypairs.checkAsync(args.domainKeyPath); return store.keypairs.checkAsync(args.domainKeyPath, 'pem');
} }
// Certificates // Certificates
, setKeypairAsync: function (args, keypair) { , setKeypairAsync: function (args, keypair) {
return store.keypairs.setAsync(args.domainKeyPath, keypair); return store.keypairs.setAsync(args.domainKeyPath, keypair, 'pem');
} }
// Certificates // Certificates
, checkAsync: function (args) { , checkAsync: function (args) {
@ -220,8 +229,7 @@ module.exports.create = function (configs) {
} }
// Certificates // Certificates
, setAsync: function (args) { , setAsync: function (args) {
// TODO get config return store.configs.getAsync(args).then(function (pyobj) {
var pyobj = args.pyobj;
var pems = args.pems; var pems = args.pems;
pyobj.checkpoints = parseInt(pyobj.checkpoints, 10) || 0; pyobj.checkpoints = parseInt(pyobj.checkpoints, 10) || 0;
@ -232,7 +240,7 @@ module.exports.create = function (configs) {
var fullchainPath = args.fullchainPath || pyobj.fullchain || path.join(liveDir, 'fullchain.pem'); var fullchainPath = args.fullchainPath || pyobj.fullchain || path.join(liveDir, 'fullchain.pem');
var chainPath = args.chainPath || pyobj.chain || path.join(liveDir, 'chain.pem'); var chainPath = args.chainPath || pyobj.chain || path.join(liveDir, 'chain.pem');
var privkeyPath = args.privkeyPath || pyobj.privkey var privkeyPath = args.privkeyPath || pyobj.privkey
//|| args.domainPrivateKeyPath || args.domainKeyPath || pyobj.keyPath || args.domainKeyPath
|| path.join(liveDir, 'privkey.pem'); || path.join(liveDir, 'privkey.pem');
var archiveDir = args.archiveDir || path.join(args.configDir, 'archive', args.domains[0]); var archiveDir = args.archiveDir || path.join(args.configDir, 'archive', args.domains[0]);
@ -248,11 +256,7 @@ module.exports.create = function (configs) {
sfs.writeFileAsync(certArchive, pems.cert, 'ascii') sfs.writeFileAsync(certArchive, pems.cert, 'ascii')
, sfs.writeFileAsync(chainArchive, pems.chain, 'ascii') , sfs.writeFileAsync(chainArchive, pems.chain, 'ascii')
, sfs.writeFileAsync(fullchainArchive, pems.cert + pems.chain, 'ascii') , sfs.writeFileAsync(fullchainArchive, pems.cert + pems.chain, 'ascii')
, sfs.writeFileAsync( , sfs.writeFileAsync(privkeyArchive, pems.privkey, 'ascii')
privkeyArchive
, pems.privkey
, 'ascii'
)
]); ]);
}).then(function () { }).then(function () {
return mkdirpAsync(liveDir); return mkdirpAsync(liveDir);
@ -261,17 +265,14 @@ module.exports.create = function (configs) {
sfs.writeFileAsync(certPath, pems.cert, 'ascii') sfs.writeFileAsync(certPath, pems.cert, 'ascii')
, sfs.writeFileAsync(chainPath, pems.chain, 'ascii') , sfs.writeFileAsync(chainPath, pems.chain, 'ascii')
, sfs.writeFileAsync(fullchainPath, pems.cert + pems.chain, 'ascii') , sfs.writeFileAsync(fullchainPath, pems.cert + pems.chain, 'ascii')
, sfs.writeFileAsync( , sfs.writeFileAsync(privkeyPath, pems.privkey, 'ascii')
privkeyPath
// TODO nix args.key, args.domainPrivateKeyPem ??
, pems.privkey
, 'ascii'
)
]); ]);
}).then(function () { }).then(function () {
pyobj.checkpoints += 1; pyobj.checkpoints += 1;
args.checkpoints += 1; args.checkpoints += 1;
// TODO other than for compatibility this is optional, right?
// or is it actually needful for renewal? (i.e. list of domains)
return writeRenewalConfig(args); return writeRenewalConfig(args);
}).then(function () { }).then(function () {
return { return {
@ -286,6 +287,7 @@ module.exports.create = function (configs) {
*/ */
}; };
}); });
});
} }
} }
@ -466,17 +468,6 @@ module.exports.create = function (configs) {
}); });
} }
// Accounts // Accounts
, getAsync: function (args) {
return store.accounts.checkAsync(args).then(function (account) {
if (!args.account) {
return store.accounts.registerAsync(args);
}
//args.account = account;
return account;
});
}
// Accounts
, setAsync: function (args, reg) { , setAsync: function (args, reg) {
var os = require("os"); var os = require("os");
var accountId = store.accounts._getAccountIdByPublicKey(reg.keypair); var accountId = store.accounts._getAccountIdByPublicKey(reg.keypair);
@ -598,7 +589,7 @@ module.exports.create = function (configs) {
//, logsDir: args.logsDir //, logsDir: args.logsDir
args.rsaKeySize = args.rsaKeySize || pyobj.rsaKeySize; args.rsaKeySize = args.rsaKeySize || pyobj.rsaKeySize;
args.http01Port = args.http01Port || pyobj.http01Port; args.http01Port = args.http01Port || pyobj.http01Port;
args.domainKeyPath = args.domainPrivateKeyPath || args.domainKeyPath || args.keyPath || pyobj.keyPath; args.domainKeyPath = args.domainKeyPath || args.keyPath || pyobj.keyPath;
return writeRenewalConfig(args); return writeRenewalConfig(args);
}); });