greenlock.js/bin/add.js

92 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-11-02 05:33:11 +00:00
'use strict';
var args = process.argv.slice(3);
var cli = require('./lib/cli.js');
2019-11-03 01:33:12 +00:00
//var path = require('path');
2019-11-02 05:33:11 +00:00
//var pkgpath = path.join(__dirname, '..', 'package.json');
2019-11-03 01:33:12 +00:00
//var pkgpath = path.join(process.cwd(), 'package.json');
2019-11-02 05:33:11 +00:00
var Flags = require('./lib/flags.js');
2019-11-02 05:33:11 +00:00
2019-11-03 01:33:12 +00:00
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) {
var myFlags = {};
[
'subject',
'altnames',
'renew-offset',
'subscriber-email',
'customer-email',
2019-11-03 01:33:12 +00:00
'server-key-type',
'challenge-http-01',
'challenge-http-01-xxxx',
'challenge-dns-01',
'challenge-dns-01-xxxx',
'challenge-tls-alpn-01',
'challenge-tls-alpn-01-xxxx',
2019-11-03 01:33:12 +00:00
'challenge',
'challenge-xxxx',
'challenge-json',
'force-save'
].forEach(function(k) {
myFlags[k] = flagOptions[k];
2019-11-02 05:33:11 +00:00
});
2019-11-03 01:33:12 +00:00
cli.parse(myFlags);
cli.main(function(argList, flags) {
Flags.mangleFlags(flags, mconf);
main(argList, flags, rc, greenlock);
2019-11-03 01:33:12 +00:00
}, args);
});
2019-11-02 05:33:11 +00:00
async function main(_, flags, rc, greenlock) {
if (!flags.subject || !flags.altnames) {
2019-11-03 01:33:12 +00:00
console.error(
'--subject and --altnames must be provided and should be valid domains'
2019-11-03 01:33:12 +00:00
);
process.exit(1);
return;
}
2019-11-02 05:33:11 +00:00
2019-11-03 01:33:12 +00:00
greenlock
.add(flags)
.catch(function(err) {
2019-11-02 05:33:11 +00:00
console.error();
console.error('error:', err.message);
console.error();
process.exit(1);
2019-11-03 01:33:12 +00:00
})
.then(function() {
return greenlock
._config({
servername:
flags.altnames[
Math.floor(Math.random() * flags.altnames.length)
]
})
.then(function(site) {
if (!site) {
console.info();
console.info(
'Internal bug or configuration mismatch: No config found.'
);
console.info();
process.exit(1);
return;
}
2019-11-02 05:33:11 +00:00
console.info();
2019-11-03 01:33:12 +00:00
Object.keys(site).forEach(function(k) {
if ('defaults' === k) {
console.info(k + ':');
Object.keys(site.defaults).forEach(function(key) {
var value = JSON.stringify(site.defaults[key]);
console.info('\t' + key + ':' + value);
});
} else {
console.info(k + ': ' + JSON.stringify(site[k]));
}
});
});
});
}