diff --git a/examples/findApiProductForProxy.js b/examples/findApiProductForProxy.js new file mode 100755 index 0000000..7a62bf1 --- /dev/null +++ b/examples/findApiProductForProxy.js @@ -0,0 +1,74 @@ +// findApiProductForProxy.js +// ------------------------------------------------------------------ +// +// created: Mon Mar 20 09:57:02 2017 +// last saved: <2017-December-07 18:19:37> + +var edgejs = require('apigee-edge-js'), + common = edgejs.utility, + apigeeEdge = edgejs.edge, + Getopt = require('node-getopt'), + version = '20171207-1807', + getopt = new Getopt(common.commonOptions.concat([ + ['P' , 'proxy=ARG', 'Required. the proxy to find.'], + ['T' , 'notoken', 'Optional. do not try to obtain a login token.'] + ])).bindHelp(); + +console.log( + 'Apigee Edge findApiProductForProxy.js tool, version: ' + version + '\n' + + 'Node.js ' + process.version + '\n'); + +common.logWrite('start'); + +// process.argv array starts with 'node' and 'scriptname.js' +var opt = getopt.parse(process.argv.slice(2)); + +function handleError(e) { + if (e) { + console.log(e); + console.log(e.stack); + process.exit(1); + } +} +// ======================================================== + +common.verifyCommonRequiredParameters(opt.options, getopt); + +if ( !opt.options.proxy ) { + console.log('You must specify a proxy to find'); + getopt.showHelp(); + process.exit(1); +} + +var options = { + mgmtServer: opt.options.mgmtserver, + org : opt.options.org, + user: opt.options.username, + password: opt.options.password, + no_token: opt.options.notoken, + verbosity: opt.options.verbose || 0 + }; + +apigeeEdge.connect(options, function(e, org) { + handleError(e); + org.products.get({expand:true}, function(e, result) { + handleError(e); + var apiproducts = result.apiProduct; + common.logWrite('total count of API products for that org: %d', apiproducts.length); + var filtered = apiproducts.filter(function(product) { + return (product.proxies.indexOf(opt.options.proxy) >= 0); + }); + + if (filtered) { + common.logWrite('count of API products containing %s: %d', opt.options.proxy, filtered.length); + if (filtered.length) { + common.logWrite(JSON.stringify(filtered.map( function(item) { return item.name;}), null, 2)); + + } + if ( opt.options.verbose ) { + common.logWrite(JSON.stringify(filtered, null, 2)); + } + } + + }); +}); diff --git a/examples/findJavaPolicies.js b/examples/findJavaPolicies.js index 214914d..d7739c2 100755 --- a/examples/findJavaPolicies.js +++ b/examples/findJavaPolicies.js @@ -7,10 +7,9 @@ // // This tool does not examine environment-wide or organization-wide resources. // -// last saved: <2017-December-07 17:55:02> +// last saved: <2017-December-07 18:06:43> -var fs = require('fs'), - async = require('async'), +var async = require('async'), edgejs = require('apigee-edge-js'), common = edgejs.utility, apigeeEdge = edgejs.edge, diff --git a/examples/package.json b/examples/package.json index 5cea3eb..4ac65f3 100644 --- a/examples/package.json +++ b/examples/package.json @@ -9,7 +9,7 @@ "author": "dchiesa@google.com", "license": "Apache-2.0", "dependencies": { - "apigee-edge-js": "^0.2.18", + "apigee-edge-js": "^0.2.19", "async": "^2.2.0", "mkdirp": "^0.5.1", "netrc": "0.1.3", diff --git a/lib/edge.js b/lib/edge.js index b096eaa..98df925 100644 --- a/lib/edge.js +++ b/lib/edge.js @@ -4,7 +4,7 @@ // library of functions for Apigee Edge. // // created: Mon Jun 6 17:32:20 2016 -// last saved: <2017-November-08 18:20:22> +// last saved: <2017-December-07 18:22:37> (function (){ var path = require('path'), @@ -1233,7 +1233,7 @@ mergeRequestOptions(conn, function(requestOptions) { requestOptions.url = (options.name) ? urljoin(conn.urlBase, 'apiproducts', options.name) : - urljoin(conn.urlBase, 'apiproducts') ; + urljoin(conn.urlBase, 'apiproducts') + (options.expand ? '?expand=true' : ''); if (conn.verbosity>0) { utility.logWrite(sprintf('GET %s', requestOptions.url)); } diff --git a/package.json b/package.json index f024e7f..94725c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apigee-edge-js", - "version": "0.2.18", + "version": "0.2.19", "description": "Dino's nodejs library for the administration API for Apigee Edge.", "main" : "index.js", "scripts": {