Skip to content

Commit

Permalink
fix: re-add deployExistingRevision to the commands (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoChiesa authored Sep 20, 2024
1 parent 50660b3 commit 8c075a9
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 62 deletions.
118 changes: 64 additions & 54 deletions lib/commands/deleteApp.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,84 @@
/* jshint node: true */
'use strict';
"use strict";

const util = require('util'),
defaults = require('../defaults'),
options = require('../options');
const util = require("util"),
defaults = require("../defaults"),
options = require("../options");

var descriptor = defaults.defaultDescriptor({
'email': {
name: 'Developer Email',
const descriptor = defaults.defaultDescriptor({
email: {
name: "Developer Email",
required: true
},
"name": {
name: "App Name",
required: true
name: {
name: "App Name",
required: true
}
});

module.exports.descriptor = descriptor;

module.exports.run = function(opts, cb) {
module.exports.run = function (opts, cb) {
options.validateSync(opts, descriptor);
if (opts.debug) {
console.log('deleteApp: %j', opts);
console.log("deleteApp: %j", opts);
}
var request = defaults.defaultRequest(opts);
deleteApp(opts, request, function(err, results) {
if (err) {
cb(err);
} else {
if (opts.debug) {
console.log('results: %j', results);
}
cb(undefined, results);
const request = defaults.defaultRequest(opts);
deleteApp(opts, request, function (err, results) {
if (err) {
cb(err);
} else {
if (opts.debug) {
console.log("results: %j", results);
}
});
cb(undefined, results);
}
});
};

function deleteApp(opts,request,done) {
let uri = util.format('%s/v1/o/%s/developers/%s/apps/%s',
opts.baseuri, opts.organization, opts.email, opts.name);
request({
uri: uri,
method:'DELETE',
json:true
},function(err,res,body){
var jsonBody = body;
if(err){
if (opts.debug) {
console.log('Error occured %s', err);
}
done(err);
}else if (res.statusCode === 200) {
if (opts.verbose) {
console.log('Delete successful');
}
if (opts.debug) {
console.log('%s', body);
}
done(undefined, jsonBody);
}else {
if (opts.verbose) {
console.error('Delete App result: %j', body);
}
var errMsg;
if (jsonBody && (jsonBody.message)) {
errMsg = jsonBody.message;
function deleteApp(opts, request, done) {
let uri = util.format(
"%s/v1/o/%s/developers/%s/apps/%s",
opts.baseuri,
opts.organization,
opts.email,
opts.name
);

request(
{
uri,
method: "DELETE",
json: true
},
function (err, res, jsonBody) {
if (err) {
if (opts.debug) {
console.log("Error occured %s", err);
}
done(err);
} else if (res.statusCode === 200) {
if (opts.verbose) {
console.log("Delete successful");
}
if (opts.debug) {
console.log("%s", jsonBody);
}
done(undefined, jsonBody);
} else {
errMsg = util.format('Delete App failed with status code %d', res.statusCode);
if (opts.verbose) {
console.error("Delete App result: %j", jsonBody);
}
const errMsg =
jsonBody && jsonBody.message
? jsonBody.message
: util.format(
"Delete App failed with status code %d",
res.statusCode
);

done(new Error(errMsg));
}
done(new Error(errMsg));
}
});
);
}
53 changes: 53 additions & 0 deletions lib/commands/getApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const util = require("util"),
defaults = require("../defaults"),
options = require("../options");

const descriptor = defaults.defaultDescriptor({
app: {
name: "app",
shortOption: "a",
required: true,
prompt: true
}
});

module.exports.descriptor = descriptor;

module.exports.format = function (r) {
return r.join("\n");
};

module.exports.run = function (opts, cb) {
options.validateSync(opts, descriptor);
if (opts.debug) {
console.log("listApps: %j", opts);
}

let uri = util.format(
"%s/v1/o/%s/apps/%s",
opts.baseuri,
opts.organization,
opts.app
);
let request = defaults.defaultRequest(opts);
if (opts.debug) {
console.log('Going to invoke "%s"', uri);
}
request.get(uri, function (err, req, body) {
if (err) {
cb(err);
} else {
if (req.statusCode === 200) {
if (opts.debug) {
console.log("App: %j", body);
}
if (opts.debug) {
console.log("All done");
}
cb(undefined, body);
} else {
cb(new Error(util.format("HTTP error %d", req.statusCode)));
}
}
});
};
41 changes: 41 additions & 0 deletions lib/commands/listApps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const util = require("util"),
defaults = require("../defaults"),
options = require("../options");

const descriptor = defaults.defaultDescriptor({});

module.exports.descriptor = descriptor;

module.exports.format = function (r) {
return r.join("\n");
};

module.exports.run = function (opts, cb) {
options.validateSync(opts, descriptor);
if (opts.debug) {
console.log("listApps: %j", opts);
}

let uri = util.format("%s/v1/o/%s/apps", opts.baseuri, opts.organization);
let request = defaults.defaultRequest(opts);
if (opts.debug) {
console.log('Going to invoke "%s"', uri);
}
request.get(uri, function (err, req, body) {
if (err) {
cb(err);
} else {
if (req.statusCode === 200) {
if (opts.debug) {
console.log("List of Apps: %j", body);
}
if (opts.debug) {
console.log("All done");
}
cb(undefined, body);
} else {
cb(new Error(util.format("HTTP error %d", req.statusCode)));
}
}
});
};
45 changes: 45 additions & 0 deletions lib/commands/listProducts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const util = require("util"),
defaults = require("../defaults"),
options = require("../options");

const descriptor = defaults.defaultDescriptor({});

module.exports.descriptor = descriptor;

module.exports.format = function (r) {
return r.join("\n");
};

module.exports.run = function (opts, cb) {
options.validateSync(opts, descriptor);
if (opts.debug) {
console.log("listProducts: %j", opts);
}

let uri = util.format(
"%s/v1/o/%s/apiproducts",
opts.baseuri,
opts.organization
);
let request = defaults.defaultRequest(opts);
if (opts.debug) {
console.log('Going to invoke "%s"', uri);
}
request.get(uri, function (err, req, body) {
if (err) {
cb(err);
} else {
if (req.statusCode === 200) {
if (opts.debug) {
console.log("List of Products: %j", body);
}
if (opts.debug) {
console.log("All done");
}
cb(undefined, body);
} else {
cb(new Error(util.format("HTTP error %d", req.statusCode)));
}
}
});
};
4 changes: 4 additions & 0 deletions lib/fns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const fns = [
"listApps",
"getApp",
"listProxies",
"listProducts",
"listSharedflows",
"listDeployments",
"undeploy",
Expand All @@ -8,6 +11,7 @@ const fns = [
"delete",
"deployNodeApp",
"deployHostedTarget",
"deployExistingRevision",
"getLogs",
"createCache",
"deleteCache",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apigeetool",
"version": "0.16.5",
"version": "0.16.6",
"description": "A CLI for Apigee Edge",
"main": "lib/main.js",
"bin": {
Expand Down
Loading

0 comments on commit 8c075a9

Please sign in to comment.