Skip to content

Commit

Permalink
update to v0.2.20
Browse files Browse the repository at this point in the history
 - add apps collection to org object
 - allow query of developers by id or email
 - add a new example that exercises the above: findApiKey.js
  • Loading branch information
DinoChiesa committed Dec 8, 2017
1 parent a725bcd commit 6baf582
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
78 changes: 78 additions & 0 deletions examples/findApiKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#! /usr/local/bin/node
/*jslint node:true */
// findApiKey.js
// ------------------------------------------------------------------
// find the developer and app name for an API key from an Edge org.
//
// last saved: <2017-December-07 18:40:48>

var edgejs = require('apigee-edge-js'),
common = edgejs.utility,
apigeeEdge = edgejs.edge,
Getopt = require('node-getopt'),
version = '20171207-1827',
getopt = new Getopt(common.commonOptions.concat([
['k' , 'key=ARG', 'the key to find.'],
['T' , 'notoken', 'optional. do not try to get a authentication token.']
])).bindHelp();

function handleError(e) {
if (e) {
console.log(e);
console.log(e.stack);
process.exit(1);
}
}

// ========================================================

console.log(
'Edge API key finder, 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));

common.verifyCommonRequiredParameters(opt.options, getopt);

if ( !opt.options.key ) {
console.log('You must specify a key 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.apps.get({expand:true}, function(e, result) {
var found = null;
handleError(e);
result.app.forEach(function(app) {
if ( !found && app.credentials) app.credentials.forEach(function(cred){
if ( !found && cred.consumerKey == opt.options.key) { found = {app:app, cred:cred}; }
});
});

if (found) {
org.developers.get({id:found.app.developerId}, function(e, result) {
common.logWrite('key: ' + opt.options.key);
common.logWrite('app: ' + found.app.name + ' ' + found.app.appId);
common.logWrite('dev: ' + found.app.developerId + ' ' +
result.firstName + ' ' +
result.lastName + ' ' +
result.userName + ' ' +
result.email);
});
}
});
});
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "dchiesa@google.com",
"license": "Apache-2.0",
"dependencies": {
"apigee-edge-js": "^0.2.19",
"apigee-edge-js": "^0.2.20",
"async": "^2.2.0",
"mkdirp": "^0.5.1",
"netrc": "0.1.3",
Expand Down
35 changes: 31 additions & 4 deletions lib/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// library of functions for Apigee Edge.
//
// created: Mon Jun 6 17:32:20 2016
// last saved: <2017-December-07 18:22:37>
// last saved: <2017-December-07 18:42:58>

(function (){
var path = require('path'),
Expand Down Expand Up @@ -81,6 +81,7 @@
this.kvms = new Kvm(conn);
this.developers = new Developer(conn);
this.developerapps = new DeveloperApp(conn);
this.apps = new App(conn);
this.sharedflows = new SharedFlow(conn);
this.products = new ApiProduct(conn);
this.appcredentials = new AppCredential(conn);
Expand Down Expand Up @@ -1002,9 +1003,34 @@
Developer.prototype.get = function(options, cb) {
var conn = this.conn;
mergeRequestOptions(conn, function(requestOptions) {
requestOptions.url = (options.developerEmail) ?
urljoin(conn.urlBase, 'developers', options.developerEmail) :
urljoin(conn.urlBase, 'developers');
if (options.developerEmail || options.email) {
requestOptions.url = urljoin(conn.urlBase, 'developers', options.developerEmail || options.email);
}
else if (options.developerId || options.id) {
requestOptions.url = urljoin(conn.urlBase, 'developers', options.developerId || options.id);
}
else {
requestOptions.url = urljoin(conn.urlBase, 'developers');
}
if (conn.verbosity>0) {
utility.logWrite(sprintf('GET %s', requestOptions.url));
}
request.get(requestOptions, commonCallback(conn, [200], cb));
});
};

function App(conn) {this.conn = conn;}

App.prototype.get = function(options, cb) {
// GET :mgmtserver/v1/o/:orgname/apps
// or
// GET :mgmtserver/v1/o/:orgname/apps/ID_OF_APP
if ( ! cb) { cb = options; options = {}; }
var conn = this.conn;
mergeRequestOptions(conn, function(requestOptions) {
requestOptions.url = (options.id) ?
urljoin(conn.urlBase, 'apps', options.id) :
urljoin(conn.urlBase, 'apps') + (options.expand ? '?expand=true' : '');
if (conn.verbosity>0) {
utility.logWrite(sprintf('GET %s', requestOptions.url));
}
Expand Down Expand Up @@ -1677,6 +1703,7 @@
// proxies { get, deploy, undeploy, del, importFromDir, importFromZip }
// caches { get, create, del }
// kvms { get, create, put, del }
// apps { get }
// sharedflows { deploy, undeploy, importFromDir, importFromZip }
// products { get, create, del}
// developers { get, create, del }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apigee-edge-js",
"version": "0.2.19",
"version": "0.2.20",
"description": "Dino's nodejs library for the administration API for Apigee Edge.",
"main" : "index.js",
"scripts": {
Expand Down

0 comments on commit 6baf582

Please sign in to comment.