Skip to content

Commit

Permalink
feat: ext plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ssvaidyanathan committed May 31, 2024
1 parent 9f27abc commit 57947b1
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 177 deletions.
53 changes: 53 additions & 0 deletions externalPlugins/EX-001-CheckForPoliciesWhileStreaming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const plugin = {
ruleId: "EX-001",
name: "Streaming",
message: "Check for policies while streaming is enabled",
fatal: false,
severity: 2, // 1 = warn, 2 = error
nodeType: "Bundle",
enabled: true
};

const onBundle = function(bundle, cb) {
let hadWarnErr=false, isProxyStreamingEnabled=false, isTargetStreamingEnabled=false;
const proxies = bundle.getProxyEndpoints();
proxies.forEach((proxyEndpoint, _p) => {
const httpProxyConnection = proxyEndpoint.getHTTPProxyConnection();
if(httpProxyConnection){
let properties = httpProxyConnection.getProperties();
if(properties!=null && (properties["request.streaming.enabled"]=="true" || properties["response.streaming.enabled"]=="true")){
isProxyStreamingEnabled = true;
}
}
});
const targets = bundle.getTargetEndpoints();
targets.forEach((targetEndpoint, _t) => {
const httpTargetConnection = targetEndpoint.getHTTPTargetConnection();
if(httpTargetConnection){
let properties = httpTargetConnection.getProperties();
if(properties!=null && (properties["request.streaming.enabled"]=="true" || properties["response.streaming.enabled"]=="true")){
isTargetStreamingEnabled = true;
}
}
});

if(isProxyStreamingEnabled || isTargetStreamingEnabled){
bundle.getPolicies().forEach(function(policy) {
if ((policy.getType() === "AssignMessage" || policy.getType() === "ExtractVariables") && policy.getSteps().length > 0) {
bundle.addMessage({
plugin,
source: policy.getSource(),
line: policy.getElement().lineNumber,
column: policy.getElement().columnNumber,
message: "ExtractVariables/AssignMessage policies not allowed when streaming is enabled"
});
hadWarnErr = true;
}
});
}
};

module.exports = {
plugin,
onBundle
};
13 changes: 12 additions & 1 deletion lib/package/HTTPProxyConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ HTTPProxyConnection.prototype.addMessage = function(msg) {
this.parent.addMessage(msg);
};


HTTPProxyConnection.prototype.getProperties = function() {
var props = new Map();
if (!this.properties) {
var propsNodeList = xpath.select("./Properties", this.element)[0].childNodes;
Array.from(propsNodeList).forEach(function(prop) {
if (prop.childNodes){
props[prop.attributes[0].nodeValue]=prop.childNodes[0].nodeValue;
}
});
}
return props;
};

HTTPProxyConnection.prototype.summarize = function() {
var summary = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/package/HTTPTargetConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ HTTPTargetConnection.prototype.getURL = function() {
};

HTTPTargetConnection.prototype.getProperties = function() {
var props = [];
var props = new Map();
if (!this.properties) {
var propsNodeList = xpath.select("./Properties", this.element)[0].childNodes;
Array.from(propsNodeList).forEach(function(prop) {
Expand Down
Loading

0 comments on commit 57947b1

Please sign in to comment.