smartacme/dist/smartacme.classes.smartacme.js

67 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-11-01 17:27:57 +00:00
"use strict";
2017-04-28 16:56:55 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2017-01-14 13:14:50 +00:00
// third party modules
2017-04-28 16:56:55 +00:00
const q = require("smartq"); // promises
2017-01-14 17:36:33 +00:00
const plugins = require("./smartacme.plugins");
const helpers = require("./smartacme.helpers");
const smartacme_classes_acmeaccount_1 = require("./smartacme.classes.acmeaccount");
var smartacme_classes_acmeaccount_2 = require("./smartacme.classes.acmeaccount");
exports.AcmeAccount = smartacme_classes_acmeaccount_2.AcmeAccount;
var smartacme_classes_acmecert_1 = require("./smartacme.classes.acmecert");
exports.AcmeCert = smartacme_classes_acmecert_1.AcmeCert;
2016-11-11 13:17:50 +00:00
/**
* class SmartAcme exports methods for maintaining SSL Certificates
*/
2016-11-01 17:27:57 +00:00
class SmartAcme {
2016-11-07 17:41:52 +00:00
/**
* the constructor for class SmartAcme
2016-11-11 13:17:50 +00:00
*/
constructor(productionArg = false) {
this.productionBool = productionArg;
2017-01-14 17:36:33 +00:00
this.keyPair = helpers.createKeypair();
if (this.productionBool) {
2017-01-14 17:36:33 +00:00
this.acmeUrl = plugins.rawacme.LETSENCRYPT_URL;
2016-11-11 13:17:50 +00:00
}
else {
2017-01-14 17:36:33 +00:00
this.acmeUrl = plugins.rawacme.LETSENCRYPT_STAGING_URL;
2016-11-11 13:17:50 +00:00
}
}
/**
2017-01-14 17:36:33 +00:00
* init the smartacme instance
2016-11-07 17:41:52 +00:00
*/
2017-01-14 17:36:33 +00:00
init() {
2016-11-11 13:17:50 +00:00
let done = q.defer();
2017-01-14 17:36:33 +00:00
plugins.rawacme.createClient({
url: this.acmeUrl,
publicKey: this.keyPair.publicKey,
privateKey: this.keyPair.privateKey
}, (err, client) => {
if (err) {
console.error('smartacme: something went wrong:');
console.log(err);
done.reject(err);
return;
}
2017-01-01 20:20:12 +00:00
// make client available in class
this.rawacmeClient = client;
done.resolve();
});
return done.promise;
}
/**
2017-01-14 17:36:33 +00:00
* creates an account if not currently present in module
* @executes ASYNC
2017-01-01 23:18:51 +00:00
*/
2017-01-15 22:11:51 +00:00
createAcmeAccount() {
2017-01-01 23:18:51 +00:00
let done = q.defer();
2017-01-14 17:36:33 +00:00
let acmeAccount = new smartacme_classes_acmeaccount_1.AcmeAccount(this);
acmeAccount.register().then(() => {
return acmeAccount.agreeTos();
}).then(() => {
done.resolve(acmeAccount);
2017-01-01 20:20:12 +00:00
});
return done.promise;
}
2016-11-01 17:27:57 +00:00
}
exports.SmartAcme = SmartAcme;
2017-04-28 16:56:55 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsc0JBQXNCO0FBQ3RCLDRCQUEyQixDQUFDLFdBQVc7QUFDdkMsK0NBQThDO0FBQzlDLCtDQUE4QztBQUU5QyxtRkFBNkQ7QUFVN0QsaUZBQTZEO0FBQXBELHNEQUFBLFdBQVcsQ0FBQTtBQUNwQiwyRUFBdUc7QUFBOUYsZ0RBQUEsUUFBUSxDQUFBO0FBRWpCOztHQUVHO0FBQ0g7SUFNRTs7T0FFRztJQUNILFlBQVksZ0JBQXlCLEtBQUs7UUFDeEMsSUFBSSxDQUFDLGNBQWMsR0FBRyxhQUFhLENBQUE7UUFDbkMsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUMsYUFBYSxFQUFFLENBQUE7UUFDdEMsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLGNBQWMsQ0FBQyxDQUFDLENBQUM7WUFDeEIsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUMs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