Hello Sai,
This requirement is to verify if shared flow is available and attached to all flows.
You have helped for similar requirement earlier, where we are checking for the
FC-ELK-Logger and shared flow ELK-Logger availability in ONE FLOW only "
PostClientFlow". Please find the below.
Now iam checking the shared flow “Conditional-Flow-Hook” availability in all flows by looping through all flows. But it’s not working. My requirement is to check if sharedflow Conditional-Flow-Hook is attached to all flows via flow hook policy or not.
Earlier working code :
var plugin = {
ruleId: “EX-PE001”,
name: “Proxy endpoint - Check for SharedFlow in PostClientFlow”,
message:
“Mandatory sharedflow missing in PostClientFlow”,
fatal: true,
severity: 2, //0-ignore; 1-warning; 2-error
nodeType: “Endpoint”,
enabled: true
}
var onProxyEndpoint = function(ep, cb) {
var hadError = false;
//PostClientFlow - check for SharedFlow
var sharedFlowsFoundInPostClientFlow = false;
if (ep.getPostClientFlow()) {
var steps = ep.getPostClientFlow().getFlowResponse().getSteps();
steps.forEach(function(step) {
if (step.getName() && ep.getParent().getPolicies()) {
var p = ep.getParent().getPolicyByName(step.getName());
if (step.getName() === “FC-ELK-Logger” && p.getType() === “FlowCallout” && p.getName() === “FC-ELK-Logger”) { //update your FlowCallout policy name here
var sharedFlowName = p.select(“//SharedFlowBundle/text()”)[0].nodeValue;
if(sharedFlowName === “ELK-Logger”){ //Update your sharedflow name here
sharedFlowsFoundInPostClientFlow= true;
}
}
}
});
}
if (!sharedFlowsFoundInPostClientFlow) {
ep.addMessage({
plugin,
message: “PostClientFlow SharedFlow is missing”
});
hadError = true;
}
if (typeof(cb) == ‘function’) {
cb(null, hadError);
}
};
module.exports = {
plugin,
onProxyEndpoint
};
Current not working code
var plugin = {
ruleId: “EX-PE001”,
name: “Proxy endpoint - Check for SharedFlow in PostClientFlow”,
message:
“Mandatory sharedflow missing in PostClientFlow”,
fatal: true,
severity: 2, //0-ignore; 1-warning; 2-error
nodeType: “Endpoint”,
enabled: true
}
var onProxyEndpoint = function(ep, cb) {
var hadError = false;
var conditionalflow = false;
var flows = ep.getFlows();
for (var i = 0; i < flows.length; i++) {
var steps = flows[i].getFlowRequest().getSteps();
for (var j = 0; j < steps.length; j++) {
var p = ep.getParent().getPolicyByName(steps[j].getName());
if (step.getName() === “FC-Conditional-Flow-Hook” && p.getType() === “FlowCallout” && p.getName() === “FC-Conditional-Flow-Hook”) { //update your FlowCallout policy name here
var sharedFlowName = p.select(“//SharedFlowBundle/text()”)[0].nodeValue;
if(sharedFlowName === “Conditional-Flow-Hook”){ //Update your sharedflow name here
conditionalflow= true;
break;
}
}
}
}
if (!conditionalflow) {
ep.addMessage({
plugin,
message: “conditionalflow SharedFlow is missing”
});
hadError = true;
}
if (typeof(cb) == ‘function’) {
cb(null, hadError);
}
};
module.exports = {
plugin,
onProxyEndpoint
};