smartcert/dist/cert.hook.js

68 lines
8.6 KiB
JavaScript
Raw Normal View History

2016-06-22 11:22:09 +00:00
#!/usr/bin/env node
2016-06-18 13:42:49 +00:00
"use strict";
2016-06-22 11:22:09 +00:00
require("typings-global");
var plugins = require("./cert.plugins");
var paths = require("./cert.paths");
var smartcli = new plugins.smartcli.Smartcli();
2016-06-28 03:53:49 +00:00
var config = plugins.smartfile.fs.toObjectSync(paths.config);
2016-06-22 11:22:09 +00:00
var cflare = new plugins.cflare.CflareAccount();
cflare.auth({
email: config.cfEmail,
key: config.cfKey
});
var setChallenge = function (domainNameArg, challengeArg) {
var done = plugins.q.defer();
2016-06-28 03:53:49 +00:00
plugins.beautylog.log("setting challenge for " + domainNameArg);
2016-06-22 11:22:09 +00:00
cflare.createRecord(prefixName(domainNameArg), "TXT", challengeArg).then(function () {
2016-06-28 03:53:49 +00:00
plugins.beautylog.ok("Challenge has been set!");
plugins.beautylog.info("We need to cool down to let DNS propagate to edge locations!");
2016-06-22 11:22:09 +00:00
cooldown().then(function () {
done.resolve();
});
});
return done.promise;
};
var cleanChallenge = function (domainNameArg) {
var done = plugins.q.defer();
2016-06-28 03:53:49 +00:00
plugins.beautylog.log("cleaning challenge for " + domainNameArg);
2016-06-22 11:22:09 +00:00
cflare.removeRecord(prefixName(domainNameArg), "TXT");
return done.promise;
};
var cooldown = function () {
var done = plugins.q.defer();
2016-06-28 03:53:49 +00:00
var cooldowntime = 40000;
var passedTime = 0;
plugins.beautylog.log("Cooling down! " + (cooldowntime / 1000).toString() + " seconds left");
var coolDownCounter = function () {
setTimeout(function () {
if (cooldowntime <= passedTime) {
plugins.beautylog.ok("Cooled down!");
done.resolve();
}
else {
passedTime = passedTime + 5000;
plugins.beautylog.log("Cooling down! " + ((cooldowntime - passedTime) / 1000).toString() + " seconds left");
coolDownCounter();
}
}, 5000);
};
coolDownCounter();
2016-06-22 11:22:09 +00:00
return done.promise;
};
var prefixName = function (domainNameArg) {
return "_acme-challenge." + domainNameArg;
};
smartcli.addCommand({
commandName: "deploy_challenge"
}).then(function (argv) {
setChallenge(argv._[1], argv._[3]);
});
smartcli.addCommand({
commandName: "clean_challenge"
}).then(function (argv) {
cleanChallenge(argv._[1]);
});
smartcli.startParse();
2016-06-18 13:07:54 +00:00
2016-06-28 03:53:49 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNlcnQuaG9vay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUdBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBQzFDLElBQVksS0FBSyxXQUFNLGNBQWMsQ0FBQyxDQUFBO0FBRXRDLElBQUksUUFBUSxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxRQUFRLEVBQUUsQ0FBQztBQUUvQyxJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsS0FBSyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQzdELElBQUksTUFBTSxHQUFHLElBQUksT0FBTyxDQUFDLE1BQU0sQ0FBQyxhQUFhLEVBQUUsQ0FBQztBQUNoRCxNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ1IsS0FBSyxFQUFFLE1BQU0sQ0FBQyxPQUFPO0lBQ3JCLEdBQUcsRUFBRSxNQUFNLENBQUMsS0FBSztDQUNwQixDQUFDLENBQUM7QUFFSCxJQUFJLFlBQVksR0FBRyxVQUFDLGFBQXFCLEVBQUUsWUFBb0I7SUFDM0QsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsR0FBRyxhQUFhLENBQUMsQ0FBQztJQUN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