Skip to content

Commit

Permalink
Merge pull request #225 from DinoChiesa/issue197a
Browse files Browse the repository at this point in the history
enable updateTargetServer command
  • Loading branch information
DinoChiesa authored May 6, 2022
2 parents 123bb6d + 7a2b74c commit 0939606
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 168 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Pull requests are welcomed.
This tool works with Apigee Edge. It does not work with Apigee X or hybrid.
For a similar tool that works with X or hybrid, see [here](https://github.com/srinandan/apigeecli).

## Contents

* [Installation](#installation)
* [What you need to know about apigeetool](#whatyouneed)
Expand Down Expand Up @@ -1059,11 +1060,18 @@ the "-u" and "-p" parameters for username and password or preferably -N for .net

Update a Target Server with the given name.

#### Example
#### Examples
Update Target Server named "test-target" with SSL enabled.

apigeetool updateTargetServer -N -o $ORG -e $ENV --targetServerName test-target --targetHost httpbin.org --targetPort 443 --targetSSL true

Disable the Target Server named "test-target"

apigeetool updateTargetServer -N -o $ORG -e $ENV --targetServerName test-target --targetEnabled false
Enable the Target Server named "test-target"

apigeetool updateTargetServer -N -o $ORG -e $ENV --targetServerName test-target --targetEnabled true

#### Required parameters

The following parameters are required. However, if any are left unspecified
Expand All @@ -1076,8 +1084,8 @@ the "-u" and "-p" parameters for username and password or preferably -N for .net
`--organization -o` (required) The organization to target.
`--environment -e` (required) The environment to target.
`--targetServerName` (required) The name of the Target Server to be created.
`--targetHost` (required) The hostname of the target.
`--targetPort` (required) The port number of the target.
`--targetHost` (optional) The hostname of the target.
`--targetPort` (optional) The port number of the target.
`--targetSSL` (optional) Whether or not SSL is configured, defaults to none.
`--targetEnabled` (optional) Whether or not the Target Server itself is enabled, defaults to true.

Expand Down
6 changes: 2 additions & 4 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env node
/* jshint node: true */
'use strict';

var main = require('./main');
var options = require('./options');
Expand Down Expand Up @@ -64,13 +62,13 @@ function runCommand() {
}
process.exit(6);
}

if (!opts.json && commandModule.format) {
console.log(commandModule.format(result));
} else {
console.log(JSON.stringify(result));
}

process.exit(0);
});
}
66 changes: 32 additions & 34 deletions lib/commands/command-utils.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
var defaults = require('../defaults')
var request = require('request')
var util = require('util')
const defaults = require('../defaults'),
util = require('util');

