authweiler
Version:
A full-flegded 0Auth2.0 HTTP proxy server
117 lines (110 loc) • 3.37 kB
JavaScript
// implements start, stop, restart, and mode (repl, cli) commands
const inquirer = require('inquirer');
const { start } = require('../../lib/core');
const path = require('path');
/**
*
* @param serverOptions
* @returns {*}
*/
function startServer(serverOptions) {
console.log('aw start');
return start(serverOptions)
}
/**
*
* @type {{name: string, commandFn: *, description: string}}
*/
exports.start = {
name: 'start',
description: 'Start the server',
builder:{
c: { alias: 'config', describe: 'path to yaml config file' },
o: { alias: 'console', describe: 'start with console' },
},
exec: function (argv) {
console.log('starting aw');
if(argv.port) {
console.log('starting aw');
startServer({ port: argv.port })
}
}
};
/**
* kills old process and spins up a new process with new configuration
* @type {{name: string, builder: {p: {alias: string, describe: string}}, description: string, exec: exec}}
*/
exports.reload = {
name: 'reload',
description: 'Reload configuration',
builder: {
p: { alias: 'path', describe: 'path to yaml config file' },
},
exec: function (argv) {
console.log('reloading server')
}
}
/**
*
* @type {{name: string, commandFn: *, description: string, execute: execute}}
*/
exports.init = {
name: 'init',
description: 'initialise a new auth service (via prompts)',
builder: {
c: { alias: 'config', describe: 'path to yaml config file' },
o: { alias: 'console', describe: 'start with console' }
},
/**
*
* @param options
* @returns {Promise<T>}
*/
exec: function (argv) {
const questions = [
{
type: 'number',
name: 'port',
default: 3000,
message: 'Enter http proxy port',
},
{
type: 'input',
name: 'authEndpoint',
default: '/api/auth',
message: 'Enter preferred authorization endpoint path',
},
{
type: 'input',
name: 'tokenEndpoint',
default: '/api/auth/token',
message: 'Enter preferred token endpoint path'
},
{
type: 'checkbox',
name: 'grantTypes',
message: 'Choose grant types to support',
choices: ['Authorization Code', 'Implicit', 'Resource Owner (Password)', 'Client Credentials', 'Device Code', 'Refresh Token']
},
{
type: 'checkbox',
name: 'extendedProfiles',
message: 'Choose extended profiles to support',
choices: ['JWT Bearer Token', 'OpenId']
},
{
type: 'confirm',
name: 'wantsToGenerateKeys',
message: 'Would you like to generate JWT signing keys'
},
{
type: 'input',
name: 'configPath',
default: path.resolve(__dirname, './', 'aw.config.yaml'),
message: 'Enter config output path',
}
];
return inquirer.prompt(questions)
.then((answers) => { console.log(answers) })
}
};