|
18 | 18 | // limitations under the License.
|
19 | 19 | //
|
20 | 20 | // created: Mon Jun 6 17:32:20 2016
|
21 |
| -// last saved: <2018-February-12 14:25:10> |
| 21 | +// last saved: <2018-February-18 11:00:16> |
22 | 22 |
|
23 | 23 | (function (){
|
24 | 24 | var path = require('path'),
|
|
143 | 143 |
|
144 | 144 | Environment.prototype.getVhosts = function(options, cb) {
|
145 | 145 | var conn = this.conn;
|
146 |
| - if (!options.name ) { |
147 |
| - throw new Error("missing environment name"); |
148 |
| - } |
| 146 | + var name = options.environmentName || options.environment || options.name; |
| 147 | + if (!name) { |
| 148 | + throw new Error("missing environment name"); |
| 149 | + } |
149 | 150 | if (conn.verbosity>0) {
|
150 | 151 | utility.logWrite('get vhosts');
|
151 | 152 | }
|
152 | 153 | mergeRequestOptions(conn, function(requestOptions) {
|
153 | 154 | requestOptions.url = (options.vhost) ?
|
154 |
| - urljoin(conn.urlBase, 'e', options.name, 'virtualhosts', options.vhost): |
155 |
| - urljoin(conn.urlBase, 'e', options.name, 'virtualhosts'); |
| 155 | + urljoin(conn.urlBase, 'e', name, 'virtualhosts', options.vhost): |
| 156 | + urljoin(conn.urlBase, 'e', name, 'virtualhosts'); |
156 | 157 | if (conn.verbosity>0) {
|
157 | 158 | utility.logWrite(sprintf('GET %s', requestOptions.url));
|
158 | 159 | }
|
159 |
| - request.get(requestOptions, commonCallback(conn, [200], function(e, result){ |
160 |
| - cb(e, result); |
161 |
| - })); |
| 160 | + request.get(requestOptions, commonCallback(conn, [200], cb)); |
162 | 161 | });
|
163 | 162 | };
|
164 | 163 |
|
|
774 | 773 | // DELETE :mgmtserver/v1/o/:orgname/e/:envname/apis/:proxyname/revisions/:revnum/deployments
|
775 | 774 | // Authorization: :edge-auth
|
776 | 775 | var collection = getCollectionNameForAssetType(assetType);
|
| 776 | + var rev = options.revision.name || options.revision; |
| 777 | + var env = options.environment.name || options.environment; |
777 | 778 | if (conn.verbosity>0) {
|
778 |
| - utility.logWrite(sprintf('Undeploy %s %s r%d from env:%s', assetType, options.name, options.revision, options.environment)); |
| 779 | + utility.logWrite(sprintf('Undeploy %s %s r%d from env:%s', assetType, options.name, rev, env)); |
779 | 780 | }
|
780 | 781 | mergeRequestOptions(conn, function(requestOptions) {
|
781 | 782 | requestOptions.url = urljoin(conn.urlBase,
|
782 |
| - 'e', options.environment, |
| 783 | + 'e', env, |
783 | 784 | collection, options.name,
|
784 |
| - 'revisions', options.revision, |
| 785 | + 'revisions', rev, |
785 | 786 | 'deployments');
|
786 | 787 | if (conn.verbosity>0) {
|
787 | 788 | utility.logWrite(sprintf('DELETE %s', requestOptions.url));
|
|
1013 | 1014 | // "email": "tet-3a-HiDxfHvHrB@apigee.com"
|
1014 | 1015 | // }
|
1015 | 1016 | var conn = this.conn;
|
1016 |
| - if ( !options.developerEmail || !options.firstName || !options.lastName || !options.userName) { |
1017 |
| - return cb({error: "missing required inputs"}); |
| 1017 | + var email = options.developerEmail || options.email; |
| 1018 | + if ( !email || !options.firstName || !options.lastName || !options.userName) { |
| 1019 | + return cb({error: "missing required inputs, one of {email, firstName, lastName, userName}"}); |
1018 | 1020 | }
|
1019 | 1021 | if (conn.verbosity>0) {
|
1020 |
| - utility.logWrite(sprintf('Create Developer %s', options.developerEmail || 'unknown')); |
| 1022 | + utility.logWrite(sprintf('Create Developer %s', email)); |
1021 | 1023 | }
|
1022 | 1024 | mergeRequestOptions(conn, function(requestOptions) {
|
1023 | 1025 | requestOptions.headers['content-type'] = 'application/json';
|
1024 | 1026 | requestOptions.url = urljoin(conn.urlBase, 'developers');
|
1025 |
| - |
1026 | 1027 | var devAttributes = uglifyAttrs(merge(options.attributes, {
|
1027 |
| - "created by": "apigee-edge-js" |
| 1028 | + "tool": "nodejs " + path.basename(process.argv[1]) |
1028 | 1029 | }));
|
1029 |
| - |
1030 | 1030 | requestOptions.body = JSON.stringify({
|
1031 | 1031 | attributes : devAttributes,
|
1032 | 1032 | userName : options.userName,
|
1033 | 1033 | firstName : options.firstName,
|
1034 | 1034 | lastName : options.lastName,
|
1035 |
| - email: options.developerEmail |
| 1035 | + email: email |
1036 | 1036 | });
|
1037 | 1037 | if (conn.verbosity>0) {
|
1038 | 1038 | utility.logWrite(sprintf('POST %s', requestOptions.url));
|
1039 | 1039 | }
|
| 1040 | + //request.debug = true; |
1040 | 1041 | request.post(requestOptions, commonCallback(conn, [201], cb));
|
1041 | 1042 | });
|
1042 | 1043 | };
|
|
1062 | 1063 |
|
1063 | 1064 | Developer.prototype.get = function(options, cb) {
|
1064 | 1065 | var conn = this.conn;
|
| 1066 | + if ( ! cb) { cb = options; options = {}; } |
1065 | 1067 | mergeRequestOptions(conn, function(requestOptions) {
|
1066 | 1068 | if (options.developerEmail || options.email) {
|
1067 | 1069 | requestOptions.url = urljoin(conn.urlBase, 'developers', options.developerEmail || options.email);
|
|
1098 | 1100 | });
|
1099 | 1101 | };
|
1100 | 1102 |
|
| 1103 | + App.prototype.del = function(options, cb) { |
| 1104 | + // DELETE :mgmtserver/v1/o/:orgname/apps/:appid |
| 1105 | + // Authorization: :edge-auth |
| 1106 | + var conn = this.conn; |
| 1107 | + if (conn.verbosity>0) { |
| 1108 | + utility.logWrite(sprintf('Delete App %s', options.appId || options.id)); |
| 1109 | + } |
| 1110 | + mergeRequestOptions(conn, function(requestOptions) { |
| 1111 | + requestOptions.url = urljoin(conn.urlBase, 'apps', options.appId || option.id); |
| 1112 | + if (conn.verbosity>0) { |
| 1113 | + utility.logWrite(sprintf('DELETE %s', requestOptions.url)); |
| 1114 | + } |
| 1115 | + request.del(requestOptions, commonCallback(conn, [200], cb)); |
| 1116 | + }); |
| 1117 | + }; |
| 1118 | + |
1101 | 1119 | function DeveloperApp(conn) {this.conn = conn;}
|
1102 | 1120 |
|
1103 | 1121 | DeveloperApp.prototype.create = function(options, cb) {
|
|
1116 | 1134 | // "name" : "ElaineApp2"
|
1117 | 1135 | // }
|
1118 | 1136 | var conn = this.conn;
|
| 1137 | + var email = options.developer || options.developerEmail || options.email; |
| 1138 | + var name = options.appName || options.name; |
| 1139 | + if ( !email || !name || !options.apiProduct) { |
| 1140 | + return cb({error: "missing required inputs, one of {developer, appName, apiProduct}"}); |
| 1141 | + } |
1119 | 1142 | if (conn.verbosity>0) {
|
1120 |
| - utility.logWrite(sprintf('Create App %s for %s', options.appName, options.developerEmail)); |
| 1143 | + utility.logWrite(sprintf('Create App %s for %s', name, email)); |
1121 | 1144 | }
|
1122 | 1145 | mergeRequestOptions(conn, function(requestOptions) {
|
1123 | 1146 | requestOptions.headers['content-type'] = 'application/json';
|
1124 |
| - requestOptions.url = urljoin(conn.urlBase, |
1125 |
| - 'developers',options.developerEmail, |
1126 |
| - 'apps'); |
| 1147 | + requestOptions.url = urljoin(conn.urlBase, 'developers', email, 'apps'); |
1127 | 1148 | var DEFAULT_EXPIRY = -1;
|
1128 | 1149 | var keyExpiresIn = DEFAULT_EXPIRY;
|
1129 | 1150 | if (options.expiry) {
|
|
1134 | 1155 | utility.logWrite(sprintf('Using default expiry of %d', keyExpiresIn));
|
1135 | 1156 | }
|
1136 | 1157 | }
|
1137 |
| - |
1138 |
| - var appAttributes = uglifyAttrs(merge(options.attributes, { |
1139 |
| - "created by": "nodejs " + path.basename(process.argv[1]) |
| 1158 | + var appAttributes = uglifyAttrs(merge(options.attributes || {}, { |
| 1159 | + "tool": "nodejs " + path.basename(process.argv[1]) |
1140 | 1160 | }));
|
1141 |
| - |
1142 | 1161 | requestOptions.body = JSON.stringify({
|
1143 | 1162 | attributes : appAttributes,
|
1144 | 1163 | apiProducts: [options.apiProduct],
|
1145 | 1164 | keyExpiresIn : keyExpiresIn,
|
1146 |
| - name: options.appName |
| 1165 | + name: name |
1147 | 1166 | });
|
1148 |
| - |
1149 | 1167 | if (conn.verbosity>0) {
|
1150 | 1168 | utility.logWrite(sprintf('POST %s', requestOptions.url));
|
1151 | 1169 | }
|
| 1170 | + //request.debug = true; |
1152 | 1171 | request.post(requestOptions, commonCallback(conn, [201], cb));
|
1153 | 1172 | });
|
1154 | 1173 | };
|
|
1157 | 1176 | // DELETE :mgmtserver/v1/o/:orgname/developers/:developer/apps/:appname
|
1158 | 1177 | // Authorization: :edge-auth
|
1159 | 1178 | var conn = this.conn;
|
| 1179 | + var name = options.appName || options.name; |
1160 | 1180 | if (conn.verbosity>0) {
|
1161 |
| - utility.logWrite(sprintf('Delete App %s for Developer %s', options.appName, options.developerEmail)); |
| 1181 | + utility.logWrite(sprintf('Delete App %s for Developer %s', name, options.developerEmail)); |
1162 | 1182 | }
|
1163 | 1183 | mergeRequestOptions(conn, function(requestOptions) {
|
1164 |
| - requestOptions.url = urljoin(conn.urlBase, 'developers', options.developerEmail, 'apps', options.appName); |
| 1184 | + requestOptions.url = urljoin(conn.urlBase, 'developers', options.developerEmail, 'apps', name); |
1165 | 1185 | if (conn.verbosity>0) {
|
1166 | 1186 | utility.logWrite(sprintf('DELETE %s', requestOptions.url));
|
1167 | 1187 | }
|
|
1171 | 1191 |
|
1172 | 1192 | DeveloperApp.prototype.get = function(options, cb) {
|
1173 | 1193 | var conn = this.conn;
|
1174 |
| - if (conn.verbosity>0) { |
1175 |
| - utility.logWrite(sprintf('Get Developer App %s/apps/%s', |
1176 |
| - options.developerEmail, |
1177 |
| - options.appName)); |
| 1194 | + var name = options.appName || options.name; |
| 1195 | + var email = options.developerEmail || options.email; |
| 1196 | + if (!email) { |
| 1197 | + throw new Error("missing developer email"); |
1178 | 1198 | }
|
| 1199 | + // if (conn.verbosity>0) { |
| 1200 | + // if (options.appName || options.name) { |
| 1201 | + // utility.logWrite(sprintf('Get Developer App %s/apps/%s', |
| 1202 | + // options.developerEmail, |
| 1203 | + // options.appName)); |
| 1204 | + // } |
| 1205 | + // else { |
| 1206 | + // utility.logWrite(sprintf('Get Developer Apps %s', |
| 1207 | + // options.developerEmail)); |
| 1208 | + // } |
| 1209 | + // } |
1179 | 1210 | mergeRequestOptions(conn, function(requestOptions) {
|
1180 |
| - requestOptions.url = urljoin(conn.urlBase, |
1181 |
| - sprintf('developers/%s/apps/%s', |
1182 |
| - options.developerEmail, |
1183 |
| - options.appName)); |
| 1211 | + requestOptions.url = (options.appName || options.name) ? |
| 1212 | + urljoin(conn.urlBase, 'developers', email, 'apps') : |
| 1213 | + urljoin(conn.urlBase, 'developers', email, 'apps', name); |
1184 | 1214 | if (conn.verbosity>0) {
|
1185 | 1215 | utility.logWrite(sprintf('GET %s', requestOptions.url));
|
1186 | 1216 | }
|
|
1246 | 1276 |
|
1247 | 1277 | function ApiProduct(conn) { this.conn = conn; }
|
1248 | 1278 |
|
1249 |
| - function reallyCreateProduct(conn, options, cb) { |
| 1279 | + ApiProduct.prototype.create = function(options, cb) { |
| 1280 | + // POST :mgmtserver/v1/o/:orgname/apiproducts/:product |
| 1281 | + // Content-Type: application/json |
| 1282 | + // Authorization: :edge-auth |
| 1283 | + // |
| 1284 | + // { |
| 1285 | + // "name" : ":product", |
| 1286 | + // "attributes" : [ {"name": "created by", "value" : "emacs"} ], |
| 1287 | + // "approvalType" : "manual", |
| 1288 | + // "displayName" : ":product", |
| 1289 | + // "proxies" : ["proxy1", "proxy2"], |
| 1290 | + // "scopes" : ["read", "write", "something"], |
| 1291 | + // "environments" : [ "prod" ] |
| 1292 | + // } |
| 1293 | + var conn = this.conn; |
1250 | 1294 | if (conn.verbosity>0) {
|
1251 | 1295 | if (options.proxy) {
|
1252 | 1296 | utility.logWrite(sprintf('Create API Product %s with proxy %s', options.productName, options.proxy));
|
1253 | 1297 | }
|
1254 |
| - else { |
| 1298 | + else if (options.proxies) { |
| 1299 | + utility.logWrite(sprintf('Create API Product %s with proxies %s', options.productName, JSON.stringify(options.proxies))); |
| 1300 | + } else { |
1255 | 1301 | utility.logWrite(sprintf('Create API Product %s with no proxy', options.productName));
|
1256 | 1302 | }
|
1257 | 1303 | }
|
1258 | 1304 | mergeRequestOptions(conn, function(requestOptions) {
|
1259 | 1305 | requestOptions.headers['content-type'] = 'application/json';
|
1260 | 1306 | requestOptions.url = urljoin(conn.urlBase, 'apiproducts');
|
1261 |
| - var prodAttributes = uglifyAttrs(merge(options.attributes, { |
1262 |
| - "created by": "apigee-edge-js" |
| 1307 | + var prodAttributes = uglifyAttrs(merge(options.attributes || {}, { |
| 1308 | + "tool": "nodejs " + path.basename(process.argv[1]) |
1263 | 1309 | }));
|
1264 |
| - |
1265 | 1310 | var rOptions = {
|
1266 |
| - name : options.productName, |
| 1311 | + name : options.productName || options.name, |
1267 | 1312 | proxies : [ ],
|
1268 | 1313 | attributes : prodAttributes,
|
1269 | 1314 | approvalType : options.approvalType || "manual",
|
1270 |
| - displayName : options.productName, |
| 1315 | + displayName : options.displayName || options.productName || options.name, |
1271 | 1316 | environments : options.environments || options.envs,
|
1272 | 1317 | scopes : options.scopes
|
1273 | 1318 | };
|
1274 |
| - |
1275 | 1319 | if (options.proxy) {
|
1276 | 1320 | rOptions.proxies.push(options.proxy);
|
1277 | 1321 | }
|
| 1322 | + else if (options.proxies && Array.isArray(options.proxies) ) { |
| 1323 | + rOptions.proxies = options.proxies; |
| 1324 | + } |
1278 | 1325 | requestOptions.body = JSON.stringify(rOptions);
|
1279 | 1326 |
|
1280 | 1327 | if (conn.verbosity>0) {
|
1281 | 1328 | utility.logWrite(sprintf('POST %s', requestOptions.url));
|
1282 | 1329 | }
|
| 1330 | + // request.debug = true; |
1283 | 1331 | request.post(requestOptions, commonCallback(conn, [201], cb));
|
1284 | 1332 | });
|
1285 |
| - } |
1286 |
| - |
1287 |
| - ApiProduct.prototype.create = function(options, cb) { |
1288 |
| - // POST :mgmtserver/v1/o/:orgname/apiproducts/:product |
1289 |
| - // Content-Type: application/json |
1290 |
| - // Authorization: :edge-auth |
1291 |
| - // |
1292 |
| - // { |
1293 |
| - // "name" : ":product", |
1294 |
| - // "attributes" : [ {"name": "created by", "value" : "emacs"} ], |
1295 |
| - // "approvalType" : "manual", |
1296 |
| - // "displayName" : ":product", |
1297 |
| - // "proxies" : ["proxy1", "proxy2"], |
1298 |
| - // "scopes" : ["read", "write", "something"], |
1299 |
| - // "environments" : [ "prod" ] |
1300 |
| - // } |
1301 |
| - var conn = this.conn; |
1302 |
| - // if ( ! options.envs) { |
1303 |
| - // conn.getEnvironments(function(e, result) { |
1304 |
| - // reallyCreateProduct(conn, merge(options, {envs: result}), cb); |
1305 |
| - // }); |
1306 |
| - // } |
1307 |
| - // else { |
1308 |
| - // reallyCreateProduct(conn, options, cb); |
1309 |
| - // } |
1310 |
| - reallyCreateProduct(conn, options, cb); |
1311 | 1333 | };
|
1312 | 1334 |
|
1313 | 1335 | ApiProduct.prototype.get = function(options, cb) {
|
|
1331 | 1353 | // DELETE :mgmtserver/v1/o/:orgname/apiproducts/:apiproductname
|
1332 | 1354 | // Authorization: :edge-auth
|
1333 | 1355 | var conn = this.conn;
|
| 1356 | + var name = options.productName || options.name; |
1334 | 1357 | if (conn.verbosity>0) {
|
1335 |
| - utility.logWrite(sprintf('Delete API Product %s', options.productName)); |
| 1358 | + utility.logWrite(sprintf('Delete API Product %s', name)); |
1336 | 1359 | }
|
1337 | 1360 | mergeRequestOptions(conn, function(requestOptions) {
|
1338 |
| - requestOptions.url = urljoin(conn.urlBase, 'apiproducts', options.productName); |
| 1361 | + requestOptions.url = urljoin(conn.urlBase, 'apiproducts', name); |
1339 | 1362 | if (conn.verbosity>0) {
|
1340 | 1363 | utility.logWrite(sprintf('DELETE %s', requestOptions.url));
|
1341 | 1364 | }
|
|
0 commit comments