module.exports.run = function(command, opts, requestOpts,done){
if (opts.verbose) {
console.log('running command ' + command)
}
var request = defaults.defaultRequest(opts);
request(requestOpts,function(err,res,body){
var jsonBody = body
if(err){
done(err)
}else if (res.statusCode == 200 || res.statusCode == 201 || res.statusCode == 204) {
if (opts.verbose) {
console.log(command + ' successful');
}
if (opts.debug) {
console.log('%s', body);
}
done(undefined, jsonBody);
}else {
if (opts.verbose) {
console.error(command + ' result: %j', body);
}
var errMsg;
if (jsonBody && (jsonBody.message)) {
errMsg = jsonBody.message;
} else {
errMsg = util.format(command + ' failed with status code %d', res.statusCode);
}
done(new Error(errMsg));
}
})
}
module.exports.run = function(command, opts, requestOpts, done) {
if (opts.verbose) {
console.log(`${command} - ${requestOpts.method} ${requestOpts.uri}`);
}
var request = defaults.defaultRequest(opts);
request(requestOpts, function(err, res, jsonBody) {
if(err){
done(err);
return;
}
if (res.statusCode == 200 || res.statusCode == 201 || res.statusCode == 204) {
if (opts.verbose) {
console.log(`${command} - success`);
}
if (opts.debug) {
console.log('%s', jsonBody);
}
done(undefined, jsonBody);
return;
}
if (opts.verbose) {
console.error(command + ' result: %j', jsonBody);
}
let errMsg = (jsonBody && (jsonBody.message)) ?
jsonBody.message :
util.format(command + ' failed with status code %d', res.statusCode);

done(new Error(errMsg));
});
};
6 changes: 5 additions & 1 deletion lib/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const Commands = {
description: 'List Target Servers',
load: () => require('./listTargetServers')
},
updateTargetServer: {
description: 'Update a Target Server',
load: () => require('./updateTargetServer')
},
listProxies: {
description: 'List Proxies',
load: () => require('./listProxies')
Expand Down Expand Up @@ -76,7 +80,7 @@ const Commands = {
},
listdeployments: {
description: 'List Deployments',
load: () => require('./listdeployments')
load: () => require('./listDeployments')
},
undeploy: {
description: 'Undeploy Proxy or Node.js Application',
Expand Down
4 changes: 0 additions & 4 deletions lib/commands/deleteTargetServer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* jshint node: true */
'use strict';

const util = require('util'),
defaults = require('../defaults'),
//options = require('../options'),
command_utils = require('./command-utils');

var descriptor = defaults.defaultDescriptor({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* jshint node: true */
'use strict';

const util = require('util'),
path = require('path'),
async = require('async'),
Expand All @@ -10,20 +7,20 @@ const util = require('util'),

tmp.setGracefulCleanup();

var defaults = require('../defaults');
var options = require('../options');
var ziputils = require('../ziputils');
var parseDeployments = require('./parsedeployments');
var fetchproxy = require('./fetchproxy');
var deployproxy = require('./deployproxy');
var createApiProxy = require('../deploycommon').createApiProxy;
var createProxy = require('../deploycommon').createProxy;
var deployProxy = require('../deploycommon').deployProxy;
var unzipProxy = require('../deploycommon').unzipProxy;
var copyFile = require('../deploycommon').copyFile;
var handleUploadResult = require('../deploycommon').handleUploadResult;
var usePackedSource = require('../deploycommon').usePackedSource;
var uploadSource = require('../deploycommon').uploadSource;
const defaults = require('../defaults'),
options = require('../options'),
ziputils = require('../ziputils'),
parseDeployments = require('./parsedeployments'),
fetchProxy = require('./fetchProxy'),
deployProxy1 = require('./deployProxy'),
createApiProxy = require('../deploycommon').createApiProxy,
createProxy = require('../deploycommon').createProxy,
deployProxy2 = require('../deploycommon').deployProxy,
unzipProxy = require('../deploycommon').unzipProxy,
copyFile = require('../deploycommon').copyFile,
handleUploadResult = require('../deploycommon').handleUploadResult,
usePackedSource = require('../deploycommon').usePackedSource,
uploadSource = require('../deploycommon').uploadSource;

const APP_YAML = 'app.yaml';

Expand Down Expand Up @@ -142,7 +139,7 @@ module.exports.run = function(opts, cb) {
createProxy(opts, request, done);
},
function(done) {
deployProxy(opts, request, done);
deployProxy2(opts, request, done);
}
])

Expand Down Expand Up @@ -185,7 +182,7 @@ function preservePoliciesRun(opts, cb) {
opts.file = fetchedProxyZip;

if (opts.verbose) { console.log('Downloading proxy %s revision %d', opts.name, opts.revision); }
fetchproxy.run(opts, function(err) {
fetchProxy.run(opts, function(err) {
if (err) { return cb(err); }

// set up temporary project dir
Expand All @@ -202,7 +199,7 @@ function preservePoliciesRun(opts, cb) {

// deploy proxy at tmpDir
opts.directory = tmpDir;
deployproxy.run(opts, cb);
deployProxy1.run(opts, cb);
});
});
});
Expand Down
37 changes: 17 additions & 20 deletions lib/commands/deploynodeapp.js → lib/commands/deployNodeApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* jshint node: true */
'use strict';

const util = require('util'),
path = require('path'),
async = require('async'),
Expand All @@ -10,20 +7,20 @@ const util = require('util'),

tmp.setGracefulCleanup();

var defaults = require('../defaults');
var options = require('../options');
var ziputils = require('../ziputils');
var parseDeployments = require('./parsedeployments');
var fetchproxy = require('./fetchproxy');
var deployproxy = require('./deployproxy');
var createApiProxy = require('../deploycommon').createApiProxy;
var createProxy = require('../deploycommon').createProxy;
var deployProxy = require('../deploycommon').deployProxy;
var unzipProxy = require('../deploycommon').unzipProxy;
var copyFile = require('../deploycommon').copyFile;
var handleUploadResult = require('../deploycommon').handleUploadResult;
var usePackedSource = require('../deploycommon').usePackedSource;
var uploadSource = require('../deploycommon').uploadSource;
const defaults = require('../defaults'),
options = require('../options'),
ziputils = require('../ziputils'),
parseDeployments = require('./parsedeployments'),
fetchProxy = require('./fetchProxy'),
deployProxy1 = require('./deployProxy'),
createApiProxy = require('../deploycommon').createApiProxy,
createProxy = require('../deploycommon').createProxy,
deployProxy2 = require('../deploycommon').deployProxy,
unzipProxy = require('../deploycommon').unzipProxy,
copyFile = require('../deploycommon').copyFile,
handleUploadResult = require('../deploycommon').handleUploadResult,
usePackedSource = require('../deploycommon').usePackedSource,
uploadSource = require('../deploycommon').uploadSource;

var cleanResults = require('../utils').cleanResults;

Expand Down Expand Up @@ -186,7 +183,7 @@ module.exports.run = function(opts, cb) {
runNpm(opts, request, done);
},
function(done) {
deployProxy(opts, request, done);
deployProxy2(opts, request, done);
}
])

Expand Down Expand Up @@ -236,7 +233,7 @@ function preservePoliciesRun(opts, cb) {
opts.file = fetchedProxyZip;

if (opts.verbose) { console.log('Downloading proxy %s revision %d', opts.name, opts.revision); }
fetchproxy.run(opts, function(err) {
fetchProxy.run(opts, function(err) {
if (err) { return cb(err); }

// set up temporary project dir
Expand All @@ -253,7 +250,7 @@ function preservePoliciesRun(opts, cb) {

// deploy proxy at tmpDir
opts.directory = tmpDir;
deployproxy.run(opts, cb);
deployProxy1.run(opts, cb);
});
});
});
Expand Down
5 changes: 1 addition & 4 deletions lib/commands/getTargetServer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* jshint node: true */
'use strict';

const util = require('util'),
defaults = require('../defaults'),
options = require('../options'),
command_utils = require('./command-utils');

var descriptor = defaults.defaultDescriptor({
Expand All @@ -15,6 +11,7 @@ var descriptor = defaults.defaultDescriptor({
},
targetServerName: {
name: 'Target Server Name',
shortOption: 'n',
required: true,
prompt: true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* jshint node: true */
'use strict';

const util = require('util'),
defaults = require('../defaults'),
options = require('../options'),
Expand Down
4 changes: 0 additions & 4 deletions lib/commands/listTargetServers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* jshint node: true */
'use strict';

const util = require('util'),
defaults = require('../defaults'),
options = require('../options'),
command_utils = require('./command-utils');

var descriptor = defaults.defaultDescriptor({
Expand Down
Loading

0 comments on commit 0939606

Please sign in to comment.