apigeetool
Advanced tools
Comparing version 0.0.4 to 0.1.0
@@ -66,4 +66,9 @@ #!/usr/bin/env node | ||
} | ||
console.log(JSON.stringify(result)); | ||
if (!opts.json && commandModule.format) { | ||
console.log(commandModule.format(result)); | ||
} else { | ||
console.log(JSON.stringify(result)); | ||
} | ||
process.exit(0); | ||
}); | ||
} |
@@ -22,2 +22,8 @@ /* jshint node: true */ | ||
} | ||
}, | ||
undeploy: { | ||
description: 'Undeploy', | ||
load: function() { | ||
return require('./undeploy'); | ||
} | ||
} | ||
@@ -24,0 +30,0 @@ }; |
@@ -13,3 +13,3 @@ /* jshint node: true */ | ||
var ziputils = require('../ziputils'); | ||
var listdeployments = require('./listdeployments'); | ||
var parseDeployments = require('./parsedeployments'); | ||
@@ -52,2 +52,10 @@ var XmlExp = /(.+)\.xml$/; | ||
module.exports.format = function(r) { | ||
if (r.name) { | ||
return parseDeployments.formatDeployment(r); | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
module.exports.run = function(opts, cb) { | ||
@@ -80,5 +88,2 @@ defaults.defaultOptions(opts); | ||
deployProxy(opts, request, done); | ||
}, | ||
function(done) { | ||
displayStatus(opts, request, done); | ||
} | ||
@@ -93,3 +98,20 @@ ], | ||
} | ||
cb(undefined, results[results.length - 1]); | ||
var deployResult = results[results.length - 1]; | ||
var deployment = parseDeployments.parseDeploymentResult(deployResult); | ||
if (deployment) { | ||
// Look up the deployed URI for user-friendliness | ||
parseDeployments.getPathInfo([ deployment ], opts, function(err) { | ||
if (err) { | ||
// Ignore this error because deployment worked | ||
if (opts.verbose) { | ||
console.log('Error looking up deployed path: %s', err); | ||
} | ||
} | ||
cb(undefined, deployment); | ||
}); | ||
} else { | ||
// Probably import-only -- do nothing | ||
cb(undefined, {}); | ||
} | ||
} | ||
@@ -167,4 +189,6 @@ }); | ||
} | ||
console.log('Creating revision %d of API %s', opts.deploymentVersion, | ||
opts.api); | ||
if (opts.verbose) { | ||
console.log('Creating revision %d of API %s', opts.deploymentVersion, | ||
opts.api); | ||
} | ||
// The only way to do this is to import a ZIP. What fun. | ||
@@ -374,2 +398,3 @@ var zipBuf = ziputils.makeOneFileZip(ProxyBase, rootEntryName, rootDoc); | ||
}, function(err, req, body) { | ||
var jsonBody = (body ? JSON.parse(body) : null); | ||
if (err) { | ||
@@ -384,3 +409,3 @@ done(err); | ||
} | ||
done(); | ||
done(undefined, jsonBody); | ||
} else { | ||
@@ -390,3 +415,2 @@ if (opts.verbose) { | ||
} | ||
var jsonBody = JSON.parse(body); | ||
var errMsg; | ||
@@ -403,16 +427,1 @@ if (jsonBody && (jsonBody.message)) { | ||
} | ||
function displayStatus(opts, request, done) { | ||
if (opts.verbose) { | ||
console.log('Checking deployment status'); | ||
} | ||
var deployOpts = { | ||
organization: opts.organization, | ||
api: opts.api, | ||
username: opts.username, | ||
password: opts.password, | ||
verbose: opts.verbose, | ||
debug: opts.debug | ||
}; | ||
listdeployments.run(deployOpts, done); | ||
} |
@@ -15,3 +15,3 @@ /* jshint node: true */ | ||
var ziputils = require('../ziputils'); | ||
var listdeployments = require('./listdeployments'); | ||
var parseDeployments = require('./parsedeployments'); | ||
@@ -49,2 +49,10 @@ var ProxyBase = 'apiproxy'; | ||
module.exports.format = function(r) { | ||
if (r.name) { | ||
return parseDeployments.formatDeployment(r); | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
module.exports.run = function(opts, cb) { | ||
@@ -80,5 +88,2 @@ defaults.defaultOptions(opts); | ||
deployProxy(opts, request, done); | ||
}, | ||
function(done) { | ||
displayStatus(opts, request, done); | ||
} | ||
@@ -93,3 +98,20 @@ ], | ||
} | ||
cb(undefined, results[results.length - 1]); | ||
var deployResult = results[results.length - 1]; | ||
var deployment = parseDeployments.parseDeploymentResult(deployResult); | ||
if (deployment) { | ||
// Look up the deployed URI for user-friendliness | ||
parseDeployments.getPathInfo([ deployment ], opts, function(err) { | ||
if (err) { | ||
// Ignore this error because deployment worked | ||
if (opts.verbose) { | ||
console.log('Error looking up deployed path: %s', err); | ||
} | ||
} | ||
cb(undefined, deployment); | ||
}); | ||
} else { | ||
// Probably import-only -- do nothing | ||
cb(undefined, {}); | ||
} | ||
} | ||
@@ -168,4 +190,6 @@ }); | ||
} | ||
console.log('Creating revision %d of API %s', opts.deploymentVersion, | ||
opts.api); | ||
if (opts.verbose) { | ||
console.log('Creating revision %d of API %s', opts.deploymentVersion, | ||
opts.api); | ||
} | ||
// The only way to do this is to import a ZIP. What fun. | ||
@@ -514,12 +538,10 @@ var zipBuf = ziputils.makeOneFileZip(ProxyBase, rootEntryName, rootDoc); | ||
}, function(err, req, body) { | ||
var jsonBody = (body ? JSON.parse(body) : null); | ||
if (err) { | ||
done(err); | ||
} else if (req.statusCode === 200) { | ||
if (opts.verbose) { | ||
console.log('Deployment successful'); | ||
} | ||
if (opts.debug) { | ||
console.log('%s', body); | ||
console.log('%j', jsonBody); | ||
} | ||
done(); | ||
done(undefined, jsonBody); | ||
} else { | ||
@@ -529,3 +551,2 @@ if (opts.verbose) { | ||
} | ||
var jsonBody = JSON.parse(body); | ||
var errMsg; | ||
@@ -542,16 +563,1 @@ if (jsonBody && (jsonBody.message)) { | ||
} | ||
function displayStatus(opts, request, done) { | ||
if (opts.verbose) { | ||
console.log('Checking deployment status'); | ||
} | ||
var deployOpts = { | ||
organization: opts.organization, | ||
api: opts.api, | ||
username: opts.username, | ||
password: opts.password, | ||
verbose: opts.verbose, | ||
debug: opts.debug | ||
}; | ||
listdeployments.run(deployOpts, done); | ||
} |
@@ -5,6 +5,6 @@ /* jshint node: true */ | ||
var util = require('util'); | ||
var path = require('path'); | ||
var async = require('async'); | ||
var _ = require('underscore'); | ||
var defaults = require('../defaults'); | ||
var parseDeployments = require('./parsedeployments'); | ||
@@ -20,8 +20,22 @@ module.exports.descriptor = defaults.defaultDescriptor({ | ||
}, | ||
revision: { | ||
name: 'Revision', | ||
shortOption: 'r' | ||
}, | ||
long: { | ||
name: 'Long', | ||
shortOption: 'l' | ||
shortOption: 'l', | ||
toggle: true | ||
} | ||
}); | ||
module.exports.format = function(r) { | ||
var s = ''; | ||
_.each(r.deployments, function(d) { | ||
s += parseDeployments.formatDeployment(d); | ||
s += '\n'; | ||
}); | ||
return s; | ||
}; | ||
module.exports.run = function(opts, cb) { | ||
@@ -69,4 +83,9 @@ var uri; | ||
if (opts.long) { | ||
fillInPaths(result, opts, cb); | ||
parseDeployments.getPathInfo(result.deployments, opts, function(err) { | ||
cb(err, result); | ||
}); | ||
} else { | ||
if (opts.debug) { | ||
console.log('All done'); | ||
} | ||
cb(undefined, result); | ||
@@ -124,94 +143,1 @@ } | ||
} | ||
// If and only if "-l" is specified, get the URI path from the proxy | ||
// and from the virtual host, in parallel using "async." | ||
function fillInPaths(d, opts, cb) { | ||
// We will fill this in with "env-vhost" keys and URI values. | ||
var vhosts = {}; | ||
async.eachLimit(d.deployments, opts.asyncLimit, function(item, done) { | ||
fillInPath(item, opts, vhosts, done); | ||
}, function(err) { | ||
cb(err, d); | ||
}); | ||
} | ||
// Look at the "default" proxy definition to get paths and virtual hosts | ||
// If there is no proxy named "default," punt for now. | ||
function fillInPath(deployment, opts, vhosts, done) { | ||
var request = defaults.defaultRequest(opts); | ||
request.get(util.format('%s/v1/o/%s/apis/%s/revisions/%d/proxies/default', | ||
opts.baseuri, opts.organization, deployment.name, | ||
deployment.revision), | ||
function(err, req, body) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
if (req.statusCode === 200) { | ||
if (body.connection && body.connection.basePath) { | ||
deployment.proxyBasePath = body.connection.basePath; | ||
deployment.virtualHosts = body.connection.virtualHost; | ||
deployment.uris = []; | ||
fillInHosts(deployment, opts, vhosts, done); | ||
} else { | ||
done(); | ||
} | ||
} else if (req.statusCode === 404) { | ||
// Proxy is not named "default", so just skip | ||
done(); | ||
} else { | ||
done(new Error(util.format('HTTP status %d', req.statusCode))); | ||
} | ||
} | ||
}); | ||
} | ||
// For each of the proxy's virtual hosts, get the base URI. Cache the | ||
// results to speed up operations on big deployments | ||
function fillInHosts(deployment, opts, vhosts, done) { | ||
async.eachSeries(deployment.virtualHosts, function(item, itemDone) { | ||
var hostKey = util.format('%s-%s', deployment.environment, item); | ||
if (vhosts[hostKey]) { | ||
deployment.uris.push(makeUri(vhosts[hostKey], deployment.basePath, | ||
deployment.proxyBasePath)); | ||
itemDone(); | ||
} else { | ||
var request = defaults.defaultRequest(opts); | ||
request.get(util.format('%s/v1/o/%s/e/%s/virtualhosts/%s', | ||
opts.baseuri, opts.organization, | ||
deployment.environment, item), | ||
function(err, req, body) { | ||
if (err) { | ||
itemDone(err); | ||
} else if (req.statusCode === 200) { | ||
var port = parseInt(body.port); | ||
var uri; | ||
var scheme = (body.sSLInfo ? 'https' : 'http'); | ||
if (body.hostAliases && (body.hostAliases.length > 0)) { | ||
uri = util.format('%s://%s', scheme, body.hostAliases[0]); | ||
} else { | ||
uri = util.format('%s://localhost', scheme); | ||
} | ||
if (((scheme === 'http') && (port != 80)) || | ||
((scheme === 'https') && (port != 443))) { | ||
uri += ':' + port; | ||
} | ||
vhosts[hostKey] = uri; | ||
deployment.uris.push(makeUri(uri, deployment.basePath, | ||
deployment.proxyBasePath)); | ||
itemDone(); | ||
} else { | ||
itemDone(new Error(util.format('HTTP error %d', req.statusCode))); | ||
} | ||
}); | ||
} | ||
}, function(err) { | ||
done(err); | ||
}); | ||
} | ||
function makeUri(hostUri, basePath, proxyPath) { | ||
if (basePath === '/') { | ||
return hostUri + proxyPath; | ||
} | ||
return hostUri + basePath, proxyPath; | ||
} |
@@ -13,3 +13,3 @@ /* jshint node: true */ | ||
var defaults = require('../defaults'); | ||
var listdeployments = require('./listdeployments'); | ||
var parseDeployments = require('./parsedeployments'); | ||
@@ -56,2 +56,10 @@ /* From python apigeetool: | ||
module.exports.format = function(r) { | ||
if (r.name) { | ||
return parseDeployments.formatDeployment(r); | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
module.exports.run = function(opts, cb) { | ||
@@ -72,5 +80,2 @@ defaults.defaultOptions(opts); | ||
undeploy(opts, request, done); | ||
}, | ||
function(done) { | ||
displayStatus(opts, request, done); | ||
} | ||
@@ -85,3 +90,11 @@ ], | ||
} | ||
cb(undefined, results[results.length - 1]); | ||
var deployResult = results[results.length - 1]; | ||
var deployment = parseDeployments.parseDeploymentResult(deployResult); | ||
if (deployment) { | ||
cb(undefined, deployment); | ||
} else { | ||
// Can't parse the result -- do nothing | ||
cb(undefined, {}); | ||
} | ||
} | ||
@@ -93,2 +106,9 @@ }); | ||
// Just undeploy what we said | ||
if (opts.revision) { | ||
opts.deploymentVersion = opts.revision; | ||
done(); | ||
return; | ||
} | ||
// Find out which revision we should be undeploying | ||
@@ -107,3 +127,3 @@ request.get(util.format('%s/v1/o/%s/apis/%s', | ||
opts.deploymentVersion = | ||
parseInt(_.max(body.revision, function(r) { return parseInt(r); })) + 1; | ||
parseInt(_.max(body.revision, function(r) { return parseInt(r); })); | ||
if (opts.verbose) { | ||
@@ -125,16 +145,27 @@ console.log('Going to undeploy revision %d of API %s', | ||
} | ||
var uri = util.format('%s/v1/o/%s/e/%s/apis/%s/revisions/%d/deployments', | ||
opts.baseuri, opts.organization, opts.environment, opts.api, | ||
opts.deploymentVersion); | ||
var uri = util.format('%s/v1/o/%s/apis/%s/deployments', | ||
opts.baseuri, opts.organization, opts.api); | ||
if (opts.debug) { | ||
console.log('Going to send DELETE to %s', uri); | ||
console.log('Going to POST to %s', uri); | ||
} | ||
var deployCmd = util.format('action=undeploy&revision=%d&env=%s', | ||
opts.deploymentVersion, opts.environment); | ||
if (opts['base-path']) { | ||
deployCmd = util.format('%s&basepath=%s', deployCmd, opts['base-path']); | ||
} | ||
if (opts.debug) { | ||
console.log('Going go send command %s', deployCmd); | ||
} | ||
request({ | ||
uri: uri, | ||
method: 'DELETE', | ||
method: 'POST', | ||
json: false, | ||
body: deployCmd, | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded', | ||
'Accept': 'application/json' } | ||
}, function(err, req, body) { | ||
var jsonBody = (body ? JSON.parse(body) : null); | ||
if (err) { | ||
@@ -149,3 +180,3 @@ done(err); | ||
} | ||
done(); | ||
done(undefined, jsonBody); | ||
} else { | ||
@@ -155,3 +186,3 @@ if (opts.verbose) { | ||
} | ||
var jsonBody = JSON.parse(body); | ||
var errMsg; | ||
@@ -168,16 +199,1 @@ if (jsonBody && (jsonBody.message)) { | ||
} | ||
function displayStatus(opts, request, done) { | ||
if (opts.verbose) { | ||
console.log('Checking deployment status'); | ||
} | ||
var deployOpts = { | ||
organization: opts.organization, | ||
api: opts.api, | ||
username: opts.username, | ||
password: opts.password, | ||
verbose: opts.verbose, | ||
debug: opts.debug | ||
}; | ||
listdeployments.run(deployOpts, done); | ||
} |
@@ -33,3 +33,3 @@ /* jshint node: true */ | ||
name: 'Base URI', | ||
shortOption: 'l' | ||
shortOption: 'L' | ||
}, | ||
@@ -45,2 +45,7 @@ debug: { | ||
toggle: true | ||
}, | ||
json: { | ||
name: 'JSON', | ||
shortOption: 'j', | ||
toggle: true | ||
} | ||
@@ -47,0 +52,0 @@ }; |
@@ -6,4 +6,3 @@ /* jshint node: true */ | ||
var util = require('util'); | ||
var readline = require('readline'); | ||
var tty = require('tty'); | ||
var read = require('read'); | ||
@@ -77,11 +76,4 @@ /* | ||
module.exports.validate = function(opts, descriptor, cb) { | ||
var console; | ||
if (opts.interactive) { | ||
console = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
} | ||
async.eachSeries(Object.getOwnPropertyNames(descriptor), function(item, done) { | ||
checkProperty(opts, descriptor, item, console, done); | ||
checkProperty(opts, descriptor, item, done); | ||
}, function(err) { | ||
@@ -92,8 +84,12 @@ cb(err, opts); | ||
function checkProperty(opts, descriptor, propName, console, done) { | ||
function checkProperty(opts, descriptor, propName, done) { | ||
var desc = descriptor[propName]; | ||
if (!desc) { | ||
done(new Error(util.format('Invalid property %s', propName))); | ||
return; | ||
} | ||
if (desc.required && !opts[propName]) { | ||
if (opts.interactive) { | ||
var pn = (desc.name ? desc.name : propName); | ||
prompt(pn, desc.secure, console, function(err, val) { | ||
prompt(pn, desc.secure, function(err, val) { | ||
if (err) { | ||
@@ -114,6 +110,12 @@ done(err); | ||
function prompt(name, secure, console, cb) { | ||
console.question(util.format('%s: ', name), function(line) { | ||
cb(undefined, line); | ||
}); | ||
function prompt(name, secure, cb) { | ||
var opts = { | ||
prompt: name + ':' | ||
}; | ||
if (secure) { | ||
opts.silent = true; | ||
opts.replace = '*'; | ||
} | ||
read(opts, cb); | ||
} | ||
@@ -120,0 +122,0 @@ |
{ | ||
"name": "apigeetool", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "A CLI for Apigee Edge", | ||
@@ -20,2 +20,3 @@ "main": "lib/main.js", | ||
"async": "0.x.x", | ||
"read": "1.x.x", | ||
"request": "2.x.x", | ||
@@ -22,0 +23,0 @@ "mustache": "x.x.x", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1905
57646
6
+ Addedread@1.x.x
+ Addedmute-stream@0.0.8(transitive)
+ Addedread@1.0.7(transitive)