Skip to content

Commit 6baf582

Browse files
committed
update to v0.2.20
- add apps collection to org object - allow query of developers by id or email - add a new example that exercises the above: findApiKey.js
1 parent a725bcd commit 6baf582

File tree

4 files changed

+111
-6
lines changed

4 files changed

+111
-6
lines changed

examples/findApiKey.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#! /usr/local/bin/node
2+
/*jslint node:true */
3+
// findApiKey.js
4+
// ------------------------------------------------------------------
5+
// find the developer and app name for an API key from an Edge org.
6+
//
7+
// last saved: <2017-December-07 18:40:48>
8+
9+
var edgejs = require('apigee-edge-js'),
10+
common = edgejs.utility,
11+
apigeeEdge = edgejs.edge,
12+
Getopt = require('node-getopt'),
13+
version = '20171207-1827',
14+
getopt = new Getopt(common.commonOptions.concat([
15+
['k' , 'key=ARG', 'the key to find.'],
16+
['T' , 'notoken', 'optional. do not try to get a authentication token.']
17+
])).bindHelp();
18+
19+
function handleError(e) {
20+
if (e) {
21+
console.log(e);
22+
console.log(e.stack);
23+
process.exit(1);
24+
}
25+
}
26+
27+
// ========================================================
28+
29+
console.log(
30+
'Edge API key finder, version: ' + version + '\n' +
31+
'Node.js ' + process.version + '\n');
32+
33+
common.logWrite('start');
34+
35+
// process.argv array starts with 'node' and 'scriptname.js'
36+
var opt = getopt.parse(process.argv.slice(2));
37+
38+
common.verifyCommonRequiredParameters(opt.options, getopt);
39+
40+
if ( !opt.options.key ) {
41+
console.log('You must specify a key to find');
42+
getopt.showHelp();
43+
process.exit(1);
44+
}
45+
46+
var options = {
47+
mgmtServer: opt.options.mgmtserver,
48+
org : opt.options.org,
49+
user: opt.options.username,
50+
password: opt.options.password,
51+
no_token: opt.options.notoken,
52+
verbosity: opt.options.verbose || 0
53+
};
54+
55+
apigeeEdge.connect(options, function(e, org) {
56+
handleError(e);
57+
org.apps.get({expand:true}, function(e, result) {
58+
var found = null;
59+
handleError(e);
60+
result.app.forEach(function(app) {
61+
if ( !found && app.credentials) app.credentials.forEach(function(cred){
62+
if ( !found && cred.consumerKey == opt.options.key) { found = {app:app, cred:cred}; }
63+
});
64+
});
65+
66+
if (found) {
67+
org.developers.get({id:found.app.developerId}, function(e, result) {
68+
common.logWrite('key: ' + opt.options.key);
69+
common.logWrite('app: ' + found.app.name + ' ' + found.app.appId);
70+
common.logWrite('dev: ' + found.app.developerId + ' ' +
71+
result.firstName + ' ' +
72+
result.lastName + ' ' +
73+
result.userName + ' ' +
74+
result.email);
75+
});
76+
}
77+
});
78+
});

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"author": "dchiesa@google.com",
1010
"license": "Apache-2.0",
1111
"dependencies": {
12-
"apigee-edge-js": "^0.2.19",
12+
"apigee-edge-js": "^0.2.20",
1313
"async": "^2.2.0",
1414
"mkdirp": "^0.5.1",
1515
"netrc": "0.1.3",

lib/edge.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// library of functions for Apigee Edge.
55
//
66
// created: Mon Jun 6 17:32:20 2016
7-
// last saved: <2017-December-07 18:22:37>
7+
// last saved: <2017-December-07 18:42:58>
88

99
(function (){
1010
var path = require('path'),
@@ -81,6 +81,7 @@
8181
this.kvms = new Kvm(conn);
8282
this.developers = new Developer(conn);
8383
this.developerapps = new DeveloperApp(conn);
84+
this.apps = new App(conn);
8485
this.sharedflows = new SharedFlow(conn);
8586
this.products = new ApiProduct(conn);
8687
this.appcredentials = new AppCredential(conn);
@@ -1002,9 +1003,34 @@
10021003
Developer.prototype.get = function(options, cb) {
10031004
var conn = this.conn;
10041005
mergeRequestOptions(conn, function(requestOptions) {
1005-
requestOptions.url = (options.developerEmail) ?
1006-
urljoin(conn.urlBase, 'developers', options.developerEmail) :
1007-
urljoin(conn.urlBase, 'developers');
1006+
if (options.developerEmail || options.email) {
1007+
requestOptions.url = urljoin(conn.urlBase, 'developers', options.developerEmail || options.email);
1008+
}
1009+
else if (options.developerId || options.id) {
1010+
requestOptions.url = urljoin(conn.urlBase, 'developers', options.developerId || options.id);
1011+
}
1012+
else {
1013+
requestOptions.url = urljoin(conn.urlBase, 'developers');
1014+
}
1015+
if (conn.verbosity>0) {
1016+
utility.logWrite(sprintf('GET %s', requestOptions.url));
1017+
}
1018+
request.get(requestOptions, commonCallback(conn, [200], cb));
1019+
});
1020+
};
1021+
1022+
function App(conn) {this.conn = conn;}
1023+
1024+
App.prototype.get = function(options, cb) {
1025+
// GET :mgmtserver/v1/o/:orgname/apps
1026+
// or
1027+
// GET :mgmtserver/v1/o/:orgname/apps/ID_OF_APP
1028+
if ( ! cb) { cb = options; options = {}; }
1029+
var conn = this.conn;
1030+
mergeRequestOptions(conn, function(requestOptions) {
1031+
requestOptions.url = (options.id) ?
1032+
urljoin(conn.urlBase, 'apps', options.id) :
1033+
urljoin(conn.urlBase, 'apps') + (options.expand ? '?expand=true' : '');
10081034
if (conn.verbosity>0) {
10091035
utility.logWrite(sprintf('GET %s', requestOptions.url));
10101036
}
@@ -1677,6 +1703,7 @@
16771703
// proxies { get, deploy, undeploy, del, importFromDir, importFromZip }
16781704
// caches { get, create, del }
16791705
// kvms { get, create, put, del }
1706+
// apps { get }
16801707
// sharedflows { deploy, undeploy, importFromDir, importFromZip }
16811708
// products { get, create, del}
16821709
// developers { get, create, del }

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apigee-edge-js",
3-
"version": "0.2.19",
3+
"version": "0.2.20",
44
"description": "Dino's nodejs library for the administration API for Apigee Edge.",
55
"main" : "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)