Skip to content

Commit

Permalink
Merge pull request #3 from ThePumpingLemma/add-cli-parser
Browse files Browse the repository at this point in the history
Add CLI parser...
  • Loading branch information
santthosh committed Apr 27, 2016
2 parents 319a664 + 67365a8 commit b781d39
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ node_modules
.node_repl_history

.aws_configure
.idea
.idea
*.swo
*.swp
65 changes: 53 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,61 @@ var bodyParser = require('body-parser');
var stream = require('stream');
var figlet = require('figlet');

if (process.argv.length != 3) {
console.error('usage: aws-es-proxy <aws-es-cluster-endpoint>');
var yargs = require('yargs')
.usage('usage: $0 [options] <aws-es-cluster-endpoint>')
.option('b', {
alias: 'bind-address',
default: '127.0.0.1',
demand: false,
describe: 'the ip address to bind to',
type: 'string'
})
.option('p', {
alias: 'port',
default: 9200,
demand: false,
describe: 'the port to bind to',
type: 'number'
})
.option('r', {
alias: 'region',
demand: false,
describe: 'the region of the Elasticsearch cluster',
type: 'string'
})
.help()
.version()
.strict();
var argv = yargs.argv;

if (argv._.length !== 1) {
yargs.showHelp();
process.exit(1);
}
var ENDPOINT = process.argv[2];
var m = ENDPOINT.match(/\.([^.]+)\.es\.amazonaws\.com\.?$/);
if (!m) {
console.error('region cannot be parsed from endpoint address, must end in .<region>.es.amazonaws.com');
process.exit(1);

var ENDPOINT = argv._[0];

// Try to infer the region if it is not provided as an argument.
var REGION = argv.r;
if (!REGION) {
var m = ENDPOINT.match(/\.([^.]+)\.es\.amazonaws\.com\.?$/);
if (m) {
REGION = m[1];
} else {
console.error('region cannot be parsed from endpoint address, etiher the endpoint must end ' +
'in .<region>.es.amazonaws.com or --region should be provided as an argument');
yargs.showHelp();
process.exit(1);
}
}

var TARGET = argv._[0];
if (!TARGET.match(/^https?:\/\//)) {
TARGET = 'https://' + TARGET;
}
var REGION = m[1];
var TARGET = 'https://' + process.argv[2];
var PORT = 9200;
var BIND_ADDRESS = '127.0.0.1';

var BIND_ADDRESS = argv.b;
var PORT = argv.p;

var creds;
var chain = new AWS.CredentialProviderChain();
Expand Down Expand Up @@ -83,4 +124,4 @@ console.log(figlet.textSync('AWS ES Proxy!', {
}));

console.log('AWS ES cluster available at http://' + BIND_ADDRESS + ':' + PORT);
console.log('Kibana available at http://' + BIND_ADDRESS + ':' + PORT + '/_plugin/kibana/');
console.log('Kibana available at http://' + BIND_ADDRESS + ':' + PORT + '/_plugin/kibana/');
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"body-parser": "^1.15.0",
"express": "^4.13.4",
"figlet": "^1.1.1",
"http-proxy": "^1.13.2"
"http-proxy": "^1.13.2",
"yargs": "^4.6.0"
}
}

0 comments on commit b781d39

Please sign in to comment.