better state management
This commit is contained in:
parent
89ef517338
commit
f6a049d92a
|
@ -104,6 +104,11 @@ Acme.prototype.post=function(url, body, cb) {
|
||||||
|
|
||||||
|
|
||||||
function registerNewAccount(state, options, cb) {
|
function registerNewAccount(state, options, cb) {
|
||||||
|
var state = {};
|
||||||
|
|
||||||
|
if (!options.accountPrivateKeyPem) {
|
||||||
|
return handleErr(new Error("options.accountPrivateKeyPem must be an ascii private key pem"));
|
||||||
|
}
|
||||||
if (!options.agreeToTerms) {
|
if (!options.agreeToTerms) {
|
||||||
cb(new Error("options.agreeToTerms must be function (tosUrl, fn => (err, true))"));
|
cb(new Error("options.agreeToTerms must be function (tosUrl, fn => (err, true))"));
|
||||||
return;
|
return;
|
||||||
|
@ -117,6 +122,10 @@ function registerNewAccount(state, options, cb) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.accountKeyPem=options.accountPrivateKeyPem;
|
||||||
|
state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPEM);
|
||||||
|
state.acme=new Acme(state.accountKeyPair);
|
||||||
|
|
||||||
register();
|
register();
|
||||||
|
|
||||||
function register() {
|
function register() {
|
||||||
|
@ -216,7 +225,11 @@ function getCert(options, cb) {
|
||||||
if (!options.removeChallenge) {
|
if (!options.removeChallenge) {
|
||||||
return handleErr(new Error("options.removeChallenge must be function(hostname, challengeKey, done) {}"));
|
return handleErr(new Error("options.removeChallenge must be function(hostname, challengeKey, done) {}"));
|
||||||
}
|
}
|
||||||
|
if (!(options.domains && options.domains.length)) {
|
||||||
|
return handleErr(new Error("options.domains must be an array of domains such as ['example.com', 'www.example.com']"));
|
||||||
|
}
|
||||||
|
|
||||||
|
state.domains = options.domains.slice(0); // copy array
|
||||||
try {
|
try {
|
||||||
state.accountKeyPem=options.accountPrivateKeyPem;
|
state.accountKeyPem=options.accountPrivateKeyPem;
|
||||||
state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPEM);
|
state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPEM);
|
||||||
|
|
Loading…
Reference in New Issue