Skip to content

Commit

Permalink
Implemented Issue apigee#162 - Target Server Get and List
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtkanaskie committed Sep 24, 2019
1 parent a010f42 commit d11585f
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 25 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ 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
* create, delete Target Servers
* attach, detach, or get a FlowHook
* create, get, delete, list Target Servers

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

Expand Down Expand Up @@ -127,8 +127,10 @@ Currently this only affects file uploads in the `deploynodeapp` command. Default
* [getKVMentry](#getKVMentry)
* [getKVMmap](#getKVMmap)
* [getlogs](#getlogs)
* [getTargetServer](#getTargetServer)
* [listdeployments](#listdeployments)
* [listSharedflowDeployments](#listSharedflowDeployments)
* [listTargetServers](#listTargetServers)
* [undeploySharedflow](#undeploySharedflow)
* [undeploy](#undeploy)

Expand Down Expand Up @@ -985,6 +987,49 @@ 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="getTargetServer"></a>getTargetServer

Get details for a Target Server with the given name.

#### Example
Get Target Server named "test-target".

apigeetool getTargetServer -N -o $ORG -e $ENV --targetServerName test-target

#### 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.
`--targetServerName` (required) The name of the Target Server to be deleted.

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

List Target Servers in a given environment.

#### Example
List Target Servers.

apigeetool listTargetServers -N -o $ORG -e $ENV

#### 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.

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

Operations on the pre-defined FlowHook names:
Expand Down
12 changes: 12 additions & 0 deletions lib/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ var Commands = {
return require('./delete-TargetServer');
}
},
getTargetServer: {
description: 'Get a Target Server',
load: function() {
return require('./get-TargetServer');
}
},
listTargetServers: {
description: 'List Target Servers',
load: function() {
return require('./list-TargetServers');
}
},
createkvmmap: {
description: 'Create a KVM map',
load: function() {
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/create-TargetServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var descriptor = defaults.defaultDescriptor({
environment: {
name: 'Environment',
shortOption: 'e',
required: true
required: true,
prompt: true
},
targetServerName: {
name: 'Target Server Name',
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/delete-TargetServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var descriptor = defaults.defaultDescriptor({
environment: {
name: 'Environment',
shortOption: 'e',
required: true
required: true,
prompt: true
},
targetServerName: {
name: 'Target Server Name',
Expand Down
38 changes: 38 additions & 0 deletions lib/commands/get-TargetServer.js
Original file line number Diff line number Diff line change
@@ -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)
};
33 changes: 33 additions & 0 deletions lib/commands/list-TargetServers.js
Original file line number Diff line number Diff line change
@@ -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({
environment: {
name: 'Environment',
shortOption: 'e',
required: true,
prompt: 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)
};
10 changes: 10 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,21 @@ ApigeeTool.createTargetServer = function(opts, cb) {
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);
};

ApigeeTool.listTargetServers = function(opts, cb) {
var cmd = require('./commands/list-TargetServers');
runCommand(cmd, opts, cb);
};

ApigeeTool.createKVM = function(opts, cb) {
var cmd = require('./commands/create-KVM');
runCommand(cmd, opts, cb);
Expand Down
14 changes: 14 additions & 0 deletions lib/promisesdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ ApigeeTool.deleteTargetServer = 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.listTargetServers = function(opts) {
var cb = q.defer()
var cmd = require('./commands/list-TargetServers');
runCommand(cmd, opts, cb);
return cb.promise
};

ApigeeTool.createKVM = function(opts) {
var cb = q.defer()
var cmd = require('./commands/create-KVM');
Expand Down
98 changes: 76 additions & 22 deletions remotetests/remotetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,43 +889,97 @@ describe('Caches', function() { // it
describe('Target Servers', function() { // it
this.timeout(REASONABLE_TIMEOUT);

it('Create Target Server SDK',function(done){
it('Create Target Server',function(done){
var opts = baseOpts();
opts.environment = config.environment;
opts.targetServerName = TARGET_SERVER_NAME;
opts.targetHost = 'localhost';
opts.targetEnabled = true;
opts.targetPort = 443;
opts.targetSSL=true;
opts.environment = config.environment

apigeetool.createTargetServer(opts, function(err, result) {
if (verbose) {
console.log('Create Target Server result = %j', result);
}
if (err) {
done(err);
} else {
try {
assert.equal(result.name,TARGET_SERVER_NAME);
assert.equal(result.port,443);
assert.equal(result.isEnabled,true);
done();
} catch (e) {
done(e);
}
}
});
});

it('List Target Servers',function(done){
var opts = baseOpts();
opts.environment = config.environment;
apigeetool.getPromiseSDK()
.createTargetServer(opts)
.then(function(res){
if (verbose) {
console.log('Create Target Server result = %j', res);
apigeetool.listTargetServers(opts, function(err, result) {
if (verbose) {
console.log('List Target Servers result = %j', result);
}
if (err) {
done(err);
} else {
try {
assert.equal(result.includes(TARGET_SERVER_NAME),true);
done();
} catch (e) {
done(e);
}
done()
},function(err){
console.log(err)
done(err)
})
}
});
});

it('Delete Target Server SDK',function(done){
it('Get Target Server',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);
apigeetool.getTargetServer(opts, function(err, result) {
if (verbose) {
console.log('Get Target Server result = %j', result);
}
if (err) {
done(err);
} else {
try {
assert.equal(result.name,TARGET_SERVER_NAME);
assert.equal(result.port,443);
assert.equal(result.isEnabled,true);
done();
} catch (e) {
done(e);
}
done()
},function(err){
console.log(err)
done(err)
})
}
});
});

it('Delete Target Server',function(done){
var opts = baseOpts();
opts.environment = config.environment;
opts.targetServerName = TARGET_SERVER_NAME;
apigeetool.deleteTargetServer(opts, function(err, result) {
if (verbose) {
console.log('Delete Target Server result = %j', result);
}
if (err) {
done(err);
} else {
try {
assert.equal(result.name,TARGET_SERVER_NAME);
done();
} catch (e) {
done(e);
}
}
});
});

}); // end target server tests
Expand Down

0 comments on commit d11585f

Please sign in to comment.