@adp-psych/container-tools
Version:
Tools for using containers for psychology experiments
62 lines (53 loc) • 1.74 kB
JavaScript
/*
* Copyright (C) 2021 Anthony Di Pietro
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @file Generates a self-signed TLS certificate.
*
* @requires selfsigned-certificate
* @author Anthony Di Pietro <anthony.dipietro@research.uwa.edu.au>
* @copyright © 2021 Anthony Di Pietro
* @license AGPL-3.0-or-later
*/
const generateSelfsignedCertificate =
require('../lib/generate-selfsigned-certificate.js');
const BINARY_NAME = 'generate-selfsigned-certificate';
const usage = () => {
console.error(
`Usage: ${BINARY_NAME} <key_filename> <certificate_filename>`,
);
console.error('');
console.error(`Example: ${BINARY_NAME} tls/privkey.pem tls/cert.pem`);
};
const main = () => {
const [keyFilename, certificateFilename] = process.argv.slice(2);
if (keyFilename === '--help' || keyFilename === '-h') {
usage();
} else if (typeof certificateFilename === 'undefined') {
usage();
process.exitCode = 1;
} else {
try {
generateSelfsignedCertificate(
keyFilename, certificateFilename,
);
} catch (error) {
process.exitCode = error;
}
}
};
main();