Skip to content

Commit

Permalink
updated with new tcpip code
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-fiscaletti committed Jan 11, 2022
1 parent 371b3ac commit 066cd5a
Show file tree
Hide file tree
Showing 38 changed files with 642 additions and 346 deletions.
5 changes: 3 additions & 2 deletions bin/index.js
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();
10 changes: 10 additions & 0 deletions client_test.js
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);
6 changes: 6 additions & 0 deletions config/client.yml
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"
14 changes: 0 additions & 14 deletions config/development.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions config/production.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions config/server.yml
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"
14 changes: 0 additions & 14 deletions config/staging.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions generate_token.js
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));
25 changes: 25 additions & 0 deletions index.js
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);
5 changes: 0 additions & 5 deletions lib/api/controllers/subscriptions.js

This file was deleted.

7 changes: 0 additions & 7 deletions lib/api/endpoints/subscribe.js

This file was deleted.

37 changes: 0 additions & 37 deletions lib/api/index.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/api/middleware/authentication.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/cli/commands/api.js

This file was deleted.

48 changes: 0 additions & 48 deletions lib/cli/commands/database.js

This file was deleted.

14 changes: 14 additions & 0 deletions lib/cli/commands/generate-sub-token.js
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);
}
16 changes: 16 additions & 0 deletions lib/cli/commands/start-server.js
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();
}
98 changes: 11 additions & 87 deletions lib/cli/index.js
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);
});
}
Loading

0 comments on commit 066cd5a

Please sign in to comment.