chore: set environment variables from option names

This commit is contained in:
Matthew Lopez 2024-06-05 16:24:37 -04:00
parent 9340afd844
commit 6fc3580331
No known key found for this signature in database
GPG Key ID: 302A6EE3D63B7E0E

View File

@ -18,44 +18,37 @@ const optionsConfig = {
nintendo_ca_g3_path: {
shortOption: 'g3',
default: './CACERT_NINTENDO_CA_G3.der',
description: 'Path to Nintendo CA - G3 certificate (may be in DER or PEM format, default to this directory)',
env: 'SSSL_NINTENDO_CA_G3_PATH'
description: 'Path to Nintendo CA - G3 certificate (may be in DER or PEM format, default to this directory)'
},
nintendo_ca_g3_format: {
shortOption: 'f',
default: 'der',
description: 'Nintendo CA - G3 certificate format (must be "der" or "pem")',
env: 'SSSL_NINTENDO_CA_G3_FORMAT'
description: 'Nintendo CA - G3 certificate format (must be "der" or "pem")'
},
ca_private_key_path: {
shortOption: 'cap',
default: undefined,
description: 'Path to private key for forged CA (will generate if not set)',
env: 'SSSL_CA_PRIVATE_KEY_PATH'
description: 'Path to private key for forged CA (will generate if not set)'
},
site_private_key_path: {
shortOption: 'sp',
default: undefined,
description: 'Path to private key for site certificate (will generate if not set)',
env: 'SSSL_SITE_PRIVATE_KEY_PATH'
description: 'Path to private key for site certificate (will generate if not set)'
},
csr_path: {
shortOption: 'csrp',
default: undefined,
description: 'Path to CSR (will generate if not set)',
env: 'SSSL_CSR_PATH'
description: 'Path to CSR (will generate if not set)'
},
common_name: {
shortOption: 'cn',
default: '*',
description: 'CN for site certificate (default to "*")',
env: 'SSSL_COMMON_NAME'
description: 'CN for site certificate (default to "*")'
},
output_folder_path: {
shortOption: 'o',
default: './',
description: 'Output folder (default to this directory)',
env: 'SSSL_OUTPUT_FOLDER_PATH'
description: 'Output folder (default to this directory)'
}
};
@ -78,7 +71,7 @@ async function main() {
const options = {};
for (const [option, config] of Object.entries(optionsConfig)) {
options[option] = commandOptions[option] || process.env[config.env] || config.default;
options[option] = commandOptions[option] || process.env['SSSL_' + option.toUpperCase()] || config.default;
}
if (validateOptions(options)) {