Skip to content

Commit

Permalink
Implemented Issue apigee#159 - Flow Hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtkanaskie committed Sep 24, 2019
1 parent 4b45e36 commit a010f42
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 13 deletions.
83 changes: 81 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You must have an account on Apigee Edge to perform any `apigeetool` functions. T
* create, retrieve or delete a KVM Map in Edge
* create, retrieve or delete a KVM Entry in Edge
* create, delete Target Servers
* attach, detach, or get a FlowHook

You need to be familiar with basic concepts and features of Apigee Edge such as API proxies, organizations, and environments.

Expand Down Expand Up @@ -98,6 +99,7 @@ Currently this only affects file uploads in the `deploynodeapp` command. Default
# <a name="reference"></a>Command reference and examples

* [addEntryToKVM](#addEntryToKVM)
* [attachFlowHook](#attachFlowHook)
* [createappkey](#createappkey)
* [createapp](#createapp)
* [createcache](#createcache)
Expand All @@ -118,9 +120,10 @@ Currently this only affects file uploads in the `deploynodeapp` command. Default
* [deploynodeapp](#deploynodeapp)
* [deployproxy](#deployproxy)
* [deploySharedflow](#deploySharedflow)
* [detachFlowHook](#detachFlowHook)
* [detachFlowHook](#detachFlowHook)
* [fetchproxy](#fetchproxy)
* [fetchSharedflow](#fetchSharedflow)
* [getFlowHook](#getFlowHook)
* [getKVMentry](#getKVMentry)
* [getKVMmap](#getKVMmap)
* [getlogs](#getlogs)
Expand Down Expand Up @@ -572,7 +575,7 @@ for organization name, all of which are required.

## <a name="undeploySharedflow"></a>undeploySharedflow

Undeploys a named API proxy or Node.js app deployed on Apigee Edge.
Undeploys a SharedFlow deployed on Apigee Edge.

#### Example

Expand Down Expand Up @@ -982,6 +985,82 @@ the "-u" and "-p" parameters for username and password or preferably -N for .net
`--environment -e` (required) The environment to target.
`--targetServerName` (required) The name of the Target Server to be deleted.

## <a name="FlowHook Operations"></a>FlowHook Operations

Operations on the pre-defined FlowHook names:

* PreProxyFlowHook
* PreTargetFlowHook
* PostTargetFlowHook
* PostProxyFlowHook

### <a name="attachFlowHook"></a>attachFlowHook

Attach a deployed SharedFlow to one of the [named FlowHooks](#FlowHook Operations).

#### Example
Attach SharedFlow "GetLogValues" to "PreProxyFlowHook".

apigeetool attachFlowHook -N -o $ORG -e $ENV --flowHookName PreProxyFlowHook --sharedFlowName GetLogValues

#### Required parameters

The following parameters are required. However, if any are left unspecified
on the command line, and if apigeetool is running in an interactive shell,
then apigeetool will prompt for them.

See [Common Parameters](#commonargs) for a list of additional parameters, including
the "-u" and "-p" parameters for username and password or preferably -N for .netrc usage.

`--organization -o` (required) The organization to target.
`--environment -e` (required) The environment to target.
`--flowHookName` (required) The pre-defined name of the FlowHook.
`--sharedFlowName` (required) The name of a deployed SharedFlow.

### <a name="detachFlowHook"></a>detachFlowHook

Detach a SharedFlow from one of the [named FlowHooks](#FlowHook Operations).

#### Example
Detach "PreProxyFlowHook".

apigeetool detachFlowHook -N -o $ORG -e $ENV --flowHookName PreProxyFlowHook

#### Required parameters

The following parameters are required. However, if any are left unspecified
on the command line, and if apigeetool is running in an interactive shell,
then apigeetool will prompt for them.

See [Common Parameters](#commonargs) for a list of additional parameters, including
the "-u" and "-p" parameters for username and password or preferably -N for .netrc usage.

`--organization -o` (required) The organization to target.
`--environment -e` (required) The environment to target.
`--flowHookName` (required) The pre-defined name of the FlowHook.

### <a name="getFlowHook"></a>getFlowHook

Get the SharedFlow currently attached to one of the [named FlowHooks](#FlowHook Operations).

#### Example
Detach "PreProxyFlowHook".

apigeetool getFlowHook -N -o $ORG -e $ENV --flowHookName PreProxyFlowHook

#### Required parameters

The following parameters are required. However, if any are left unspecified
on the command line, and if apigeetool is running in an interactive shell,
then apigeetool will prompt for them.

See [Common Parameters](#commonargs) for a list of additional parameters, including
the "-u" and "-p" parameters for username and password or preferably -N for .netrc usage.

`--organization -o` (required) The organization to target.
`--environment -e` (required) The environment to target.
`--flowHookName` (required) The pre-defined name of the FlowHook.

# <a name="sdkreference"></a>SDK Reference

You could use apigeetool as an SDK to orchestrate tasks that you want to perform with Edge, for eg, deploying an api proxy or running tests etc.
Expand Down
52 changes: 52 additions & 0 deletions lib/commands/attachFlowHook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* 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
},
flowHookName: {
name: 'One of: PreProxyFlowHook\n PreTargetFlowHook\n PostTargetFlowHook\n PostProxyFlowHook',
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)
};
18 changes: 18 additions & 0 deletions lib/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ 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');
}
},
createTargetServer: {
description: 'Create a Target Server',
load: function() {
Expand Down
42 changes: 42 additions & 0 deletions lib/commands/detachFlowHook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* 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
},
flowHookName: {
name: 'One of: PreProxyFlowHook\n PreTargetFlowHook\n PostTargetFlowHook\n PostProxyFlowHook',
required: true,
prompt: 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)
};
3 changes: 2 additions & 1 deletion lib/commands/fetchsharedflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ module.exports.run = function (opts, cb) {
if (err) {
console.log("Failed to write file: " + f);
console.log("Error text: " + err);
cb(err);
}
else {
if (opts.verbose) { console.log('Save file: ' + f); }
cb(undefined, res.statusCode + " - wrote: " + f);
}
cb(err);
});
}
}
Expand Down
42 changes: 42 additions & 0 deletions lib/commands/getFlowHook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* 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
},
flowHookName: {
name: 'One of: PreProxyFlowHook\n PreTargetFlowHook\n PostTargetFlowHook\n PostProxyFlowHook',
required: true,
prompt: 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)
};
15 changes: 15 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ 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);
};

function runCommand(cmd, opts, cb) {
options.validate(opts, cmd.descriptor, function(err) {
if (err) {
Expand Down
21 changes: 21 additions & 0 deletions lib/promisesdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,27 @@ 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
}

function runCommand(cmd, opts, cb) {
options.validate(opts, cmd.descriptor, function(err) {
if (err) {
Expand Down
Loading

0 comments on commit a010f42

Please sign in to comment.