Skip to content

Commit

Permalink
Merge pull request #247 from apigee-internal/for302
Browse files Browse the repository at this point in the history
introduce change for code quality
  • Loading branch information
keyurkarnik authored Jul 2, 2019
2 parents 7b493e7 + a8fbaba commit fe9202a
Show file tree
Hide file tree
Showing 39 changed files with 5,905 additions and 2,429 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ logging-report.txt
logstuf.txt
quick.sh
.nyc_output
test-e2e-local
16 changes: 13 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"esversion": 6,
"node": true
}
"asi" : true,
"esversion" : 6,
"node" : true,
"sub" : true,
"strict": true,
"white": true,
"unused": true,
"eqeqeq": true,
"maxparams": 10,
"maxdepth": 5,
"maxstatements": 25,
"maxcomplexity": 10
}
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
language: node_js
node_js:
- '6.14'
- '8'
- '10'
- '12'
notifications:
slack:
secure: RK3HxQ0I107uWCqq+yhfLwiJMBFqnkXq0fyZGbX3TuhIeVXG3huyuwzSVt3NHVX1KJiWbKuFnJOKFfIRPlZEVxrlqOHEoqUhwjC4Zt35QGBrSZQJF6aSKsL2qe8U042zcClrKDvZ4Ool34XAU255LKgeIJVkOmn8gYe/LIfUETGrbWxM1sm03cUpdXwy9ggDVLKifE8SJ/ZDXmzwCx9M/t/1BTX90u6OUsQHJbpkEkbAD8U3vCM49tdmnpV0lh0JZoQwf74+O5c1zE3yj0uDfGz9HAXUJ84Fcr8OAwBFlooUCKLbmWOi4aETzU/byzI6H//d1gGAydHrqnbb+esRr4UD7NvWQQP77ZcAOLeII3rDepzkCJ8ozi5ht246gIwimO2SbJ378tu9sfEaZo6bVXqg8FkNq/G1Swu/5gp9xp5r02lMRkQpIovXMe3o2emYjRF/zHJAKye9ISAHP0yXrqYUZDwn/Ll2OtgSYXg5/hP0R5CGWX8yr6ahOVGHJiF1ndQMnyUrLMAT4WPrd/joFWCmJsd/p8jncqaZYrjVb+FhuMfjUatmXSYY6cVV3aV+kgZyHuLTKQNa7Hp40I836lUAu+qOEZ8jwIKYWS5N8ge0IN2XVpE4JMfG/7UW1r9N7MY24pvNQww0NDPi5Zd1bQPurWwjnBV5YGHc5XGe2/8=
Expand Down
18 changes: 11 additions & 7 deletions cli/cmd-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const setup = function setup() {
.option('-f, --force', 'replace any existing keys')
.description('install a certificate for your organization')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;
if (options.token) {
if (!options.org) { return options.error('org is required'); }
Expand All @@ -42,7 +42,7 @@ const setup = function setup() {
.option('-p, --password <password>', 'password of the organization admin')
.description('delete the certificate for your organization')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;
if (options.token) {
if (!options.org) { return options.error('org is required'); }
Expand All @@ -68,7 +68,7 @@ const setup = function setup() {
.option('-p, --password <password>', 'password of the organization admin')
.description('check that your organization has a certificate installed')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;
if (options.token) {
if (!options.org) { return options.error('org is required'); }
Expand All @@ -91,7 +91,7 @@ const setup = function setup() {
.option('-e, --env <env>', 'the environment')
.description('retrieve the public key')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
if (!options.org) { return options.error('org is required'); }
if (!options.env) { return options.error('env is required'); }
cert.retrievePublicKey(options)
Expand All @@ -109,9 +109,13 @@ const setup = function setup() {
commander.help();
}
};
function optionError(message) {
console.error(message);
this.help();
function optionError(caller) {
return(((obj) => {
return((message) => {
console.error(message);
obj.help();
});
})(caller))
}
// prompt for a password if it is not specified
function promptForPassword( options, cb) {
Expand Down
19 changes: 12 additions & 7 deletions cli/cmd-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function() {
.option('-d, --debug', 'execute with debug output')

.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;
options.configDir = options.configDir || process.env.EDGEMICRO_CONFIG_DIR;

Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports = function() {
.option('-t, --token <token>', 'OAuth token to use with management API')
.description('upgrade kvm to support JWT Key rotation')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;

if (!options.token) {
Expand Down Expand Up @@ -131,7 +131,7 @@ module.exports = function() {
.option('-t, --token <token>', 'OAuth token to use with management API')
.description('upgrade edgemicro-auth proxy')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;

if (!options.token) {
Expand Down Expand Up @@ -173,7 +173,7 @@ module.exports = function() {
.option('-t, --token <token>', 'OAuth token to use with management API')
.description('Rotate JWT Keys')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;

if (!options.token) {
Expand Down Expand Up @@ -229,7 +229,12 @@ function promptForPassword(options, cb) {
}
}

function optionError(message) {
console.error(message);
this.help();
function optionError(caller) {
return(((obj) => {
return((message) => {
console.error(message);
obj.help();
});
})(caller))
}

17 changes: 11 additions & 6 deletions cli/cmd-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const setup = function setup() {
.option('-f, --file <file>', 'file containing jwt')
.description('decode a token without verifying it')
.action((options)=>{
options.error = optionError;
options.error = optionError(options);
if (!options.file) {return options.error( 'file is required' );}
token.decodeToken(options)
});
Expand All @@ -22,7 +22,7 @@ const setup = function setup() {
.option('-e, --env <env>', 'the environment')
.description('verify a jwt token against the public key')
.action((options)=> {
options.error = optionError;
options.error = optionError(options);
if (!options.file) { return options.error('file is required'); }
if (!options.org) { return options.error('org is required'); }
if (!options.env) { return options.error('env is required'); }
Expand All @@ -37,7 +37,7 @@ const setup = function setup() {
.option('-s, --secret <secret>', 'the client secret')
.description('create a client_credentials oauth token')
.action((options)=>{
options.error = optionError;
options.error = optionError(options);
if (!options.org) { return options.error('id is required'); }
if (!options.secret) { return options.error('client secret is required'); }
if (!options.org) { return options.error('org is required'); }
Expand All @@ -59,9 +59,14 @@ const setup = function setup() {
}
};

function optionError(message) {
console.error(message);
this.help();
function optionError(caller) {
return(((obj) => {
return((message) => {
console.error(message);
obj.help();
});
})(caller))
}


module.exports = setup;
58 changes: 37 additions & 21 deletions cli/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const setup = function setup() {
.option('-k --key <key>', 'Path to private key to be used by Apigee Edge')
.option('-s --cert <cert>', 'Path to certificate to be used by Apigee Edge')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;

if (options.token) {
Expand Down Expand Up @@ -108,7 +108,7 @@ const setup = function setup() {
.option('-k, --key <key>', 'key for authenticating with Edge')
.option('-s, --secret <secret>', 'secret for authenticating with Edge')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
if (!options.org) {
return options.error('org is required');
}
Expand Down Expand Up @@ -142,7 +142,7 @@ const setup = function setup() {
.option('-t, --target <target>', 'target endpoint for proxy; required if apiProxyName is set')
.description('start the gateway based on configuration')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.secret = options.secret || process.env.EDGEMICRO_SECRET;
options.key = options.key || process.env.EDGEMICRO_KEY;
options.org = options.org || process.env.EDGEMICRO_ORG;
Expand Down Expand Up @@ -185,15 +185,15 @@ const setup = function setup() {
//if any of these are set, look for environment variable
if (!process.env.EDGEMICRO_LOCAL && !process.env.EDGEMICRO_LOCAL_PROXY) {
return options.error('set the EDGEMICRO_LOCAL or EDGEMICRO_LOCAL_PROXY variable for apiProxyName parameter');
process.exit(1);
//process.exit(1);
} else if (process.env.EDGEMICRO_LOCAL && process.env.EDGEMICRO_LOCAL_PROXY) {
return options.error('set the EDGEMICRO_LOCAL or EDGEMICRO_LOCAL_PROXY; not both');
process.exit(1);
//process.exit(1);
} else {
if (options.apiProxyName && options.target && options.revision && options.basepath) {
if (!validateUrl(options.target)) {
return options.error('target endpoint not a valid url');
process.exit(1);
//process.exit(1);
}
if (process.env.EDGEMICRO_LOCAL) {
//create fake credentials - not used anywhere
Expand All @@ -205,7 +205,7 @@ const setup = function setup() {
return;
} else {
return options.error('apiProxyName, target, revision and basepath are all mandatory parms when EDGEMICRO_LOCAL or EDGEMICRO_LOCAL_PROXY is set');
process.exit(1);
//process.exit(1);
}
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ const setup = function setup() {
.option('-u, --configUrl <configUrl>', 'Provide the endpoint to download the edgemicro config file')
.description('reload the edgemicro cluster by pulling new configuration')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.secret = options.secret || process.env.EDGEMICRO_SECRET;
options.key = options.key || process.env.EDGEMICRO_KEY;
options.org = options.org || process.env.EDGEMICRO_ORG;
Expand Down Expand Up @@ -324,7 +324,7 @@ const setup = function setup() {
.description('Start microgateway using forever-monitor')
.action((options) => {
options.action = options.action || "start";
options.error = optionError;
options.error = optionError(options);
if (options.file) {
foreverOptions = JSON.parse(fs.readFileSync(options.file, {
encoding: 'utf8'
Expand All @@ -333,12 +333,16 @@ const setup = function setup() {
if (options.action !== "start" && options.action !== "stop") {
return options.error('action must be start or stop');
}

/* FOUND THIS WITHOUT ASSIGNMENT ?? What should it be doing?
foreverOptions ? foreverOptions : {
max: 3,
silent: false,
killTree: true,
minUptime: 2000
};
*/

var child = new(forever.Monitor)(path.join(__dirname, '..', 'app.js'), foreverOptions);
if (options.action == "start") {
try {
Expand Down Expand Up @@ -374,7 +378,7 @@ const setup = function setup() {
.option('-p, --password <password>', 'password of the organization admin')
.description('generate authentication keys for runtime auth between Microgateway and Edge')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
if (!options.username) {
return options.error('username is required');
}
Expand All @@ -389,7 +393,11 @@ const setup = function setup() {
return options.error('password is required');
}
keyGenerator.generate(options, (err) => {
err ? process.exit(1) : process.exit(0);
if ( err ) {
process.exit(1)
} else {
process.exit(0)
}
});
})

Expand All @@ -405,7 +413,7 @@ const setup = function setup() {
.option('-s, --secret <secret>', 'Microgateway secret to be revoked')
.description('revoke authentication keys for runtime auth between Microgateway and Edge')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
if (!options.username) {
return options.error('username is required');
}
Expand All @@ -426,7 +434,11 @@ const setup = function setup() {
return options.error('password is required');
}
keyGenerator.revoke(options, (err) => {
err ? process.exit(1) : process.exit(0);
if ( err ) {
process.exit(1)
} else {
process.exit(0)
}
});
});

Expand All @@ -443,7 +455,7 @@ const setup = function setup() {
.option('-b, --baseuri <baseuri>', 'baseuri for management apis')
.description('upgrade kvm to support JWT Key rotation')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
if (!options.org) {
return options.error('org is required');
}
Expand Down Expand Up @@ -476,7 +488,7 @@ const setup = function setup() {
.option('-b, --baseuri <baseuri>', 'baseuri for management apis')
.description('upgrade edgemicro-auth proxy')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
options.token = options.token || process.env.EDGEMICRO_SAML_TOKEN;

if (!options.org) {
Expand Down Expand Up @@ -511,7 +523,7 @@ const setup = function setup() {
.option('-b, --baseuri <baseuri>', 'baseuri for management apis')
.description('Rotate JWT Keys')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
if (!options.username) {
return options.error('username is required');
}
Expand Down Expand Up @@ -540,7 +552,7 @@ const setup = function setup() {
.option('-p, --password <password>', 'password of the organization admin')
.description('clean up microgateway artifacts from the org')
.action((options) => {
options.error = optionError;
options.error = optionError(options);
if (!options.username) {
return options.error('username is required');
}
Expand Down Expand Up @@ -575,11 +587,15 @@ const setup = function setup() {
}
};

function optionError(message) {
console.error(message);
this.help();
function optionError(caller) {
return(((obj) => {
return((message) => {
console.error(message);
obj.help();
});
})(caller))
}

// prompt for a password if it is not specified
function promptForPassword(options, cb) {

Expand Down
Loading

0 comments on commit fe9202a

Please sign in to comment.