diff --git a/.gitignore b/.gitignore
index 8946080..6bbc147 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
node_modules
+remotetests/testconfig.js
testdir.zip
test.zip
-*.tgz
\ No newline at end of file
+*.tgz
diff --git a/README.md b/README.md
index 83ccf51..6a3552b 100644
--- a/README.md
+++ b/README.md
@@ -21,12 +21,12 @@ This is a tool for deploying API proxies and Node.js applications to the Apigee
You must have an account on Apigee Edge to perform any `apigeetool` functions. These functions include:
-* deploying an API proxy to Edge,
-* undeploying an API proxy from Edge,
+* deploying an API proxy or shared flow to Edge,
+* undeploying an API proxy or shared flow from Edge,
* deploying Node.js apps to Edge,
-* listing deployed API proxies on Edge,
-* retrieving deployed proxies and apps from Edge,
-* deleting proxy definitions from Edge, and
+* listing deployed API proxies or shared flows on Edge,
+* retrieving deployed proxies or shared flows from Edge,
+* deleting proxy or shared flow definitions from Edge, and
* retreiving log messages from Node.js apps deployed to Edge.
* create or delete an API product in Edge
* create or delete a Developer in Edge
@@ -34,6 +34,10 @@ You must have an account on Apigee Edge to perform any `apigeetool` functions. T
* create or delete a Cache resource in Edge
* create, retrieve or delete a KVM Map in Edge
* create, retrieve or delete a KVM Entry in Edge
+* attach, detach, or get a FlowHook
+* list, create, get, delete Roles
+* assign, remove, verify Users for a Role
+* get all Users in a Role
You need to be familiar with basic concepts and features of Apigee Edge such as API proxies, organizations, and environments.
@@ -70,9 +74,6 @@ trusted TLS certificate.
(optional) Limit for the maximum number of operations performed concurrently.
Currently this only affects file uploads in the `deploynodeapp` command. Defaults to 4.
-`--json -j`
-(optional) Formats the command's response as a JSON object.
-
`--organization -o`
(required) The name of the organization to deploy to. May be set as an environment variable APIGEE_ORGANIZATION.
@@ -93,37 +94,51 @@ Currently this only affects file uploads in the `deploynodeapp` command. Default
# Command reference and examples
-* [deploynodeapp](#deploynodeapp)
-* [deployhostedtarget](#deployhostedtarget)
-* [deployproxy](#deployproxy)
-* [undeploy](#undeploy)
-* [listdeployments](#listdeployments)
-* [fetchproxy](#fetchproxy)
-* [getlogs](#getlogs)
-* [delete](#delete)
-* [deploySharedflow](#deploySharedflow)
-* [undeploySharedflow](#undeploySharedflow)
-* [listSharedflowDeployments](#listSharedflowDeployments)
-* [fetchSharedflow](#fetchSharedflow)
-* [deleteSharedflow](#deleteSharedflow)
-* [createdeveloper](#createdeveloper)
-* [deletedeveloper](#deletedeveloper)
-* [createproduct](#createproduct)
-* [deleteproduct](#deleteproduct)
-* [createapp](#createapp)
-* [deleteapp](#deleteapp)
+* [addEntryToKVM](#addEntryToKVM)
+* [assignUserRole](#assignUserRole)
+* [attachFlowHook](#attachFlowHook)
* [createappkey](#createappkey)
+* [createapp](#createapp)
* [createcache](#createcache)
+* [createdeveloper](#createdeveloper)
+* [createKVMmap](#createKVMmap)
+* [createProduct](#createproduct)
+* [createRole](#createRole)
+* [createTargetServer](#createTargetServer)
+* [deleteapp](#deleteapp)
* [deletecache](#deletecache)
-* [createkvmmap](#createkvmmap)
-* [addEntryToKVM](#addEntryToKVM)
-* [getkvmmap](#getkvmmap)
-* [getKVMentry](#getKVMentry)
-* [deletekvmmap](#deletekvmmap)
+* [deletedeveloper](#deletedeveloper)
* [deleteKVMentry](#deleteKVMentry)
-* [createTargetServer](#createTargetServer)
+* [deleteKVMmap](#deleteKVMmap)
+* [deleteproduct](#deleteproduct)
+* [deleteRole](#deleteRole)
+* [deleteSharedflow](#deleteSharedflow)
* [deleteTargetServer](#deleteTargetServer)
-
+* [delete](#delete)
+* [deployhostedtarget](#deployhostedtarget)
+* [deploynodeapp](#deploynodeapp)
+* [deployproxy](#deployproxy)
+* [deploySharedflow](#deploySharedflow)
+* [detachFlowHook](#detachFlowHook)
+* [fetchproxy](#fetchproxy)
+* [fetchSharedflow](#fetchSharedflow)
+* [getFlowHook](#getFlowHook)
+* [getKVMentry](#getKVMentry)
+* [getKVMmap](#getKVMmap)
+* [getlogs](#getlogs)
+* [getRoles](#getRoles)
+* [getRole](#getRole)
+* [getRolePermissions](#getRolePermissions)
+* [getRoleUsers](#getRoleUsers)
+* [getTargetServer](#getTargetServer)
+* [listdeployments](#listdeployments)
+* [listSharedflowDeployments](#listSharedflowDeployments)
+* [listTargetServers](#listTargetServers)
+* [removeUserRole](#removeUserRole)
+* [setRolePermissions](#setRolePermissions)
+* [undeploySharedflow](#undeploySharedflow)
+* [undeploy](#undeploy)
+* [verifyUserRole](#verifyUserRole)
## deploynodeapp
@@ -701,14 +716,14 @@ When the `--organization` and `--environment` options are present, the operation
When the `--organization` and `--api` options are present, the operation will correspond to the API-scoped KVM.
-### createkvmmap
+### createKVMmap
Creates a map in the Apigee KVM with the given name.
#### Example
Create KVM map named "test-map"
- apigeetool createkvmmap -u sdoe@example.com -o sdoe -e test --mapName test-map
+ apigeetool createKVMmap -u sdoe@example.com -o sdoe -e test --mapName test-map
#### Required parameters
@@ -771,7 +786,7 @@ for organization name, all of which are required.
`--api -n`
(optional) The API to target for an API-scoped KVM operation.
-### getkvmmap
+### getKVMmap
Retrieves an entire KVM map with all of its entries, by name.
@@ -779,7 +794,7 @@ Retrieves an entire KVM map with all of its entries, by name.
Get map named "test-map".
- apigeetool getkvmmap -u sdoe@example.com -o sdoe -e test --mapName test-map
+ apigeetool getKVMmap -u sdoe@example.com -o sdoe -e test --mapName test-map
#### Required parameters
@@ -836,7 +851,7 @@ for organization name, all of which are required.
`--api -n`
(optional) The API to target for an API-scoped KVM operation.
-### deletekvmmap
+### deleteKVMmap
Deletes an entire map from the Apigee KVM along with all of its entries.
@@ -844,7 +859,7 @@ Deletes an entire map from the Apigee KVM along with all of its entries.
Delete map named "test-map".
- apigeetool deletekvmmap -u sdoe@example.com -o sdoe -e test --mapName test-map
+ apigeetool deleteKVMmap -u sdoe@example.com -o sdoe -e test --mapName test-map
#### Required parameters
@@ -875,7 +890,7 @@ Deletes a single entry by name from an Apigee KVM map.
Delete entry named "test1" from the map named "test-map".
- apigeetool deletekvmmap -u sdoe@example.com -o sdoe -e test --mapName test-map --entryName test1
+ apigeetool deleteKVMmmap -u sdoe@example.com -o sdoe -e test --mapName test-map --entryName test1
#### Required parameters
@@ -1046,7 +1061,7 @@ Delete a Developer in Edge
//developer delete failed
}) ;
-## Create Product
+## Create Product
Creates a new API Product in Edge
diff --git a/lib/cli.js b/lib/cli.js
index 4c48857..888d756 100755
--- a/lib/cli.js
+++ b/lib/cli.js
@@ -64,11 +64,11 @@ function runCommand() {
}
process.exit(6);
}
- if (!opts.json && commandModule.format) {
- console.log(commandModule.format(result));
- } else {
- console.log(JSON.stringify(result));
- }
+
+ console.log(JSON.stringify(result));
+ // Raw
+ // console.log(result);
+
process.exit(0);
});
}
diff --git a/lib/commands/assignUserRole.js b/lib/commands/assignUserRole.js
new file mode 100644
index 0000000..014aced
--- /dev/null
+++ b/lib/commands/assignUserRole.js
@@ -0,0 +1,41 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ },
+ email: {
+ name: 'Developer email',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('assignUserRole: %j', opts);
+ }
+
+ var formData = util.format('id=%s', encodeURIComponent(opts.email));
+ var uri = util.format('%s/v1/o/%s/userroles/%s/users', opts.baseuri, opts.organization, opts.roleName);
+ var requestOptions = {
+ uri: uri,
+ method:'POST',
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
+ body: formData,
+ json:true
+ }
+ command_utils.run('assignUserRole', opts,requestOptions,cb)
+};
diff --git a/lib/commands/attachFlowHook.js b/lib/commands/attachFlowHook.js
new file mode 100644
index 0000000..14cd3d9
--- /dev/null
+++ b/lib/commands/attachFlowHook.js
@@ -0,0 +1,51 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ environment: {
+ name: 'Environment',
+ shortOption: 'e',
+ required: true
+ },
+ flowHookName: {
+ name: 'Flow hook name',
+ required: true,
+ prompt: true
+ },
+ sharedFlowName: {
+ name: 'Shared Flow name',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('attachFlowHook: %j', opts);
+ }
+ var payload = {
+ "continueOnError" : true,
+ "sharedFlow" : opts.sharedFlowName
+ }
+ if(opts.targetSSL){
+ payload.sSLInfo = {enabled: true}
+ }
+
+ var uri = util.format('%s/v1/o/%s/e/%s/flowhooks/%s', opts.baseuri, opts.organization, opts.environment, opts.flowHookName);
+ var requestOpts = {
+ uri: uri,
+ method:'POST',
+ body: payload,
+ json:true
+ }
+ command_utils.run('attachFlowHook',opts, requestOpts, cb)
+};
diff --git a/lib/commands/command-utils.js b/lib/commands/command-utils.js
index e999af4..c8ef829 100644
--- a/lib/commands/command-utils.js
+++ b/lib/commands/command-utils.js
@@ -11,7 +11,7 @@ module.exports.run = function(command, opts, requestOpts,done){
var jsonBody = body
if(err){
done(err)
- }else if (res.statusCode == 200 || res.statusCode == 201) {
+ }else if (res.statusCode == 200 || res.statusCode == 201 || res.statusCode == 204) {
if (opts.verbose) {
console.log(command + ' successful');
}
diff --git a/lib/commands/commands.js b/lib/commands/commands.js
index 35dd8b7..92e5f9a 100644
--- a/lib/commands/commands.js
+++ b/lib/commands/commands.js
@@ -7,12 +7,42 @@ var Table = require('cli-table');
var options = require('../options');
var Commands = {
+ attachFlowHook: {
+ description: 'Attach a Shared Flow to a Flow Hook',
+ load: function() {
+ return require('./attachFlowHook');
+ }
+ },
+ detachFlowHook: {
+ description: 'Detach a Shared Flow from a Flow Hook',
+ load: function() {
+ return require('./detachFlowHook');
+ }
+ },
+ getFlowHook: {
+ description: 'Get the Shared Flow attached to a Flow Hook',
+ load: function() {
+ return require('./getFlowHook');
+ }
+ },
+ listTargetServers: {
+ description: 'List Target Servers',
+ load: function() {
+ return require('./list-TargetServers');
+ }
+ },
createTargetServer: {
description: 'Create a Target Server',
load: function() {
return require('./create-TargetServer');
}
},
+ getTargetServer: {
+ description: 'Get a Target Server',
+ load: function() {
+ return require('./get-TargetServer');
+ }
+ },
deleteTargetServer: {
description: 'Delete a Target Server',
load: function() {
@@ -186,6 +216,66 @@ var Commands = {
load: function () {
return require('./deployExistingRevision');
}
+ },
+ getRoles: {
+ description: "Get list of roles in an organziation",
+ load: function () {
+ return require('./getRoles');
+ }
+ },
+ createRole: {
+ description: "Create a userrole in an organziation",
+ load: function () {
+ return require('./createRole');
+ }
+ },
+ getRole: {
+ description: "Get a userrole in an organziation",
+ load: function () {
+ return require('./getRole');
+ }
+ },
+ deleteRole: {
+ description: "Delete a userrole in an organziation",
+ load: function () {
+ return require('./deleteRole');
+ }
+ },
+ getRolePermissions: {
+ description: "Get resource permissions for a role",
+ load: function () {
+ return require('./getRolePermissions');
+ }
+ },
+ setRolePermissions: {
+ description: "Set resource permissions for a role",
+ load: function () {
+ return require('./setRolePermissions');
+ }
+ },
+ assignUserRole: {
+ description: "Assign user to a role",
+ load: function () {
+ return require('./assignUserRole');
+ }
+ },
+ removeUserRole: {
+ description: "Remove user from a role",
+ load: function () {
+ return require('./removeUserRole');
+ }
+ },
+ verifyUserRole: {
+ description: "Verify a user is in a role",
+ load: function () {
+ return require('./verifyUserRole');
+ }
+ },
+ getRoleUsers: {
+ description: "Get users in role",
+ load: function () {
+ return require('./getRoleUsers');
+ }
}
};
diff --git a/lib/commands/create-TargetServer.js b/lib/commands/create-TargetServer.js
index cfa8c6f..6996552 100644
--- a/lib/commands/create-TargetServer.js
+++ b/lib/commands/create-TargetServer.js
@@ -16,18 +16,21 @@ var descriptor = defaults.defaultDescriptor({
},
targetServerName: {
name: 'Target Server Name',
- required: true
+ required: true,
+ prompt: true
},
targetHost: {
name: 'Target Host',
- required: true
+ required: true,
+ prompt: true
},
targetEnabled: {
name: 'Target Enabled'
},
targetPort: {
name: 'Target Port',
- required: true
+ required: true,
+ prompt: true
},
targetSSL:{
name: 'SSL Info'
diff --git a/lib/commands/createRole.js b/lib/commands/createRole.js
new file mode 100644
index 0000000..fe56346
--- /dev/null
+++ b/lib/commands/createRole.js
@@ -0,0 +1,39 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('createRole: %j', opts);
+ }
+ var payload = {
+ "role" : [
+ {"name" : opts.roleName}
+ ]
+ };
+
+ var uri = util.format('%s/v1/o/%s/userroles', opts.baseuri, opts.organization);
+ var requestOptions = {
+ uri: uri,
+ method:'POST',
+ body: payload,
+ json:true
+ }
+ command_utils.run('createRole', opts,requestOptions,cb)
+};
diff --git a/lib/commands/delete-TargetServer.js b/lib/commands/delete-TargetServer.js
index 35751ea..5e273e5 100644
--- a/lib/commands/delete-TargetServer.js
+++ b/lib/commands/delete-TargetServer.js
@@ -16,7 +16,8 @@ var descriptor = defaults.defaultDescriptor({
},
targetServerName: {
name: 'Target Server Name',
- required: true
+ required: true,
+ prompt: true
}
});
@@ -30,7 +31,7 @@ module.exports.run = function(opts, cb) {
var requestOptions = {
uri: uri,
method:'DELETE',
- json:false
+ json:true
}
command_utils.run('deleteTargetServer', opts,requestOptions,cb)
};
diff --git a/lib/commands/deleteRole.js b/lib/commands/deleteRole.js
new file mode 100644
index 0000000..99623ba
--- /dev/null
+++ b/lib/commands/deleteRole.js
@@ -0,0 +1,32 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('deleteRole: %j', opts);
+ }
+ var uri = util.format('%s/v1/o/%s/userroles/%s', opts.baseuri, opts.organization, opts.roleName);
+ var requestOptions = {
+ uri: uri,
+ method:'DELETE',
+ json:true
+ }
+ command_utils.run('deleteRole', opts,requestOptions,cb)
+};
diff --git a/lib/commands/detachFlowHook.js b/lib/commands/detachFlowHook.js
new file mode 100644
index 0000000..f31e5e6
--- /dev/null
+++ b/lib/commands/detachFlowHook.js
@@ -0,0 +1,40 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ environment: {
+ name: 'Environment',
+ shortOption: 'e',
+ required: true
+ },
+ flowHookName: {
+ name: 'Flow hook name',
+ required: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('detachFlowHook: %j', opts);
+ }
+ if(opts.targetSSL){
+ payload.sSLInfo = {enabled: true}
+ }
+
+ var uri = util.format('%s/v1/o/%s/e/%s/flowhooks/%s', opts.baseuri, opts.organization, opts.environment, opts.flowHookName);
+ var requestOpts = {
+ uri: uri,
+ method:'DELETE',
+ json:true
+ }
+ command_utils.run('detachFlowHook',opts, requestOpts, cb)
+};
diff --git a/lib/commands/fetchproxy.js b/lib/commands/fetchproxy.js
index 65b996a..ec982d7 100644
--- a/lib/commands/fetchproxy.js
+++ b/lib/commands/fetchproxy.js
@@ -69,7 +69,7 @@ module.exports.run = function(opts, cb) {
console.log( "Error text: " + err );
}
else {
- console.log( 'Save file: ' + f );
+ if (opts.verbose) { console.log('Save file: ' + f); }
}
cb(err);
});
diff --git a/lib/commands/fetchsharedflow.js b/lib/commands/fetchsharedflow.js
index be7746f..73578ac 100644
--- a/lib/commands/fetchsharedflow.js
+++ b/lib/commands/fetchsharedflow.js
@@ -71,7 +71,7 @@ module.exports.run = function (opts, cb) {
console.log("Error text: " + err);
}
else {
- console.log('Save file: ' + f);
+ if (opts.verbose) { console.log('Save file: ' + f); }
}
cb(err);
});
diff --git a/lib/commands/get-TargetServer.js b/lib/commands/get-TargetServer.js
new file mode 100644
index 0000000..03ddd63
--- /dev/null
+++ b/lib/commands/get-TargetServer.js
@@ -0,0 +1,38 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ environment: {
+ name: 'Environment',
+ shortOption: 'e',
+ required: true,
+ prompt: true
+ },
+ targetServerName: {
+ name: 'Target Server Name',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('getTargetServer: %j', opts);
+ }
+ var uri = util.format('%s/v1/o/%s/e/%s/targetservers/%s', opts.baseuri, opts.organization, opts.environment,opts.targetServerName);
+ var requestOptions = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('getTargetServer', opts,requestOptions,cb)
+};
diff --git a/lib/commands/getFlowHook.js b/lib/commands/getFlowHook.js
new file mode 100644
index 0000000..d8e6696
--- /dev/null
+++ b/lib/commands/getFlowHook.js
@@ -0,0 +1,40 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ environment: {
+ name: 'Environment',
+ shortOption: 'e',
+ required: true
+ },
+ flowHookName: {
+ name: 'Flow hook name',
+ required: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('getFlowHook: %j', opts);
+ }
+ if(opts.targetSSL){
+ payload.sSLInfo = {enabled: true}
+ }
+
+ var uri = util.format('%s/v1/o/%s/e/%s/flowhooks/%s', opts.baseuri, opts.organization, opts.environment, opts.flowHookName);
+ var requestOpts = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('getFlowHook',opts, requestOpts, cb)
+};
diff --git a/lib/commands/getRole.js b/lib/commands/getRole.js
new file mode 100644
index 0000000..8c9b4cc
--- /dev/null
+++ b/lib/commands/getRole.js
@@ -0,0 +1,32 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('getRole: %j', opts);
+ }
+ var uri = util.format('%s/v1/o/%s/userroles/%s', opts.baseuri, opts.organization, opts.roleName);
+ var requestOptions = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('getRole', opts,requestOptions,cb)
+};
diff --git a/lib/commands/getRolePermissions.js b/lib/commands/getRolePermissions.js
new file mode 100644
index 0000000..86cdb2c
--- /dev/null
+++ b/lib/commands/getRolePermissions.js
@@ -0,0 +1,32 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('getRolePermissions: %j', opts);
+ }
+ var uri = util.format('%s/v1/o/%s/userroles/%s/permissions', opts.baseuri, opts.organization, opts.roleName);
+ var requestOptions = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('getRolePermissions', opts,requestOptions,cb)
+};
diff --git a/lib/commands/getRoleUsers.js b/lib/commands/getRoleUsers.js
new file mode 100644
index 0000000..10e760b
--- /dev/null
+++ b/lib/commands/getRoleUsers.js
@@ -0,0 +1,33 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('getRoleUsers: %j', opts);
+ }
+
+ var uri = util.format('%s/v1/o/%s/userroles/%s/users', opts.baseuri, opts.organization, opts.roleName);
+ var requestOptions = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('getRoleUsers', opts,requestOptions,cb)
+};
diff --git a/lib/commands/getRoles.js b/lib/commands/getRoles.js
new file mode 100644
index 0000000..0765301
--- /dev/null
+++ b/lib/commands/getRoles.js
@@ -0,0 +1,27 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('getRoles: %j', opts);
+ }
+ var uri = util.format('%s/v1/o/%s/userroles', opts.baseuri, opts.organization);
+ var requestOptions = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('getRoles', opts,requestOptions,cb)
+};
diff --git a/lib/commands/list-TargetServers.js b/lib/commands/list-TargetServers.js
new file mode 100644
index 0000000..fe53bdc
--- /dev/null
+++ b/lib/commands/list-TargetServers.js
@@ -0,0 +1,32 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ environment: {
+ name: 'Environment',
+ shortOption: 'e',
+ required: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('listTargetServers: %j', opts);
+ }
+ var uri = util.format('%s/v1/o/%s/e/%s/targetservers', opts.baseuri, opts.organization, opts.environment);
+ var requestOptions = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('listTargetServers', opts,requestOptions,cb)
+};
diff --git a/lib/commands/listsharedflowdeployments.js b/lib/commands/listsharedflowdeployments.js
index 4ed009e..67c6234 100644
--- a/lib/commands/listsharedflowdeployments.js
+++ b/lib/commands/listsharedflowdeployments.js
@@ -17,10 +17,6 @@ var descriptor = defaults.defaultDescriptor({
name: 'Environment',
shortOption: 'e'
},
- revision: {
- name: 'Revision',
- shortOption: 'r'
- },
long: {
name: 'Long',
shortOption: 'l',
diff --git a/lib/commands/removeUserRole.js b/lib/commands/removeUserRole.js
new file mode 100644
index 0000000..2fcff92
--- /dev/null
+++ b/lib/commands/removeUserRole.js
@@ -0,0 +1,38 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ },
+ email: {
+ name: 'Developer email',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('removeUserRole: %j', opts);
+ }
+
+ var uri = util.format('%s/v1/o/%s/userroles/%s/users/%s', opts.baseuri, opts.organization, opts.roleName, opts.email );
+ var requestOptions = {
+ uri: uri,
+ method:'DELETE',
+ json:true
+ }
+ command_utils.run('removeUserRole', opts,requestOptions,cb)
+};
diff --git a/lib/commands/setRolePermissions.js b/lib/commands/setRolePermissions.js
new file mode 100644
index 0000000..79f47aa
--- /dev/null
+++ b/lib/commands/setRolePermissions.js
@@ -0,0 +1,45 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ },
+ permissions: {
+ name: 'Permissions array for path and verbs',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('setRolePermissions: %j', opts);
+ }
+
+ if( opts.permissions ) {
+ var permissions = JSON.parse(opts.permissions);
+ }
+ var payload = {
+ "resourcePermission" : permissions
+ };
+ var uri = util.format('%s/v1/o/%s/userroles/%s/resourcepermissions', opts.baseuri, opts.organization, opts.roleName);
+ var requestOptions = {
+ uri: uri,
+ method:'POST',
+ body: payload,
+ json:true
+ }
+ command_utils.run('setRolePermissions', opts,requestOptions,cb)
+};
diff --git a/lib/commands/verifyUserRole.js b/lib/commands/verifyUserRole.js
new file mode 100644
index 0000000..a960f66
--- /dev/null
+++ b/lib/commands/verifyUserRole.js
@@ -0,0 +1,38 @@
+/* jshint node: true */
+'use strict';
+
+var util = require('util');
+var _ = require('underscore');
+
+var defaults = require('../defaults');
+var options = require('../options');
+var command_utils = require('./command-utils')
+
+var descriptor = defaults.defaultDescriptor({
+ roleName: {
+ name: 'Role Name',
+ required: true,
+ prompt: true
+ },
+ email: {
+ name: 'EMail for the user',
+ required: true,
+ prompt: true
+ }
+});
+
+module.exports.descriptor = descriptor;
+
+module.exports.run = function(opts, cb) {
+ if (opts.debug) {
+ console.log('verifyUserRole: %j', opts);
+ }
+
+ var uri = util.format('%s/v1/o/%s/userroles/%s/users/%s', opts.baseuri, opts.organization, opts.roleName, opts.email );
+ var requestOptions = {
+ uri: uri,
+ method:'GET',
+ json:true
+ }
+ command_utils.run('verifyUserRole', opts,requestOptions,cb)
+};
diff --git a/lib/defaults.js b/lib/defaults.js
index 1843765..c25a082 100644
--- a/lib/defaults.js
+++ b/lib/defaults.js
@@ -14,17 +14,20 @@ var DefaultDescriptor = {
help: {
name: 'Help',
shortOption: 'h',
+ scope: 'default',
toggle: true
},
username: {
name: 'Username',
shortOption: 'u',
+ scope: 'default',
required: true,
prompt: true
},
password: {
name: 'Password',
shortOption: 'p',
+ scope: 'default',
required: true,
prompt: true,
secure: true
@@ -32,6 +35,7 @@ var DefaultDescriptor = {
header: {
name: 'Header',
shortOption: 'H',
+ scope: 'default',
required: false,
prompt: false,
multiple: true
@@ -39,51 +43,55 @@ var DefaultDescriptor = {
token: {
name: 'Token',
shortOption: 't',
- required: true,
+ scope: 'default',
+ required: false,
prompt: false
},
netrc: {
name: 'netrc',
shortOption: 'N',
+ scope: 'default',
required: false,
toggle: true
},
organization: {
name: 'Organization',
shortOption: 'o',
+ scope: 'default',
required: true
},
baseuri: {
name: 'Base URI',
- shortOption: 'L'
+ shortOption: 'L',
+ scope: 'default'
},
debug: {
name: 'Debug',
shortOption: 'D',
- toggle: true
+ scope: 'default',
+ toggle: true,
},
verbose: {
name: 'Verbose',
shortOption: 'V',
- toggle: true
- },
- json: {
- name: 'JSON',
- shortOption: 'j',
+ scope: 'default',
toggle: true
},
cafile: {
name: 'CA file',
- shortOption: 'c'
+ shortOption: 'c',
+ scope: 'default'
},
insecure: {
name: 'insecure',
shortOption: 'k',
+ scope: 'default',
toggle: true
},
asynclimit: {
name: 'Async limit',
shortOption: 'a',
+ scope: 'default',
type: 'int'
}
};
diff --git a/lib/main.js b/lib/main.js
index 82d89b6..78d9924 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -98,11 +98,21 @@ ApigeeTool.deleteApp = function(opts,cb){
runCommand(cmd, opts, cb);
};
+ApigeeTool.listTargetServers = function(opts, cb) {
+ var cmd = require('./commands/list-TargetServers');
+ runCommand(cmd, opts, cb);
+};
+
ApigeeTool.createTargetServer = function(opts, cb) {
var cmd = require('./commands/create-TargetServer');
runCommand(cmd, opts, cb);
};
+ApigeeTool.getTargetServer = function (opts, cb) {
+ var cmd = require('./commands/get-TargetServer.js');
+ runCommand(cmd, opts, cb);
+};
+
ApigeeTool.deleteTargetServer = function(opts,cb){
var cmd = require('./commands/delete-TargetServer');
runCommand(cmd, opts, cb);
@@ -113,8 +123,8 @@ ApigeeTool.createKVM = function(opts, cb) {
runCommand(cmd, opts, cb);
};
-ApigeeTool.getkvmmap = function(opts, cb) {
- var cmd = require('./commands/getkvmmap');
+ApigeeTool.getKVMmap = function(opts, cb) {
+ var cmd = require('./commands/getKVMmap');
runCommand(cmd, opts, cb);
};
@@ -163,6 +173,62 @@ ApigeeTool.deleteSharedflow = function (opts, cb) {
runCommand(cmd, opts, cb);
};
+ApigeeTool.attachFlowHook = function (opts, cb) {
+ var cmd = require('./commands/attachFlowHook.js');
+ runCommand(cmd, opts, cb);
+};
+
+ApigeeTool.detachFlowHook = function (opts, cb) {
+ var cmd = require('./commands/detachFlowHook.js');
+ runCommand(cmd, opts, cb);
+};
+
+ApigeeTool.getFlowHook = function (opts, cb) {
+ var cmd = require('./commands/getFlowHook.js');
+ runCommand(cmd, opts, cb);
+};
+
+ApigeeTool.getRoles = function (opts, cb) {
+ var cmd = require('./commands/getRoles.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.getRole = function (opts, cb) {
+ var cmd = require('./commands/getRole.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.createRole = function (opts, cb) {
+ var cmd = require('./commands/createRole.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.deleteRole = function (opts, cb) {
+ var cmd = require('./commands/deleteRole.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.getRolePermissions = function (opts, cb) {
+ var cmd = require('./commands/getRolePermissions.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.setRolePermissions = function (opts, cb) {
+ var cmd = require('./commands/setRolePermissions.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.assignUserRole = function (opts, cb) {
+ var cmd = require('./commands/assignUserRole.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.removeUserRole = function (opts, cb) {
+ var cmd = require('./commands/removeUserRole.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.verifyUserRole = function (opts, cb) {
+ var cmd = require('./commands/verifyUserRole.js');
+ runCommand(cmd, opts, cb);
+};
+ApigeeTool.getRoleUsers = function (opts, cb) {
+ var cmd = require('./commands/getRoleUsers.js');
+ runCommand(cmd, opts, cb);
+};
+
function runCommand(cmd, opts, cb) {
options.validate(opts, cmd.descriptor, function(err) {
if (err) {
diff --git a/lib/options.js b/lib/options.js
index 4da1735..8dc0da4 100644
--- a/lib/options.js
+++ b/lib/options.js
@@ -47,8 +47,9 @@ module.exports.getopts = function(argv, start, descriptor) {
} else {
badArg(argv[i]);
}
+ } else {
+ badArg(argv[i]);
}
-
}
else {
var shortArg = /^-([A-Za-z])/.exec(argv[i]);
@@ -124,27 +125,33 @@ module.exports.validate = function(opts, descriptor, cb) {
function checkProperty(opts, descriptor, propName, done) {
var desc = descriptor[propName];
+ // console.log( "DEBUG " + desc.required + " " + opts[propName] + " " + opts.prompt + " " + desc.prompt + " " + propName);
+ // console.log( "DEBUG OPTs" + JSON.stringify(opts) );
if (desc === null || desc === undefined) {
done(new Error(util.format('Invalid property %s', propName)));
return;
}
- if (desc.required && !opts[propName] && (!opts.prompt && desc.prompt)) {
- if (opts.interactive) {
- var pn = (desc.name ? desc.name : propName);
- prompt(pn, desc.secure, function(err, val) {
- if (err) {
- done(err);
- } else {
- if (desc.secure === true) {
- opts[propName] = new SecureValue(val);
+ if (desc.required && !opts[propName]) {
+ if (desc.prompt && !opts.prompt ) {
+ if (opts.interactive) {
+ var pn = (desc.name ? desc.name : propName);
+ prompt(pn, desc.secure, function(err, val) {
+ if (err) {
+ done(err);
} else {
- opts[propName] = val;
+ if (desc.secure === true) {
+ opts[propName] = new SecureValue(val);
+ } else {
+ opts[propName] = val;
+ }
+ done();
}
- done();
- }
- });
+ });
+ } else {
+ done(new Error(util.format('Missing required option "%s"', propName)));
+ }
} else {
- done(new Error(util.format('Missing required option "%s"', propName)));
+ done(new Error(util.format('Missing required option with no prompt "%s"', propName)));
}
} else {
if (opts[propName] && (desc.secure === true)) {
@@ -207,9 +214,13 @@ module.exports.getHelp = function(descriptor) {
var tab = new Table(TableFormat);
_.each(_.sortBy(_.pairs(descriptor)), function(d) {
- tab.push([d[0],
+ tab.push([
+ d[0],
(d[1].shortOption ? '-' + d[1].shortOption : ''),
- ((d[1].required && !d[1].prompt) ? '(required)': '(optional)')]);
+ ((d[1].required && !d[1].prompt) ? '(required)': '(optional)'),
+ ((d[1].name ? d[1].name : 'undefined')),
+ ((d[1].scope == 'default') ? '' : '(command specific)')
+ ]);
});
return tab.toString();
diff --git a/lib/promisesdk.js b/lib/promisesdk.js
index 2d9be0c..6ac73df 100644
--- a/lib/promisesdk.js
+++ b/lib/promisesdk.js
@@ -161,6 +161,13 @@ ApigeeTool.deleteDeveloper = function(opts){
return cb.promise
}
+ApigeeTool.listTargetServers = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/list-TargetServers');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+};
+
ApigeeTool.createTargetServer = function(opts) {
var cb = q.defer()
var cmd = require('./commands/create-TargetServer');
@@ -168,6 +175,13 @@ ApigeeTool.createTargetServer = function(opts) {
return cb.promise
};
+ApigeeTool.getTargetServer = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/get-TargetServer');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+};
+
ApigeeTool.deleteTargetServer = function(opts){
var cb = q.defer()
var cmd = require('./commands/delete-TargetServer');
@@ -197,9 +211,9 @@ ApigeeTool.getKVMentry = function(opts) {
return cb.promise
}
-ApigeeTool.getkvmmap = function(opts) {
+ApigeeTool.getKVMmap = function(opts) {
var cb = q.defer()
- var cmd = require('./commands/getkvmmap');
+ var cmd = require('./commands/getKVMmap');
runCommand(cmd, opts, cb);
return cb.promise
}
@@ -232,6 +246,88 @@ ApigeeTool.createAppKey = function(opts) {
return cb.promise
}
+ApigeeTool.attachFlowHook = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/attachFlowHook');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+
+ApigeeTool.detachFlowHook = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/detachFlowHook');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+
+ApigeeTool.getFlowHook = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/getFlowHook');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+
+ApigeeTool.getRoles = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/getRoles');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.createRole = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/createRole');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.getRole = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/getRole');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.deleteRole = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/deleteRole');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.setRolePermissions = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/setRolePermissions');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.getRolePermissions = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/getRolePermissions');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.assignUserRole = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/assignUserRole');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.removeUserRole = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/removeUserRole');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.verifyUserRole = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/verifyUserRole');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+ApigeeTool.getRoleUsers = function(opts) {
+ var cb = q.defer()
+ var cmd = require('./commands/getRoleUsers');
+ runCommand(cmd, opts, cb);
+ return cb.promise
+}
+
function runCommand(cmd, opts, cb) {
options.validate(opts, cmd.descriptor, function(err) {
if (err) {
diff --git a/remotetests/remotetest.js b/remotetests/remotetest.js
index 9f735c5..65cfd72 100644
--- a/remotetests/remotetest.js
+++ b/remotetests/remotetest.js
@@ -24,11 +24,18 @@ var TARGET_SERVER_NAME = 'apigee-cli-test-servername';
var MAP_NAME = 'apigee-cli-test-kvm';
var MAP_NAME_ENCRYPTED = 'apigee-cli-test-kvm-encrypted';
var SHARED_FLOW_NAME = 'apigee-cli-sf';
+var ROLE_NAME = 'apigee-cli-test-role';
var verbose = false;
+var deployedRevision;
+var deployedUri;
+var prevSharedFlow;
+
+// Run all using: mocha remotetests
+// Run all "describe" tests using: mocha remotetests --grep "SharedFlows and FlowHooks"
+// Run one "it" test using: mocha remotetests --grep "fetchSharedflow"
describe('Remote Tests', function() {
this.timeout(REASONABLE_TIMEOUT);
-
var deployedRevision;
var deployedUri;
@@ -39,13 +46,13 @@ describe('Remote Tests', function() {
opts.environment = config.environment;
apigeetool.deleteKVM(opts,function(err,result) {
if (verbose) {
- console.log('Delete KVM result = %j', result);
+ console.log('Delete envrypted KVM result = %j', result);
}
done();
});
});
-
- it('Deploy Apigee Proxy with Promise SDK', function(done) {
+
+ it('Deploy Apigee Proxy', function(done) {
var opts = baseOpts();
opts.api = APIGEE_PROXY_NAME;
opts.directory = path.join(__dirname, '../test/fixtures/employees');
@@ -73,149 +80,152 @@ describe('Remote Tests', function() {
done(err);
})
});
+});
- describe('Products / Developers', function() {
-
- it('Create Product', function(done){
- var opts = baseOpts() ;
- var displayName = 'custom name';
- opts.productName = APIGEE_PRODUCT_NAME;
- opts.productDesc = 'abc123';
- opts.displayName = displayName;
- opts.proxies = APIGEE_PROXY_NAME;
- opts.quota = '1';
- opts.quotaInterval = '1';
- opts.quotaTimeUnit = 'minute';
-
- var sdk = apigeetool.getPromiseSDK()
-
- sdk.createProduct(opts)
- .then(function(result){
- try {
- assert.equal(result.displayName, displayName);
- done();
- } catch (e) {
- done(e);
- }
- },function(err){
- done(err)
- }) ;
- });
+describe('Products / Developers', function() {
+ this.timeout(REASONABLE_TIMEOUT);
- it('Create Private Product', function(done){
- var opts = baseOpts() ;
- var displayName = 'custom name';
- opts.productName = APIGEE_PRIVATE_PRODUCT_NAME;
- opts.productDesc = 'abc123';
- opts.displayName = displayName;
- opts.proxies = APIGEE_PROXY_NAME;
- opts.quota = '1';
- opts.quotaInterval = '1';
- opts.quotaTimeUnit = 'minute';
- opts.attributes = [ {"name": "access", "value": "private"} ];
- var sdk = apigeetool.getPromiseSDK()
-
- sdk.createProduct(opts)
- .then(function(result){
- try {
- assert.equal(result.displayName, displayName);
- assert.equal(result.attributes.length, 1);
- assert.equal(result.attributes[0].name, 'access');
- assert.equal(result.attributes[0].value, 'private');
- done();
- } catch (e) {
- done(e);
- }
- },function(err){
- done(err)
- }) ;
- });
+ it('Create Product', function(done){
+ var opts = baseOpts() ;
+ var displayName = 'custom name';
+ opts.productName = APIGEE_PRODUCT_NAME;
+ opts.productDesc = 'abc123';
+ opts.displayName = displayName;
+ opts.proxies = APIGEE_PROXY_NAME;
+ opts.quota = '1';
+ opts.quotaInterval = '1';
+ opts.quotaTimeUnit = 'minute';
+ opts.approvalType = "auto";
- it('Create Developer' , function(done){
- var opts = baseOpts()
- opts.email = DEVELOPER_EMAIL
- opts.firstName = 'Test'
- opts.lastName = 'Test1'
- opts.userName = 'runningFromTest123'
-
- var sdk = apigeetool.getPromiseSDK()
-
- sdk.createDeveloper(opts)
- .then(function(result){
- done()
- },function(err){
- done(err)
- }) ;
- });
+ var sdk = apigeetool.getPromiseSDK()
- it('Create App' , function(done){
- var opts = baseOpts()
- opts.name = APP_NAME
- opts.apiproducts = APIGEE_PRODUCT_NAME
- opts.email = DEVELOPER_EMAIL
+ sdk.createProduct(opts)
+ .then(function(result){
+ try {
+ assert.equal(result.displayName, displayName);
+ done();
+ } catch (e) {
+ done(e);
+ }
+ },function(err){
+ done(err)
+ }) ;
+ });
- var sdk = apigeetool.getPromiseSDK()
+ it('Create Private Product', function(done){
+ var opts = baseOpts() ;
+ var displayName = 'custom name';
+ opts.productName = APIGEE_PRIVATE_PRODUCT_NAME;
+ opts.productDesc = 'abc123';
+ opts.displayName = displayName;
+ opts.proxies = APIGEE_PROXY_NAME;
+ opts.quota = '1';
+ opts.quotaInterval = '1';
+ opts.quotaTimeUnit = 'minute';
+ opts.attributes = [ {"name": "access", "value": "private"} ];
+ opts.approvalType = "auto";
+ var sdk = apigeetool.getPromiseSDK()
- sdk.createApp(opts)
- .then(function(result){
- done()
- },function(err){
- done(err)
- }) ;
- });
+ sdk.createProduct(opts)
+ .then(function(result){
+ try {
+ assert.equal(result.displayName, displayName);
+ assert.equal(result.attributes.length, 1);
+ assert.equal(result.attributes[0].name, 'access');
+ assert.equal(result.attributes[0].value, 'private');
+ done();
+ } catch (e) {
+ done(e);
+ }
+ },function(err){
+ done(err)
+ }) ;
+ });
- it('Delete App' , function(done){
- var opts = baseOpts()
- opts.email = DEVELOPER_EMAIL
- opts.name = APP_NAME
- var sdk = apigeetool.getPromiseSDK()
- sdk.deleteApp(opts)
- .then(function(result){
- done()
- },function(err){
- done(err)
- }) ;
- });
+ it('Create Developer' , function(done){
+ var opts = baseOpts()
+ opts.email = DEVELOPER_EMAIL
+ opts.firstName = 'Test'
+ opts.lastName = 'Test1'
+ opts.userName = 'runningFromTest123'
- it('Delete Developer' , function(done){
- var opts = baseOpts()
- opts.email = DEVELOPER_EMAIL
- var sdk = apigeetool.getPromiseSDK()
- sdk.deleteDeveloper(opts)
- .then(function(result){
- done()
- },function(err){
- done(err)
- }) ;
- });
+ var sdk = apigeetool.getPromiseSDK()
- it('Delete API Product',function(done){
- var opts = baseOpts() ;
- opts.productName = APIGEE_PRODUCT_NAME
-
- var sdk = apigeetool.getPromiseSDK()
-
- sdk.deleteProduct(opts)
- .then(function(result){
- done()
- },function(err){
- done(err)
- }) ;
- });
+ sdk.createDeveloper(opts)
+ .then(function(result){
+ done()
+ },function(err){
+ done(err)
+ }) ;
+ });
- it('Delete API private Product',function(done){
- var opts = baseOpts() ;
- opts.productName = APIGEE_PRIVATE_PRODUCT_NAME
-
- var sdk = apigeetool.getPromiseSDK()
-
- sdk.deleteProduct(opts)
- .then(function(result){
- done()
- },function(err){
- done(err)
- }) ;
- });
+ it('Create App' , function(done){
+ var opts = baseOpts()
+ opts.name = APP_NAME
+ opts.apiProducts = APIGEE_PRODUCT_NAME
+ opts.email = DEVELOPER_EMAIL
+
+ var sdk = apigeetool.getPromiseSDK()
+
+ sdk.createApp(opts)
+ .then(function(result){
+ done()
+ },function(err){
+ done(err)
+ });
+ });
+
+ it('Delete App' , function(done){
+ var opts = baseOpts()
+ opts.email = DEVELOPER_EMAIL
+ opts.name = APP_NAME
+ var sdk = apigeetool.getPromiseSDK()
+ sdk.deleteApp(opts)
+ .then(function(result){
+ done()
+ },function(err){
+ done(err)
+ }) ;
+ });
+
+ it('Delete Developer' , function(done){
+ var opts = baseOpts()
+ opts.email = DEVELOPER_EMAIL
+ var sdk = apigeetool.getPromiseSDK()
+ sdk.deleteDeveloper(opts)
+ .then(function(result){
+ done()
+ },function(err){
+ done(err)
+ }) ;
+ });
+
+ it('Delete API Product',function(done){
+ var opts = baseOpts() ;
+ opts.productName = APIGEE_PRODUCT_NAME
+
+ var sdk = apigeetool.getPromiseSDK()
+
+ sdk.deleteProduct(opts)
+ .then(function(result){
+ done()
+ },function(err){
+ done(err)
+ }) ;
+ });
+
+ it('Delete API private Product',function(done){
+ var opts = baseOpts() ;
+ opts.productName = APIGEE_PRIVATE_PRODUCT_NAME
+
+ var sdk = apigeetool.getPromiseSDK()
+
+ sdk.deleteProduct(opts)
+ .then(function(result){
+ done()
+ },function(err){
+ done(err)
+ }) ;
});
it('Deploy Apigee Proxy', function(done) {
@@ -468,6 +478,36 @@ describe('Remote Tests', function() {
});
});
+ it('Fetch proxy', function(done) {
+ var opts = baseOpts();
+ opts.api = APIGEE_PROXY_NAME;
+ opts.revision = deployedRevision;
+
+ apigeetool.fetchProxy(opts, function(err, result) {
+ if (verbose) {
+ console.log('Fetch proxy result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
+
+ it('Delete proxy', function(done) {
+ var opts = baseOpts();
+ opts.api = APIGEE_PROXY_NAME;
+
+ apigeetool.delete(opts, function(err, result) {
+ if (verbose) {
+ console.log('Delete proxy result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
+
+});
+
+describe('Node.js Apps', function() {
+ this.timeout(REASONABLE_TIMEOUT);
+
it('Deploy Node.js App', function(done) {
var opts = baseOpts();
opts.api = NODE_PROXY_NAME;
@@ -649,161 +689,190 @@ describe('Remote Tests', function() {
});
});
- describe('Hosted Target', function() {
-
- it('Deploy Hosted Targets App', function(done) {
- var opts = baseOpts();
- opts.api = HOSTED_TARGETS_PROXY_NAME;
- opts.directory = path.join(__dirname, '../test/fixtures/hellohostedtargets');
- opts.main = 'server.js';
- opts['base-path'] = '/cli-hosted-targets-test';
+ it('Delete node proxy', function(done) {
+ var opts = baseOpts();
+ opts.api = NODE_PROXY_NAME;
- apigeetool.deployHostedTarget(opts, function(err, result) {
- if (verbose) {
- console.log('Deploy result = %j', result);
- }
- if (err) {
- done(err);
- } else {
- try {
- if(Array.isArray(result)) result = result[0]
- assert.equal(result.name, HOSTED_TARGETS_PROXY_NAME);
- assert.equal(result.environment, config.environment);
- assert.equal(result.state, 'deployed');
- //it will be 2 for remote testing public cloud/ http & https
- assert.equal(result.uris.length, 2);
- assert(typeof result.revision === 'number');
- deployedRevision = result.revision;
- deployedUri = result.uris[0];
- setTimeout(done, 10000);
- } catch (e) {
- done(e);
- }
- }
- });
+ apigeetool.delete(opts, function(err, result) {
+ if (verbose) {
+ console.log('Delete node proxy result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
});
+ });
- it('List Deployments by app', function(done) {
- var opts = baseOpts();
- delete opts.environment;
- opts.api = HOSTED_TARGETS_PROXY_NAME;
- opts.long = true;
+}); // End Node.js Apps
- apigeetool.listDeployments(opts, function(err, result) {
- if (verbose) {
- console.log('List result = %j', result);
- }
- if (err) {
- done(err);
- } else {
- var deployment = _.find(result.deployments, function(d) {
- return (d.name === HOSTED_TARGETS_PROXY_NAME);
- });
- try {
- assert.equal(deployment.name, HOSTED_TARGETS_PROXY_NAME);
- assert.equal(deployment.environment, config.environment);
- assert.equal(deployment.state, 'deployed');
- assert.equal(deployment.revision, deployedRevision);
- assert.equal(deployment.uris.length, 2);
- assert.equal(deployment.uris[0], deployedUri);
- done();
- } catch (e) {
- done(e);
- }
+describe('Hosted Target', function() {
+ this.timeout(REASONABLE_TIMEOUT);
+
+ it('Deploy Hosted Targets App', function(done) {
+ var opts = baseOpts();
+ opts.api = HOSTED_TARGETS_PROXY_NAME;
+ opts.directory = path.join(__dirname, '../test/fixtures/hellohostedtargets');
+ opts.main = 'server.js';
+ opts['base-path'] = '/cli-hosted-targets-test';
+
+ apigeetool.deployHostedTarget(opts, function(err, result) {
+ if (verbose) {
+ console.log('Deploy result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else {
+ try {
+ if(Array.isArray(result)) result = result[0]
+ assert.equal(result.name, HOSTED_TARGETS_PROXY_NAME);
+ assert.equal(result.environment, config.environment);
+ assert.equal(result.state, 'deployed');
+ //it will be 2 for remote testing public cloud/ http & https
+ assert.equal(result.uris.length, 2);
+ assert(typeof result.revision === 'number');
+ deployedRevision = result.revision;
+ deployedUri = result.uris[0];
+ setTimeout(done, 10000);
+ } catch (e) {
+ done(e);
}
- });
+ }
});
+ });
+
+ it('List Deployments by app', function(done) {
+ var opts = baseOpts();
+ delete opts.environment;
+ opts.api = HOSTED_TARGETS_PROXY_NAME;
+ opts.long = true;
- it('Verify deployed URI', function(done) {
+ apigeetool.listDeployments(opts, function(err, result) {
if (verbose) {
- console.log('Testing %s', deployedUri);
+ console.log('List result = %j', result);
}
- request(deployedUri, function(err, resp, body) {
- if (err) {
- console.error(err, resp.statusCode, body);
- done(err);
- } else {
- try {
- assert.equal(resp.statusCode, 200);
- done();
- } catch (e) {
- done(e);
- }
+ if (err) {
+ done(err);
+ } else {
+ var deployment = _.find(result.deployments, function(d) {
+ return (d.name === HOSTED_TARGETS_PROXY_NAME);
+ });
+ try {
+ assert.equal(deployment.name, HOSTED_TARGETS_PROXY_NAME);
+ assert.equal(deployment.environment, config.environment);
+ assert.equal(deployment.state, 'deployed');
+ assert.equal(deployment.revision, deployedRevision);
+ assert.equal(deployment.uris.length, 2);
+ assert.equal(deployment.uris[0], deployedUri);
+ done();
+ } catch (e) {
+ done(e);
}
- });
+ }
});
+ });
- it('Check build logs from deployed URI', function(done) {
- var opts = baseOpts();
- opts['hosted-build'] = true;
- opts.api = HOSTED_TARGETS_PROXY_NAME;
-
- var logStream = new stream.PassThrough();
- logStream.setEncoding('utf8');
- opts.stream = logStream;
- apigeetool.getLogs(opts, function(err) {
- assert.ifError(err);
-
- var allLogs = '';
- logStream.on('data', function(chunk) {
- allLogs += chunk;
- });
- logStream.on('end', function() {
- assert(/DONE/.test(allLogs));
+ it('Verify deployed URI', function(done) {
+ if (verbose) {
+ console.log('Testing %s', deployedUri);
+ }
+ request(deployedUri, function(err, resp, body) {
+ if (err) {
+ console.error(err, resp.statusCode, body);
+ done(err);
+ } else {
+ try {
+ assert.equal(resp.statusCode, 200);
done();
- });
+ } catch (e) {
+ done(e);
+ }
+ }
+ });
+ });
+
+ it('Check build logs from deployed URI', function(done) {
+ var opts = baseOpts();
+ opts['hosted-build'] = true;
+ opts.api = HOSTED_TARGETS_PROXY_NAME;
+
+ var logStream = new stream.PassThrough();
+ logStream.setEncoding('utf8');
+ opts.stream = logStream;
+ apigeetool.getLogs(opts, function(err) {
+ assert.ifError(err);
+
+ var allLogs = '';
+ logStream.on('data', function(chunk) {
+ allLogs += chunk;
+ });
+ logStream.on('end', function() {
+ assert(/DONE/.test(allLogs));
+ done();
});
});
+ });
- it('Check runtime logs from deployed URI', function(done) {
- var opts = baseOpts();
- opts['hosted-runtime'] = true;
- opts.api = HOSTED_TARGETS_PROXY_NAME;
+ it('Check runtime logs from deployed URI', function(done) {
+ var opts = baseOpts();
+ opts['hosted-runtime'] = true;
+ opts.api = HOSTED_TARGETS_PROXY_NAME;
- var logStream = new stream.PassThrough();
- logStream.setEncoding('utf8');
- opts.stream = logStream;
+ var logStream = new stream.PassThrough();
+ logStream.setEncoding('utf8');
+ opts.stream = logStream;
- apigeetool.getLogs(opts, function(err) {
- assert.ifError(err);
+ apigeetool.getLogs(opts, function(err) {
+ assert.ifError(err);
- var allLogs = '';
- logStream.on('data', function(chunk) {
- allLogs += chunk;
- });
- logStream.on('end', function() {
- //Validate runtime logs
- assert(/Node HTTP server is listening/.test(allLogs));
- done();
- });
+ var allLogs = '';
+ logStream.on('data', function(chunk) {
+ allLogs += chunk;
+ });
+ logStream.on('end', function() {
+ //Validate runtime logs
+ assert(/Node HTTP server is listening/.test(allLogs));
+ done();
});
});
+ });
- it('Undeploy Hosted Targets App Without Revision', function(done) {
- var opts = baseOpts();
- opts.api = HOSTED_TARGETS_PROXY_NAME;
+ it('Undeploy Hosted Targets App Without Revision', function(done) {
+ var opts = baseOpts();
+ opts.api = HOSTED_TARGETS_PROXY_NAME;
- apigeetool.undeploy(opts, function(err, result) {
- if (verbose) {
- console.log('Undeploy result = %j', result);
- }
- if (err) {
- done(err);
- } else {
- try {
- assert.equal(result.name, HOSTED_TARGETS_PROXY_NAME);
- assert.equal(result.environment, config.environment);
- assert.equal(result.state, 'undeployed');
- assert.equal(result.revision, deployedRevision);
- done();
- } catch (e) {
- done(e);
- }
+ apigeetool.undeploy(opts, function(err, result) {
+ if (verbose) {
+ console.log('Undeploy result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else {
+ try {
+ assert.equal(result.name, HOSTED_TARGETS_PROXY_NAME);
+ assert.equal(result.environment, config.environment);
+ assert.equal(result.state, 'undeployed');
+ assert.equal(result.revision, deployedRevision);
+ done();
+ } catch (e) {
+ done(e);
}
- });
+ }
+ });
+ });
+
+ it('Delete hosted target proxy', function(done) {
+ var opts = baseOpts();
+ opts.api = HOSTED_TARGETS_PROXY_NAME;
+
+ apigeetool.delete(opts, function(err, result) {
+ if (verbose) {
+ console.log('Delete hosted target proxy result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
});
- }); // end hosted target tests
+ });
+
+}); // end hosted target tests
+describe('Caches', function() {
it('Create an Cache Resource',function(done){
var opts = baseOpts();
opts.cache = CACHE_RESOURCE_NAME;
@@ -833,9 +902,30 @@ describe('Remote Tests', function() {
}
});
});
+}); // end cache tests
- it('Create Target Server',function(done){
+describe('Target Servers', function() {
+ this.timeout(REASONABLE_TIMEOUT);
+
+ it('List Target Servers SDK',function(done){
+ var opts = baseOpts();
+ opts.environment = config.environment;
+ apigeetool.getPromiseSDK()
+ .listTargetServers(opts)
+ .then(function(res){
+ if (verbose) {
+ console.log('List Target Servers result = %j', res);
+ }
+ done()
+ },function(err){
+ console.log(err)
+ done(err)
+ })
+ });
+
+ it('Create Target Server SDK',function(done){
var opts = baseOpts();
+ opts.environment = config.environment;
opts.targetServerName = TARGET_SERVER_NAME;
opts.targetHost = 'localhost';
opts.targetEnabled = true;
@@ -844,20 +934,98 @@ describe('Remote Tests', function() {
opts.environment = config.environment;
apigeetool.getPromiseSDK()
.createTargetServer(opts)
- .then(function(){done()},
- function(err){
- console.log(err)
- done(err)})
+ .then(function(res){
+ if (verbose) {
+ console.log('Create Target Server result = %j', res);
+ }
+ done()
+ },function(err){
+ console.log(err)
+ done(err)
+ })
});
- it('Delete Target Server',function(done){
+ it('Get Target Server SDK',function(done){
var opts = baseOpts();
+ opts.environment = config.environment;
opts.targetServerName = TARGET_SERVER_NAME;
+ apigeetool.getPromiseSDK()
+ .getTargetServer(opts)
+ .then(function(res){
+ if (verbose) {
+ console.log('Get Target Server result = %j', res);
+ }
+ done()
+ },function(err){
+ console.log(err)
+ done(err)
+ })
+ });
+
+ it('Delete Target Server SDK',function(done){
+ var opts = baseOpts();
opts.environment = config.environment;
+ opts.targetServerName = TARGET_SERVER_NAME;
+ apigeetool.getPromiseSDK()
+ .deleteTargetServer(opts)
+ .then(function(res){
+ if (verbose) {
+ console.log('Delete Target Server result = %j', res);
+ }
+ done()
+ },function(err){
+ console.log(err)
+ done(err)
+ })
+ });
- apigeetool.deleteTargetServer(opts,function(err,result) {
+}); // end target server tests
+
+describe('KVM', function() {
+ it('Create KVM',function(done){
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME;
+ opts.environment = config.environment;
+ apigeetool.getPromiseSDK()
+ .createKVM(opts)
+ .then(function(res){
+ if (verbose) {
+ console.log('Create KVM result = %j', res);
+ }
+ done()
+ },function(err){
+ console.log(err)
+ done(err)
+ })
+ });
+
+ it('Create Encrypted KVM',function(done){
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME_ENCRYPTED;
+ opts.environment = config.environment;
+ opts.encrypted = true;
+ apigeetool.getPromiseSDK()
+ .createKVM(opts)
+ .then(function(res){
+ if (!res.encrypted) {
+ return done(new Error('Map was not encrypted'));
+ } else if (verbose) {
+ console.log('Create KVM result = %j', res);
+ }
+ done();
+ }, function(err){
+ console.log(err)
+ done(err)
+ })
+ });
+
+ it('Delete Encrypted KVM',function(done){
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME_ENCRYPTED;
+ opts.environment = config.environment;
+ apigeetool.deleteKVM(opts,function(err,result) {
if (verbose) {
- console.log('Delete TargetServer result = %j', result);
+ console.log('Delete Encrypted KVM result = %j', result);
}
if (err) {
done(err);
@@ -867,174 +1035,394 @@ describe('Remote Tests', function() {
});
});
- describe('KVM', function() {
- it('Create KVM',function(done){
- var opts = baseOpts();
- opts.mapName = MAP_NAME;
- opts.environment = config.environment;
- apigeetool.getPromiseSDK()
- .createKVM(opts)
- .then(function(){done()},
- function(err){
- console.log(err)
- done(err)})
+ it('Add Entry to KVM',function(done){
+ // This will not work for non-cps orgs
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME;
+ opts.environment = config.environment;
+ opts.entryName = 'test';
+ opts.entryValue = 'test1';
+ apigeetool.getPromiseSDK()
+ .addEntryToKVM(opts)
+ .then(function(res){
+ if (verbose) {
+ console.log('Add Entry to KVM result = %j', res);
+ }
+ done()
+ },function(err){
+ console.log(err)
+ done(err)
+ })
+ });
+
+ it('Get KVM Entry', function(done) {
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME;
+ opts.environment = config.environment;
+ opts.entryName = 'test';
+ apigeetool.getPromiseSDK()
+ .getKVMentry(opts)
+ .then(function(body){
+ if (verbose) {
+ console.log('Get KVM Entry result = %j', body);
+ }
+ assert.equal(body.value, 'test1')
+ done()
+ },
+ function(err) {
+ console.log(err);
+ done(err);
+ })
+ });
+
+ it('Get KVM Map', function(done) {
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME;
+ opts.environment = config.environment;
+ apigeetool.getPromiseSDK()
+ .getKVMmap(opts)
+ .then(function(body){
+ if (verbose) {
+ console.log('Get KVM Map result = %j', body);
+ }
+ assert.equal(body.entry.length, 1)
+ done()
+ },
+ function(err) {
+ console.log(err);
+ done(err);
+ })
+ });
+
+ it('Delete KVM Entry', function(done) {
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME;
+ opts.environment = config.environment;
+ opts.entryName = 'test';
+ apigeetool.getPromiseSDK()
+ .deleteKVMentry(opts)
+ .then(function(body){
+ if (verbose) {
+ console.log('Get KVM Map result = %j', body);
+ }
+ assert.equal(body.value, 'test1')
+ done()
+ },
+ function(err) {
+ console.log(err);
+ done(err);
+ })
+ });
+
+ it('Delete KVM',function(done){
+ var opts = baseOpts();
+ opts.mapName = MAP_NAME;
+ opts.environment = config.environment;
+ apigeetool.deleteKVM(opts,function(err,result) {
+ if (verbose) {
+ console.log('Delete KVM result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else {
+ done()
+ }
});
+ });
+}); // end KVM tests
- it('Create Encrypted KVM',function(done){
- var opts = baseOpts();
- opts.mapName = MAP_NAME_ENCRYPTED;
- opts.environment = config.environment;
- opts.encrypted = true;
- apigeetool.getPromiseSDK()
- .createKVM(opts)
- .then(function(res){
- if (!res.encrypted) {
- return done(new Error('Map was not encrypted'));
+describe('SharedFlows and FlowHooks', function() {
+ this.timeout(REASONABLE_TIMEOUT);
+ it('Deploy SharedFlow', function (done) {
+ var opts = baseOpts();
+ var deployedRevision;
+ opts.name = SHARED_FLOW_NAME;
+ opts.directory = path.join(__dirname, '../test/fixtures/employees-sf');
+ apigeetool.deploySharedflow(opts, function (err, result) {
+ if (verbose) {
+ console.log('Deploy result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else {
+ try {
+ if (Array.isArray(result)) {
+ result = result[0]
}
+ assert.equal(result.name, SHARED_FLOW_NAME);
+ assert.equal(result.environment, config.environment);
+ assert.equal(result.state, 'deployed');
+ // assert.equal(result.uris.length, 1);
+ assert(typeof result.revision === 'number');
+ deployedRevision = result.revision;
+ // deployedUri = result.uris[0];
done();
- }, function(err){
- console.log(err)
- done(err)
- })
+ } catch (e) {
+ done(e);
+ }
+ }
});
+ });
- it('Add Entry to KVM',function(done){
- // This will not work for non-cps orgs
- var opts = baseOpts();
- opts.mapName = MAP_NAME;
- opts.environment = config.environment;
- opts.entryName = 'test';
- opts.entryValue = 'test1';
- apigeetool.getPromiseSDK()
- .addEntryToKVM(opts)
- .then(function(){done()},
- function(err){
- console.log(err);
- done(err)})
+ it('listSharedflowDeployments', function(done) {
+ var opts = baseOpts();
+ opts.sharedFlowName = SHARED_FLOW_NAME;
+ opts.revision = 1;
+
+ apigeetool.listSharedflowDeployments(opts, function(err, result) {
+ if (verbose) {
+ console.log('listSharedflowDeployments result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else { done(); }
});
+ });
- it('Get KVM Entry', function(done) {
- var opts = baseOpts();
- opts.mapName = MAP_NAME;
- opts.environment = config.environment;
- opts.entryName = 'test';
- apigeetool.getPromiseSDK()
- .getKVMentry(opts)
- .then(function(body){
- assert.equal(body.value, 'test1')
- done()
- },
- function(err) {
- console.log(err);
- done(err);
- })
- })
- it('Get KVM Map', function(done) {
- var opts = baseOpts();
- opts.mapName = MAP_NAME;
- opts.environment = config.environment;
- apigeetool.getPromiseSDK()
- .getkvmmap(opts)
- .then(function(body){
- assert.equal(body.entry.length, 1)
- done()
- },
- function(err) {
- console.log(err);
- done(err);
- })
- })
+ it('fetchSharedflow', function(done) {
+ var opts = baseOpts();
+ opts.name = SHARED_FLOW_NAME;
+ opts.revision = 1
- it('Delete KVM Entry', function(done) {
- var opts = baseOpts();
- opts.mapName = MAP_NAME;
- opts.environment = config.environment;
- opts.entryName = 'test';
- apigeetool.getPromiseSDK()
- .deleteKVMentry(opts)
- .then(function(body){
- assert.equal(body.value, 'test1')
- done()
- },
- function(err) {
- console.log(err);
- done(err);
- })
- })
+ apigeetool.fetchSharedflow(opts, function(err, result) {
+ if (verbose) {
+ console.log('fetchSharedflow result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else { done(); }
+ });
+ });
- it('Delete KVM',function(done){
- var opts = baseOpts();
- opts.mapName = MAP_NAME;
- opts.environment = config.environment;
- apigeetool.deleteKVM(opts,function(err,result) {
- if (verbose) {
- console.log('Delete KVM result = %j', result);
- }
- if (err) {
- done(err);
- } else {
- done()
+ it('getPreviousSharedFlow', function(done) {
+ var opts = baseOpts();
+ opts.flowHookName = "PreProxyFlowHook";
+
+ apigeetool.getFlowHook(opts, function(err, result) {
+ if (verbose) {
+ console.log('getFlowhook result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else {
+ if( result.sharedFlow ) {
+ prevSharedFlow = result.sharedFlow;
}
- });
+ done();
+ }
+ });
+ });
+
+ it('attachFlowhook', function(done) {
+ var opts = baseOpts();
+ opts.flowHookName = "PreProxyFlowHook";
+ opts.sharedFlowName = SHARED_FLOW_NAME;
+
+ apigeetool.attachFlowHook(opts, function(err, result) {
+ if (verbose) {
+ console.log('attachFlowHook result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else {
+ done();
+ }
});
- })
+ });
+ it('detachFlowHook', function(done) {
+ var opts = baseOpts();
+ opts.flowHookName = "PreProxyFlowHook";
+
+ apigeetool.detachFlowHook(opts, function(err, result) {
+ if (verbose) {
+ console.log('detachFlowHook result = %j', result);
+ }
+ if (err) {
+ done(err);
+ } else {
+ done();
+ }
+ });
+ });
- describe('SharedFlows', function() {
- it('Deploy SharedFlow', function (done) {
+ it('re-attachFlowHook', function(done) {
+ if( prevSharedFlow ) {
var opts = baseOpts();
- opts.name = SHARED_FLOW_NAME;
- opts.directory = path.join(__dirname, '../test/fixtures/employees-sf');
- apigeetool.deploySharedflow(opts, function (err, result) {
+ opts.flowHookName = "PreProxyFlowHook";
+ opts.sharedFlowName = prevSharedFlow;
+
+ apigeetool.attachFlowHook(opts, function(err, result) {
if (verbose) {
- console.log('Deploy result = %j', result);
+ console.log('prevSharedFlow ' + prevSharedFlow );
+ console.log('re-attachFlowHook result = %j', result);
}
if (err) {
done(err);
} else {
- try {
- if (Array.isArray(result)) {
- result = result[0]
- }
- assert.equal(result.name, SHARED_FLOW_NAME);
- assert.equal(result.environment, config.environment);
- assert.equal(result.state, 'deployed');
- // assert.equal(result.uris.length, 1);
- assert(typeof result.revision === 'number');
- deployedRevision = result.revision;
- // deployedUri = result.uris[0];
- done();
- } catch (e) {
- done(e);
- }
+ done();
}
});
+ } else {
+ done();
+ }
+ });
+
+ it('undeploySharedflow', function(done) {
+ var opts = baseOpts();
+ opts.name = SHARED_FLOW_NAME;
+
+ apigeetool.undeploySharedflow(opts, function(err, result) {
+ if (err) {
+ done(err);
+ } else { // If response is non-200 it throws an Error
+ done();
+ }
});
+ });
- it('listSharedflowDeployments'); // Until MGMT-3671 is merged, will not work
+ it('deleteSharedflow', function(done) {
+ var opts = baseOpts();
+ opts.name = SHARED_FLOW_NAME;
+ apigeetool.deleteSharedflow(opts, done);
+ });
+}); // end shared flow and flow hook tests
- it('fetchSharedflow');
+describe('User Roles and Permissions', function() {
+ this.timeout(REASONABLE_TIMEOUT);
+
+ it('Create Role', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
- it('undeploySharedflow', function(done) {
- var opts = baseOpts();
- opts.name = SHARED_FLOW_NAME;
+ apigeetool.createRole(opts, function (err, result) {
+ if (verbose) {
+ console.log('Create Role result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
- apigeetool.undeploySharedflow(opts, function(err, result) {
- if (err) {
- done(err);
- } else { // If response is non-200 it throws an Error
- done();
- }
- });
+ it('Get Role', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
+
+ apigeetool.getRole(opts, function (err, result) {
+ if (verbose) {
+ console.log('Get Role result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
});
+ });
- it('deleteSharedflow', function(done) {
- var opts = baseOpts();
- opts.name = SHARED_FLOW_NAME;
- apigeetool.deleteSharedflow(opts, done);
+ it('Get Roles', function (done) {
+ var opts = baseOpts();
+
+ apigeetool.getRoles(opts, function (err, result) {
+ if (verbose) {
+ console.log('Get Roles result = %j', result);
+ }
+ if (err) { done(err); } else {
+ assert.equal( result.includes(ROLE_NAME), true );
+ done();
+ }
+ });
+ });
+
+ it('Set Role Permissions', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
+ opts.permissions = '[{"path":"/userroles","permissions":["get"]}]';
+
+ apigeetool.setRolePermissions(opts, function (err, result) {
+ if (verbose) {
+ console.log('Set Role Permissions result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
+
+ it('Get Role Permissions', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
+
+ apigeetool.getRolePermissions(opts, function (err, result) {
+ if (verbose) {
+ console.log('Get Role Permissions result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
+
+ it('Assign User to Role', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
+ opts.email = config.useremail;
+
+ apigeetool.assignUserRole(opts, function (err, result) {
+ if (verbose) {
+ console.log('Assign User to Role result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
+
+ it('Verify User in Role', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
+ opts.email = config.useremail;
+
+ apigeetool.verifyUserRole(opts, function (err, result) {
+ if (verbose) {
+ console.log('Verify User in Role result = %j', result);
+ }
+ if (err) { done(err); } else {
+ assert.equal( result.emailId, opts.email);
+ done();
+ }
+ });
+ });
+
+ it('Verify access allowed', function (done) {
+ var opts = baseOpts();
+ opts.netrc = false;
+ opts.username = config.useremail;
+ opts.password = config.userpassword;
+ apigeetool.getRoles(opts, function (err, result) {
+ if (verbose) {
+ console.log('Verify access allowed result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
});
- })
+ });
+
+
+ it('Remove User from Role', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
+ opts.email = config.useremail;
+
+ apigeetool.removeUserRole(opts, function (err, result) {
+ if (verbose) {
+ console.log('Remove User from Role result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
+
+ it('Delete Role', function (done) {
+ var opts = baseOpts();
+ opts.roleName = ROLE_NAME;
+
+ apigeetool.deleteRole(opts, function (err, result) {
+ if (verbose) {
+ console.log('Delete Role result = %j', result);
+ }
+ if (err) { done(err); } else { done(); }
+ });
+ });
+
});
function baseOpts() {
diff --git a/remotetests/testconfig-sample.js b/remotetests/testconfig-sample.js
index 3b5b4b4..d967b46 100644
--- a/remotetests/testconfig-sample.js
+++ b/remotetests/testconfig-sample.js
@@ -10,11 +10,17 @@ module.exports = {
// The user name to authenticate with for the Apigee management API
username: '',
// The password for that user name
- password: ''
+ password: '',
// comment the username and password and uncomment the following to use .netrc
// netrc: true
-
+ debug: false,
+ verbose: false,
+
+ // Developer must exist or be added to org before tests
+ useremail: 'someone+tester@google.com',
+ userpassword: 'Supersecret123'
+
// Uncomment for the management API URI of your local Apigee environment
// Leave commented to test using the Apigee cloud.
//baseuri: 'http://mgmt:8080'
diff --git a/test/testoptions.js b/test/testoptions.js
index 05b0956..ac2bfbf 100644
--- a/test/testoptions.js
+++ b/test/testoptions.js
@@ -31,7 +31,21 @@ describe('Options parsing test', function(done) {
bar: { required: false, prompt: false },
baz: { required: true, prompt: true }
};
- var opts = { foo: 1, bar: 'baz'};
+ var opts = { foo: 1, bar: 'value'};
+ options.validate(opts, desc, function(err) {
+ assert(err);
+ assert(/Missing required option/.test(err.message));
+ done();
+ });
+ });
+
+ it('Test missing option prompt false', function(done) {
+ var desc = {
+ foo: {},
+ ping: { required: false, prompt: false },
+ pong: { required: true, prompt: false }
+ };
+ var opts = { foo: 1, ping: 1};
options.validate(opts, desc, function(err) {
assert(err);
assert(/Missing required option/.test(err.message));
@@ -101,13 +115,16 @@ describe('Options parsing test', function(done) {
it('Test command-line help', function() {
var desc = {
- foo: {},
- bar: { required: false, shortOption: 'b' },
- baz: { required: true }
+ foo: { },
+ ping: { name: 'Ping', required: false, prompt: false },
+ pong: { name: 'Pong', required: true, prompt: false }
};
+ var opts = { ping: 1, pong: 'value'};
var help = options.getHelp(desc);
- //console.log('Help is:' + help);
+ // console.log('Help is: ' + help);
+ assert.notEqual( help, undefined );
});
+
it('Test command-line toggle', function() {
var desc = {
foo: {},