Skip to content

Commit

Permalink
remove dead code relating to the Edge management server
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoChiesa committed Dec 19, 2024
1 parent b736fb8 commit 98b05de
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 502 deletions.
4 changes: 0 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ const findBundle = (p) => {
"-e, --excluded [value]",
"The comma separated list of tests to exclude (default: none)",
)
// .option("-M, --mgmtserver [value]", "Apigee management server")
// .option("-u, --user [value]", "Apigee user account")
// .option("-p, --password [value]", "Apigee password")
// .option("-o, --organization [value]", "Apigee organization")
.option(
"-x, --externalPluginsDirectory [value]",
"Relative or full path to an external plugins directory",
Expand Down
148 changes: 40 additions & 108 deletions lib/package/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function _buildEndpoints(folder, tag, bundle, processFunction) {
if (endptFile.endsWith(".xml") && fs.lstatSync(fqFname).isFile()) {
const doc = xpath.select(
tag,
new Dom().parseFromString(fs.readFileSync(fqFname).toString())
new Dom().parseFromString(fs.readFileSync(fqFname).toString()),
);
doc.forEach((element) => processFunction(element, fqFname, bundle));
}
Expand Down Expand Up @@ -67,7 +67,12 @@ function buildsharedflows(bundle) {
processFunction = function (element, fqFname, bundle) {
bundle.proxyEndpoints = bundle.proxyEndpoints || [];
bundle.proxyEndpoints.push(
new Endpoint(element, bundle, fqFname, bundleType.BundleType.SHAREDFLOW)
new Endpoint(
element,
bundle,
fqFname,
bundleType.BundleType.SHAREDFLOW,
),
);
};
_buildEndpoints(folder, tag, bundle, processFunction);
Expand All @@ -92,10 +97,10 @@ function buildPolicies(bundle) {
const ext = policyFile.split(".").pop();
if (ext === "xml") {
bundle.policies.push(
new Policy(bundle.proxyRoot + "/policies", policyFile, bundle)
new Policy(bundle.proxyRoot + "/policies", policyFile, bundle),
);
}
}
},
);
}
}
Expand All @@ -110,7 +115,7 @@ function _buildResources(parent, path, resources) {
_buildResources(parent, path + "/" + policyFile, resources);
} else if (!policyFile.endsWith("~")) {
resources.push(
new Resource(parent, path + "/" + policyFile, policyFile)
new Resource(parent, path + "/" + policyFile, policyFile),
);
}
});
Expand All @@ -132,7 +137,7 @@ Bundle.prototype.getElement = function () {
if (!this.element && fs.existsSync(filePath)) {
debug(`getElement: filePath:${filePath}`);
this.element = new Dom().parseFromString(
fs.readFileSync(filePath).toString()
fs.readFileSync(filePath).toString(),
);
}
return this.element;
Expand All @@ -157,7 +162,7 @@ Bundle.prototype.getRevision = function () {
try {
const attr = xpath.select(
`/${this.xPathName}/@revision`,
this.getElement()
this.getElement(),
);
this.revision = (attr[0] && attr[0].value) || "undefined";
} catch (e) {
Expand Down Expand Up @@ -192,7 +197,7 @@ function processFileSystem(config, bundle, cb) {
.filter(
(file) =>
fs.lstatSync(path.join(bundle.root, file)).isFile() &&
file.endsWith(".xml")
file.endsWith(".xml"),
);

if (files.length > 1) {
Expand All @@ -211,7 +216,7 @@ function processFileSystem(config, bundle, cb) {
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
messages: []
messages: [],
};

//only run for proxy or shared flow root
Expand All @@ -236,7 +241,7 @@ function processFileSystem(config, bundle, cb) {
"No " +
bundleTypeName +
" folder found in: " +
JSON.stringify(folders)
JSON.stringify(folders),
});
}
}
Expand All @@ -260,66 +265,9 @@ function Bundle(config, cb) {
this.resolvedPath = config.source.path;
this.sourceType = config.source.type;

if (config.source.type === "ManagementServer") {
//shared flow not implemented for management server
if (config.source.bundleType === bundleType.BundleType.SHAREDFLOW) {
throw "SharedFlows for management server not supported";
}

const ManagementServer = require("./ManagementServer.js"),
org = config.source.org,
api = config.source.api,
revision = config.source.revision,
tempFolder = "/tmp/" + api,
ms = new ManagementServer({
org,
authorization: config.source.authorization
});

deleteFolderRecursive(tempFolder);
fs.mkdirSync(tempFolder);
const fileStream = fs.createWriteStream(tempFolder + "/apiproxy.zip");

ms.get(
"Bundle",
{ org },
{
api,
revision,
onRes: function (res) {
if (res.statusCode === 200) {
res.pipe(fileStream).on("close", function () {
decompress(tempFolder + "/apiproxy.zip", tempFolder).then(
(files) => {
//add the info to the config object here
config.source.path = tempFolder + "/apiproxy";
processFileSystem(config, bundle, cb);
}
);
});
} else {
if (cb) {
cb(null, {
status: res.statusCode,
message: res.statusMessage
});
}
}
}
},
function (body) {
//callback on bundle downloaded
if (body.error) {
console.log(body.error);
//bundle.addMessage(JSON.stringify(body.error));
deleteFolderRecursive(tempFolder);
}
}
);
} else {
processFileSystem(config, bundle, cb);
}
processFileSystem(config, bundle, cb);
}

const isFile = (spec) => {
const exists = fs.existsSync(spec),
stats = exists && fs.lstatSync(spec);
Expand Down Expand Up @@ -353,15 +301,15 @@ Bundle.prototype.getReport = function (cb) {
) {
try {
const docElement = new Dom().parseFromString(
fs.readFileSync(item.filePath).toString()
fs.readFileSync(item.filePath).toString(),
).documentElement;
const directives = lintUtil.findDirectives(docElement);
d(JSON.stringify(directives, null, 2));
if (directives.length > 0) {
const keep = (item) => {
d("checking " + JSON.stringify(item));
const directivesForThisRule = directives.filter((directive) =>
directive.disable.includes(item.ruleId)
directive.disable.includes(item.ruleId),
);
/*
* If there is a directive specifying the ruleId for this message
Expand All @@ -373,21 +321,21 @@ Bundle.prototype.getReport = function (cb) {
directivesForThisRule.length == 0 ||
(item.line &&
!directivesForThisRule.find(
(d) => d.line + 1 == item.line
(d) => d.line + 1 == item.line,
)) ||
(!item.line &&
!directivesForThisRule.find(
(d) => d.line == 2 || d.line == 3
(d) => d.line == 2 || d.line == 3,
))
);
};
item.messages = item.messages.filter(keep);
// update totals
item.warningCount = item.messages.filter(
(m) => m.severity == 1
(m) => m.severity == 1,
).length;
item.errorCount = item.messages.filter(
(m) => m.severity == 2
(m) => m.severity == 2,
).length;
}
} catch (e) {
Expand Down Expand Up @@ -456,7 +404,7 @@ Bundle.prototype.onBundle = function (pluginFunction, cb) {

Bundle.prototype.onPolicies = function (pluginFunction, cb) {
this.getPolicies().forEach((policy) =>
pluginFunction(policy, getcb(`policy '${policy.getName()}'`))
pluginFunction(policy, getcb(`policy '${policy.getName()}'`)),
);
cb(null, {});
};
Expand All @@ -472,8 +420,8 @@ Bundle.prototype.onSteps = function (pluginFunction, callback) {
proxies.forEach((ep) =>
ep.onSteps(
pluginFunction,
getcb(`STEP proxyendpoint '${ep.getName()}'`)
)
getcb(`STEP proxyendpoint '${ep.getName()}'`),
),
);
} else {
debug("no proxyEndpoints");
Expand All @@ -482,8 +430,8 @@ Bundle.prototype.onSteps = function (pluginFunction, callback) {
targets.forEach((ep) =>
ep.onSteps(
pluginFunction,
getcb(`STEP targetendpoint '${ep.getName()}'`)
)
getcb(`STEP targetendpoint '${ep.getName()}'`),
),
);
} else {
debug("no targetEndpoints");
Expand All @@ -505,16 +453,16 @@ Bundle.prototype.onConditions = function (pluginFunction, callback) {
proxies.forEach((ep) =>
ep.onConditions(
pluginFunction,
getcb(`COND proxyendpoint '${ep.getName()}'`)
)
getcb(`COND proxyendpoint '${ep.getName()}'`),
),
);
}
if (targets && targets.length > 0) {
targets.forEach((ep) =>
ep.onConditions(
pluginFunction,
getcb(`COND targetendpoint '${ep.getName()}'`)
)
getcb(`COND targetendpoint '${ep.getName()}'`),
),
);
}
} catch (exc1) {
Expand All @@ -530,7 +478,7 @@ Bundle.prototype.onResources = function (pluginFunction, cb) {
bundle
.getResources()
.forEach((re) =>
pluginFunction(re, getcb(`resource '${re.getFileName()}'`))
pluginFunction(re, getcb(`resource '${re.getFileName()}'`)),
);
}
cb(null, {});
Expand All @@ -539,7 +487,7 @@ Bundle.prototype.onResources = function (pluginFunction, cb) {
Bundle.prototype.onFaultRules = function (pluginFunction, cb) {
if (this.getFaultRules()) {
this.getFaultRules().forEach(
(fr) => fr && pluginFunction(fr, getcb(`faultrule '${fr.getName()}'`))
(fr) => fr && pluginFunction(fr, getcb(`faultrule '${fr.getName()}'`)),
);
}
cb(null, {});
Expand All @@ -548,7 +496,7 @@ Bundle.prototype.onFaultRules = function (pluginFunction, cb) {
Bundle.prototype.onDefaultFaultRules = function (pluginFunction, cb) {
if (this.getDefaultFaultRules()) {
this.getDefaultFaultRules().forEach(
(dfr) => dfr && pluginFunction(dfr, getcb("defaultfaultrule"))
(dfr) => dfr && pluginFunction(dfr, getcb("defaultfaultrule")),
);
}
cb(null, {});
Expand All @@ -558,7 +506,7 @@ Bundle.prototype.onProxyEndpoints = function (pluginFunction, cb) {
const eps = this.getProxyEndpoints();
if (eps && eps.length > 0) {
eps.forEach((ep) =>
pluginFunction(ep, getcb(`PEP proxyendpoint '${ep.getName()}'`))
pluginFunction(ep, getcb(`PEP proxyendpoint '${ep.getName()}'`)),
);
}
cb(null, {});
Expand All @@ -568,7 +516,7 @@ Bundle.prototype.onTargetEndpoints = function (pluginFunction, cb) {
const eps = this.getTargetEndpoints();
if (eps && eps.length > 0) {
eps.forEach((ep) =>
pluginFunction(ep, getcb(`TEP targetendpoint '${ep.getName()}'`))
pluginFunction(ep, getcb(`TEP targetendpoint '${ep.getName()}'`)),
);
}
cb(null, {});
Expand Down Expand Up @@ -629,7 +577,7 @@ Bundle.prototype.getFaultRules = function () {
if (!this.faultRules) {
this.faultRules = this.getEndpoints().reduce(
(a, ep) => [...a, ep.getFaultRules()],
[]
[],
);
}
return this.faultRules;
Expand All @@ -639,7 +587,7 @@ Bundle.prototype.getDefaultFaultRules = function () {
if (!this.defaultFaultRules) {
this.defaultFaultRules = this.getEndpoints().reduce(
(a, ep) => [...a, ep.getDefaultFaultRule()],
[]
[],
);
}
return this.defaultFaultRules;
Expand All @@ -666,26 +614,10 @@ Bundle.prototype.summarize = function () {

policies: this.getPolicies()
? this.getPolicies().map((po) => po.summarize())
: []
: [],
};
return summary;
};

function deleteFolderRecursive(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file) {
const curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}

//Public
module.exports = Bundle;
Loading

0 comments on commit 98b05de

Please sign in to comment.