-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
371b3ac
commit 066cd5a
Showing
38 changed files
with
642 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
const cli = require(`../lib/cli`); | ||
cli.execute(); | ||
const path = require(`path`); | ||
const cli = require(path.join(__dirname, '..', 'lib', 'cli')); | ||
cli(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// const operations = require(`./lib/protocol`); | ||
// console.log(operations.client.auth_failure); | ||
|
||
const config = require(`./lib/client/config`).load(); | ||
const Client = require(`./lib/client/client`); | ||
|
||
const client = Client.connect(config); | ||
|
||
// const operations = require(`./lib/protocol-loader`)('client'); | ||
// console.log(operations); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
client: | ||
tls: | ||
use_tls: false | ||
host: "localhost" | ||
port: 1234 | ||
auth: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NDE4NzQwMDksIm5iZiI6MTY0MTg3NDAwOSwiZXhwIjoxNzk5NjYyMDA5LCJpc3MiOiJsb2NhbGhvc3Q6MTIzNCJ9.oa3vSUL2KcQ356YUecpVlct6zCCmOios4CbdA0Ng2Lg" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
server: | ||
tls: | ||
use_tls: false | ||
private_key: "path/to/private/key" | ||
certificate: "path/to/certificate" | ||
listen: | ||
host: "localhost" | ||
port: 1234 | ||
keep_alive_interval: 2000 | ||
|
||
authentication: | ||
private_key: | ||
type: "string" | ||
value: "asdf1234" | ||
public_key: | ||
type: "string" | ||
value: "asdf1234" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const { generateToken } = require(`./lib/authentication`); | ||
const config = require(`./lib/config`).load(); | ||
|
||
console.log(generateToken(config)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// const config = require(`./lib/config`).load(); | ||
|
||
// const { protocol } = require(`./lib/proto/auth`); | ||
|
||
// protocol.local(config, '1d'); | ||
|
||
// const token = generateToken(config, 500); | ||
// console.log(token); | ||
// const decoded = tryAuthenticateToken(config, token); | ||
// console.log(decoded); | ||
|
||
const config = require(`./lib/server/config`).load(); | ||
|
||
const Server = require('./lib/server/server'); | ||
const server = new Server(config); | ||
|
||
server.on('listening', function(port, host) { | ||
console.log(`listening on ${host}:${port}`); | ||
}); | ||
|
||
server.on('error', function(error) { | ||
console.log(error); | ||
}); | ||
|
||
server.listen(1234); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { generateToken } = require(`../../server/authentication`); | ||
|
||
module.exports = (notBefore, expiresIn, audience, channel, ...events) => { | ||
const config = require(`../../server/config`).load(); | ||
const token = generateToken(config, { | ||
notBefore, | ||
expiresIn: expiresIn === 'never' ? undefined : expiresIn, | ||
audience: audience == '*' ? undefined : audience, | ||
channel, | ||
events | ||
}); | ||
|
||
console.log(token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const Server = require(`../../server/server`); | ||
|
||
module.exports = () => { | ||
const config = require(`../../server/config`).load(); | ||
const server = new Server(config); | ||
|
||
server.on('listening', function(port, host) { | ||
console.log(`listening on ${host}:${port}`); | ||
}); | ||
|
||
server.on('error', function(error) { | ||
console.log(error); | ||
}); | ||
|
||
server.listen(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,14 @@ | ||
const yargs = require(`yargs`); | ||
const fs = require(`fs`); | ||
const path = require(`path`); | ||
|
||
const COMM_MODULES = { | ||
api: require(`./commands/api`), | ||
database: require(`./commands/database`) | ||
}; | ||
const SuperCli = require('super-cli'); | ||
|
||
async function execute() { | ||
const compiled = yargs | ||
.usage(`coattail -l | -h | [ -m <module> [ -l | -a <action> [ -f <flags> | -l ] ] ]`) | ||
.option('m', { alias: 'module', describe: 'Module on which to perform action.', type: 'string' }) | ||
.option('a', { alias: 'action', describe: 'Action to perform on specified module.', type: 'string'}) | ||
.option('l', { alias: 'list', describe: 'Lists available modules, available actions for specified module or available flags for specified action..', type: 'boolean'}) | ||
.option('h', { alias: 'help', describe: 'Shows this help message.', type: 'boolean'}) | ||
.options('f', { alias: 'flags', describe: 'Flags to pass to specified action.', type: 'array'}); | ||
module.exports = () => { | ||
const cli = new SuperCli(); | ||
|
||
const options = compiled.argv; | ||
|
||
if (process.argv.length < 3 || options.help) { | ||
compiled.showHelp(); | ||
compiled.exit(0); | ||
} | ||
|
||
if (options.module) { | ||
const modName = options.module; | ||
|
||
if (! Object.keys(COMM_MODULES).includes(modName)) { | ||
console.log(`Invalid module '${modName}'.`); | ||
compiled.exit(1); | ||
} | ||
|
||
const mod = COMM_MODULES[modName]; | ||
|
||
if (options.action) { | ||
const actionName = options.action; | ||
|
||
if (! Object.keys(mod.actions).includes(actionName)) { | ||
console.log(`Invalid action '${actionName}' for module '${modName}'.`); | ||
compiled.exit(1); | ||
} | ||
|
||
const action = mod.actions[actionName]; | ||
|
||
if (options.list) { | ||
console.log(`Available flags for action '${options.action}' of module '${modName}':`); | ||
const flagNames = Object.keys(action.flags); | ||
flagNames.forEach(name => console.log(` - ${name}: ${action.flags[name]}`)); | ||
compiled.exit(0); | ||
} | ||
|
||
if (options.flags && options.flags.length > 0) { | ||
options.flags.forEach(flag => { | ||
if (! Object.keys(action.flags).includes(flag)) { | ||
console.log(`Invalid flag '${flag}' for action '${actionName}' of module '${modName}'.`); | ||
compiled.exit(1); | ||
} | ||
}) | ||
} | ||
|
||
try { | ||
await mod[actionName](options.flags); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} else { | ||
if (options.list) { | ||
console.log(`Available actions for module '${modName}':`); | ||
const actionNames = Object.keys(mod.actions); | ||
actionNames.forEach(name => console.log(` - ${name}: ${mod.actions[name].description}`)); | ||
compiled.exit(0); | ||
} | ||
} | ||
} else { | ||
if (options.list) { | ||
console.log(`coattail: Available modules:`); | ||
const moduleNames = Object.keys(COMM_MODULES); | ||
moduleNames.forEach(name => console.log(` - ${name}: ${COMM_MODULES[name].description}`)); | ||
compiled.exit(0); | ||
} | ||
|
||
if (options.help) { | ||
compiled.showHelp(); | ||
compiled.exit(0); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
execute | ||
}; | ||
fs.readdirSync(path.join(__dirname, 'commands')).forEach(commandFile => { | ||
const commandName = commandFile.replace('.js', ''); | ||
const command = require(`.${path.sep}${path.join('commands', commandName)}`); | ||
cli.on(commandName, command); | ||
}); | ||
} |
Oops, something went wrong.