smartcert/dist/cert.hook.js

51 lines
5.7 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();
var config = plugins.smartfile.local.toObjectSync(paths.config);
var cflare = new plugins.cflare.CflareAccount();
cflare.auth({
email: config.cfEmail,
key: config.cfKey
});
var setChallenge = function (domainNameArg, challengeArg) {
var done = plugins.q.defer();
cflare.createRecord(prefixName(domainNameArg), "TXT", challengeArg).then(function () {
cooldown().then(function () {
done.resolve();
});
});
return done.promise;
};
var cleanChallenge = function (domainNameArg) {
var done = plugins.q.defer();
cflare.removeRecord(prefixName(domainNameArg), "TXT");
return done.promise;
};
var cooldown = function () {
var done = plugins.q.defer();
console.log("Cooling down!");
setTimeout(function () {
done.resolve();
}, 20000);
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-22 11:35:15 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNlcnQuaG9vay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUdBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBQzFDLElBQVksS0FBSyxXQUFNLGNBQWMsQ0FBQyxDQUFBO0FBRXRDLElBQUksUUFBUSxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxRQUFRLEVBQUUsQ0FBQztBQUUv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