minor cleanup
This commit is contained in:
parent
03c2be409a
commit
61235c798c
49
index.js
49
index.js
|
@ -117,7 +117,7 @@ var defaults = {
|
|||
, chainPath: [ ':configDir', 'live', ':hostname', 'chain.pem' ].join(path.sep)
|
||||
|
||||
, 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) {
|
||||
|
@ -129,6 +129,9 @@ module.exports.create = function (configs) {
|
|||
return configs;
|
||||
}
|
||||
|
||||
if (!configs.domainKeyPath) {
|
||||
configs.domainKeyPath = configs.privkeyPath || defaults.privkeyPath;
|
||||
}
|
||||
Object.keys(defaults).forEach(function (key) {
|
||||
if (!(key in configs)) {
|
||||
configs[key] = defaults[key];
|
||||
|
@ -148,6 +151,12 @@ module.exports.create = function (configs) {
|
|||
else {
|
||||
return { privateKeyPem: key };
|
||||
}
|
||||
}, function (err) {
|
||||
if ('ENOENT' !== err.code) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
, setAsync: function (keypath, keypair, format) {
|
||||
|
@ -178,11 +187,11 @@ module.exports.create = function (configs) {
|
|||
return PromiseA.reject(new Error("missing options.domainKeyPath"));
|
||||
}
|
||||
|
||||
return store.keypairs.checkAsync(args.domainKeyPath);
|
||||
return store.keypairs.checkAsync(args.domainKeyPath, 'pem');
|
||||
}
|
||||
// Certificates
|
||||
, setKeypairAsync: function (args, keypair) {
|
||||
return store.keypairs.setAsync(args.domainKeyPath, keypair);
|
||||
return store.keypairs.setAsync(args.domainKeyPath, keypair, 'pem');
|
||||
}
|
||||
// Certificates
|
||||
, checkAsync: function (args) {
|
||||
|
@ -220,8 +229,7 @@ module.exports.create = function (configs) {
|
|||
}
|
||||
// Certificates
|
||||
, setAsync: function (args) {
|
||||
// TODO get config
|
||||
var pyobj = args.pyobj;
|
||||
return store.configs.getAsync(args).then(function (pyobj) {
|
||||
var pems = args.pems;
|
||||
|
||||
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 chainPath = args.chainPath || pyobj.chain || path.join(liveDir, 'chain.pem');
|
||||
var privkeyPath = args.privkeyPath || pyobj.privkey
|
||||
//|| args.domainPrivateKeyPath || args.domainKeyPath || pyobj.keyPath
|
||||
|| args.domainKeyPath
|
||||
|| path.join(liveDir, 'privkey.pem');
|
||||
|
||||
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(chainArchive, pems.chain, 'ascii')
|
||||
, sfs.writeFileAsync(fullchainArchive, pems.cert + pems.chain, 'ascii')
|
||||
, sfs.writeFileAsync(
|
||||
privkeyArchive
|
||||
, pems.privkey
|
||||
, 'ascii'
|
||||
)
|
||||
, sfs.writeFileAsync(privkeyArchive, pems.privkey, 'ascii')
|
||||
]);
|
||||
}).then(function () {
|
||||
return mkdirpAsync(liveDir);
|
||||
|
@ -261,17 +265,14 @@ module.exports.create = function (configs) {
|
|||
sfs.writeFileAsync(certPath, pems.cert, 'ascii')
|
||||
, sfs.writeFileAsync(chainPath, pems.chain, 'ascii')
|
||||
, sfs.writeFileAsync(fullchainPath, pems.cert + pems.chain, 'ascii')
|
||||
, sfs.writeFileAsync(
|
||||
privkeyPath
|
||||
// TODO nix args.key, args.domainPrivateKeyPem ??
|
||||
, pems.privkey
|
||||
, 'ascii'
|
||||
)
|
||||
, sfs.writeFileAsync(privkeyPath, pems.privkey, 'ascii')
|
||||
]);
|
||||
}).then(function () {
|
||||
pyobj.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);
|
||||
}).then(function () {
|
||||
return {
|
||||
|
@ -286,6 +287,7 @@ module.exports.create = function (configs) {
|
|||
*/
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -466,17 +468,6 @@ module.exports.create = function (configs) {
|
|||
});
|
||||
}
|
||||
// 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) {
|
||||
var os = require("os");
|
||||
var accountId = store.accounts._getAccountIdByPublicKey(reg.keypair);
|
||||
|
@ -598,7 +589,7 @@ module.exports.create = function (configs) {
|
|||
//, logsDir: args.logsDir
|
||||
args.rsaKeySize = args.rsaKeySize || pyobj.rsaKeySize;
|
||||
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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue