greenlock.js-ARCHIVED/bin/add.js

87 lines
2.6 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('./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
2019-11-03 01:33:12 +00:00
var Flags = require('./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',
'server-key-type',
'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) {
main(argList, flags, rc, greenlock, mconf);
}, args);
});
2019-11-02 05:33:11 +00:00
2019-11-03 01:33:12 +00:00
async function main(_, flags, rc, greenlock, mconf) {
if (!flags.subject) {
console.error(
'--subject must be provided as the id of the site/certificate'
);
process.exit(1);
return;
}
2019-11-02 05:33:11 +00:00
2019-11-03 01:33:12 +00:00
Flags.mangleFlags(flags, mconf);
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();
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;
}
console.info();
console.info('Created config!');
console.info();
2019-11-02 05:33:11 +00:00
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]));
}
});
console.info();
});
});
}