Skip to content

Commit 9e689f4

Browse files
Merge pull request #342 from DinoChiesa/issue339
migrate PO00{1,2,3,4,5} to ST00{3,4,5,6,7}
2 parents 435e31d + 0f44be2 commit 9e689f4

File tree

51 files changed

+1931
-1487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1931
-1487
lines changed

README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,14 @@ This example uses the "externalPlugins" directory with a plugin for alternate po
8181

8282
### Listing plugins
8383
List plugins and formatters, with or without --externalPluginsDirectory.
84-
```
84+
```sh
8585
apigeelint --list
86-
apigeelint --list -x ./externalPlugins or apigeelint --list --externalPluginsDirectory ./externalPlugins
86+
apigeelint --list -x ./externalPlugins
87+
88+
# or
89+
90+
apigeelint --list --externalPluginsDirectory ./externalPlugins
91+
8792
```
8893

8994
## Does this tool just lint or does it also check style?
@@ -122,7 +127,7 @@ You can also contribute by reporting issues, asking for new features.
122127
## Rules
123128

124129
The list of rules is a work in progress. We expect it to increase over time. As
125-
product features change (new policies, etc), we will change rules as
130+
product features change (new policies, deprecated policies, etc), we will change rules as
126131
well.
127132

128133
This is the current list:
@@ -141,32 +146,32 @@ This is the current list:
141146
|   |:white_check_mark:| BN009 | Statistics Collector - duplicate policies | Warn on duplicate policies when no conditions are present or conditions are duplicates. |
142147
|   |:white_check_mark:| BN010 | Missing policies | Issue an error if a referenced policy is not present in the bundle. |
143148
| Proxy Definition |   |   |   |   |
144-
|   |:white_check_mark:| PD001 | RouteRules to Targets | RouteRules should map to defined Targets |
145-
|   |:white_check_mark:| PD002 | Unreachable Route Rules - defaults | Only one RouteRule should be present without a condition |
149+
|   |:white_check_mark:| PD001 | RouteRules to Targets | RouteRules should map to defined Targets. |
150+
|   |:white_check_mark:| PD002 | Unreachable Route Rules - defaults | Only one RouteRule should be present without a condition. |
146151
|   |:white_check_mark:| PD003 | Unreachable Route Rules | RouteRule without a condition should be last. |
147152
|   |:white_check_mark:| PD004 | ProxyEndpoint name | ProxyEndpoint name should match basename of filename. |
148153
|   |:white_check_mark:| PD005 | VirtualHost | ProxyEndpoint should have one HTTPProxyConnection, and in the case of profile=apigeex, no VirtualHost. |
149154
| Target Definition |   |   |   |   |
150155
|   |:white_check_mark:| TD001 | Mgmt Server as Target | Discourage calls to the Management Server from a Proxy via target. |
151-
|   |:white_check_mark:| TD002 | Use Target Servers | Encourage the use of target servers |
156+
|   |:white_check_mark:| TD002 | Use Target Servers | Encourage the use of target servers. |
152157
|   |:white_check_mark:| TD003 | TargetEndpoint name | TargetEndpoint name should match basename of filename. |
153158
|   |:white_check_mark:| TD004 | TargetEndpoint SSLInfo | TargetEndpoint HTTPTargetConnection should enable TLS/SSL. |
154159
|   |:white_check_mark:| TD005 | TargetEndpoint SSLInfo references | TargetEndpoint SSLInfo should use references for KeyStore and TrustStore. |
155160
| Flow |   |   |   |   |
156161
|   |:white_check_mark:| FL001 | Unconditional Flows | Only one unconditional flow will get executed. Error if more than one was detected. |
157162
| Step |   |   |   |   |
158-
|   |:white_check_mark:| ST001 | Empty Step | Empty steps clutter the bundle. |
163+
|   |:white_check_mark:| ST001 | Empty Step | Empty steps clutter the bundle. |
159164
|   |:white_check_mark:| ST002 | Step Structure | each Step should have at most one Name element, one Condition element, no others. |
165+
|   |:white_check_mark:| ST003 | Extract Variables Step with JSONPayload | A check for message content should be performed before policy execution. |
166+
|   |:white_check_mark:| ST004 | Extract Variables Step with XMLPayload | A check for message content should be performed before policy execution. |
167+
|   |:white_check_mark:| ST005 | Extract Variables Step with FormParam | A check for message content should be performed before policy execution. |
168+
|   |:white_check_mark:| ST006 | JSON Threat Protection Step | A check for message content should be performed before policy execution. |
169+
|   |:white_check_mark:| ST007 | XML Threat Protection Step | A check for message content should be performed before policy execution. |
160170
| Policy |   |   |   |   |
161-
|   |:white_check_mark:| PO001 | JSON Threat Protection | A check for a body element must be performed before policy execution. |
162-
|   |:white_check_mark:| PO002 | XML Threat Protection | A check for a body element must be performed before policy execution. |
163-
|   |:white_check_mark:| PO003 | Extract Variables with JSONPayload | A check for a body element must be performed before policy execution. |
164-
|   |:white_check_mark:| PO004 | Extract Variables with XMLPayload | A check for a body element must be performed before policy execution. |
165-
|   |:white_check_mark:| PO005 | Extract Variables with FormParam | A check for a body element must be performed before policy execution. |
166171
|   |:white_check_mark:| PO006 | Policy Name & filename agreement | Policy name attribute should coincide with the policy filename. |
167172
|   |:white_check_mark:| PO007 | Policy Naming Conventions - type indication | It is recommended that the policy name use a prefix or follow a pattern that indicates the policy type. |
168173
|   |:white_check_mark:| PO008 | Policy DisplayName & DisplayName agreement | Check that the policy filename matches the display name of the policy. |
169-
|   |:white_medium_square:| PO009 | Service Callout Target - Mgmt Server | Targeting management server may result in higher than expected latency use with caution. |
174+
|   |:white_medium_square:| PO009 | Service Callout Target - Mgmt Server | Targeting management server may result in higher than expected latency; use with caution. |
170175
|   |:white_medium_square:| PO010 | Service Callout Target - Target Server | Encourage use of target servers. |
171176
|   |:white_medium_square:| PO011 | Service Callout Target - Dynamic URLs | Error on dynamic URLs in target server URL tag. |
172177
|   |:white_check_mark:| PO012 | AssignMessage/AssignTo | Warn on unnecessary AssignTo in AssignMessage when createNew is false and no destination variable. |
@@ -210,6 +215,28 @@ This is the current list:
210215

211216
From an implementation perspective, the focus is on plugin support and flexibility over performance. Compute is cheap.
212217

218+
## Release Notes
219+
220+
### Release v2.31.0
221+
222+
#### Condition checks around policies
223+
224+
In release v2.31.0, the plugins PO001, PO002, PO003, PO004, and PO005 have been
225+
converted to ST006, ST007, ST003, ST004, and ST005, respectively. These plugins
226+
move from the "Policy" category to the "Step" category because the plugin
227+
analyzes the attachment of the policy in a Step element, rather than the policy
228+
itself. Also these plugins will now generate warnings, rather than errors.
229+
230+
If previously you excluded PO003 via the `--excluded` option, you must now
231+
exclude ST003, and so on.
232+
233+
#### Sharedflows
234+
235+
Starting with release v2.31.0, using apigeelint against Sharedflows will
236+
generate a correct report. Previously the report on a sharedflow was truncated
237+
and omitted some warnings and errors.
238+
239+
213240

214241
## Support
215242

lib/package/Bundle.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -306,29 +306,20 @@ function Bundle(config, cb) {
306306
Bundle.prototype.getReport = function(cb) {
307307
//go out and getReport from endpoints, resources, policies
308308

309-
var result = [this.report],
310-
append = function(a) {
311-
a.forEach(function(e) {
312-
result.push(e.getReport());
313-
});
314-
};
309+
let result = [this.report];
310+
const appendCollection =
311+
collection => collection.forEach( item => result.push(item.getReport()) );
315312

316-
//no endpoints in shared flow
317-
if(this.bundleTypeName !== bundleType.BundleType.SHAREDFLOW){
318-
append(this.getEndpoints());
319-
}
320-
append(this.getPolicies());
321-
append(this.getResources());
313+
appendCollection(this.getEndpoints()); // for either apiproxy or sharedflow
314+
appendCollection(this.getPolicies());
315+
appendCollection(this.getResources());
322316
if (cb) {
323317
cb(result);
324318
}
325319
return result;
326320
};
327321

328322
Bundle.prototype.addMessage = function(msg) {
329-
//lets inspect what we got
330-
//if it includes a plugin field
331-
//then process new style
332323
if (msg.hasOwnProperty("plugin")) {
333324
msg.ruleId = msg.plugin.ruleId;
334325
if (!msg.severity) msg.severity = msg.plugin.severity;
@@ -563,7 +554,7 @@ Bundle.prototype.getDefaultFaultRules = function() {
563554
};
564555

565556
Bundle.prototype.summarize = function() {
566-
var summary = {
557+
let summary = {
567558
report: this.getReport(),
568559
root: this.root,
569560
name: this.getName(),

lib/package/Endpoint.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Endpoint(element, parent, fname, bundletype) {
3131
debug(`> new Endpoint() ${fname}`);
3232
this.bundleType = bundletype ? bundletype : "apiproxy" //default to apiproxy if bundletype not passed
3333
this.fileName = fname;
34-
this.parent = parent;
34+
this.parent = parent; // the bundle
3535
this.element = element;
3636
this.report = {
3737
filePath: fname.substring(fname.indexOf("/" + this.bundleType)),
@@ -169,7 +169,6 @@ Endpoint.prototype.getPostClientFlow = function() {
169169

170170
Endpoint.prototype.getSharedFlow = function() {
171171
if (!this.sharedFlow) {
172-
//find the preflow tag
173172
var doc = xpath.select(".", this.element);
174173
if (doc && doc[0]) {
175174
this.sharedFlow = new Flow(doc[0], this);
@@ -230,7 +229,9 @@ Endpoint.prototype.getFlows = function() {
230229
else {
231230
debug(`Flow`);
232231
}
233-
flows.push(new Flow(elt, ep));
232+
let f = new Flow(elt, ep);
233+
debug(`getFlows() flow= ${f.element.tagName}`);
234+
flows.push(f);
234235
});
235236
});
236237
}
@@ -428,14 +429,15 @@ Endpoint.prototype.getParent = function() {
428429
};
429430

430431
Endpoint.prototype.addMessage = function(msg) {
432+
debug(`> addMessage`);
431433
//Severity should be one of the following: 0 = off, 1 = warning, 2 = error
432434
if (msg.hasOwnProperty("plugin")) {
433435
msg.ruleId = msg.plugin.ruleId;
434436
if (!msg.severity) msg.severity = msg.plugin.severity;
435437
msg.nodeType = msg.plugin.nodeType;
436438
delete msg.plugin;
437439
}
438-
debug(`Endpoint.addMessage ${msg.ruleId}: ${msg.message}`);
440+
debug(`addMessage ${msg.ruleId}: ${msg.message}`);
439441

440442
if (!msg.hasOwnProperty("entity")) {
441443
msg.entity = this;
@@ -466,37 +468,42 @@ Endpoint.prototype.addMessage = function(msg) {
466468
};
467469

468470
Endpoint.prototype.summarize = function() {
469-
var summary = {};
471+
debug('> summarize');
472+
let summary = {
473+
name : this.getName(),
474+
type : this.getType(),
475+
};
476+
477+
if(this.bundleType === bundleTypes.BundleType.SHAREDFLOW){
478+
debug('summarize - is SharedFlow');
479+
summary.flows =
480+
this.getSharedFlow().summarize();
481+
}
482+
else {
483+
debug('summarize - is Apiproxy');
484+
summary.proxyName = this.getProxyName();
485+
486+
let faultRules = this.getFaultRules();
487+
if (faultRules) {
488+
summary.faultRules = [];
489+
faultRules.forEach(function(fr) {
490+
summary.faultRules.push(fr.summarize());
491+
});
492+
}
470493

471-
summary.name = this.getName();
472-
summary.type = this.getType();
473-
summary.proxyName = this.getProxyName();
494+
summary.defaultFaultRule =
495+
(this.getDefaultFaultRule() && this.getDefaultFaultRule().summarize()) ||
496+
{};
474497

475-
var faultRules = this.getFaultRules();
476-
if (faultRules) {
477-
summary.faultRules = [];
478-
faultRules.forEach(function(fr) {
479-
summary.faultRules.push(fr.summarize());
480-
});
481-
}
498+
summary.preFlow = (this.getPreFlow() && this.getPreFlow().summarize()) || {};
482499

483-
summary.defaultFaultRule =
484-
(this.getDefaultFaultRule() && this.getDefaultFaultRule().summarize()) ||
485-
{};
500+
summary.flows = this.getFlows().map(flow => flow.summarize());
486501

487-
summary.preFlow = (this.getPreFlow() && this.getPreFlow().summarize()) || {};
488-
489-
summary.flows = [];
490-
this.getFlows().forEach(function(flow) {
491-
summary.flows.push(flow.summarize());
492-
});
493-
summary.postFlow =
494-
(this.getPostFlow() && this.getPostFlow().summarize()) || {};
495-
summary.routeRules = [];
496-
this.getRouteRules().forEach(function(rr) {
497-
summary.routeRules.push(rr.summarize());
498-
});
502+
summary.postFlow =
503+
(this.getPostFlow() && this.getPostFlow().summarize()) || {};
504+
summary.routeRules = this.getRouteRules().map(rr => rr.summarize());
499505

506+
}
500507
return summary;
501508
};
502509

lib/package/Flow.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,22 @@ const xpath = require("xpath"),
2222
getcb = myUtil.curry(myUtil.diagcb, debug);
2323

2424
function Flow(element, parent) {
25-
this.parent = parent;
25+
this.parent = parent; // like ProxyEndpoint , TargetEndpoint
2626
this.element = element;
2727
this.condition = null;
2828
this.flowResponse = null;
2929
this.sharedflow = null;
3030
this.description = null;
31+
let self = this;
32+
debug(`Flow ctor: self: ${self.element.tagName}`);
3133
}
3234

3335
Flow.prototype.getName = function() {
3436
if (!this.name) {
3537
var attr = xpath.select("./@name", this.element);
3638
this.name = (attr[0] && attr[0].value) || "";
3739
}
40+
debug(`getName(): self: ${self.element.tagName}, name: ${this.name}`);
3841
return this.name;
3942
};
4043

@@ -43,9 +46,10 @@ Flow.prototype.getMessages = function() {
4346
};
4447

4548
Flow.prototype.getType = function() {
46-
//lets go ahead and look this up
4749
if (!this.type) {
48-
this.type = xpath.select("name(/*)", this.element);
50+
// Flow | PreFlow || PostFlow || PostClientFlow
51+
//this.type = xpath.select("name(/*)", this.element);
52+
this.type = this.element.tagName;
4953
}
5054
return this.type;
5155
};
@@ -93,7 +97,8 @@ Flow.prototype.getFlowRequest = function() {
9397
};
9498

9599
Flow.prototype.getFlowResponse = function() {
96-
if (this.flowResponse == null) {
100+
let self = this;
101+
if ( ! this.flowResponse) {
97102
let doc = xpath.select("./Response", this.element);
98103
this.flowResponse = (doc && doc[0]) ? new FlowPhase(doc[0], this) : false;
99104
}

lib/package/FlowPhase.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const xpath = require("xpath"),
2323
function FlowPhase(element, parent) {
2424
this.parent = parent;
2525
this.element = element;
26+
debug(`parent is ${parent.getType()}`);
2627
}
2728

2829
FlowPhase.prototype.getType = function() {
@@ -62,7 +63,7 @@ FlowPhase.prototype.onSteps = function(pluginFunction, cb) {
6263
let steps = this.getSteps();
6364
if (steps && steps.length > 0) {
6465
steps.forEach( (step, ix) =>
65-
pluginFunction(step, getcb(`step ${ix}}`)));
66+
pluginFunction(step, getcb(`step ${ix}`)));
6667
}
6768
cb(null, {});
6869
};
@@ -71,7 +72,7 @@ FlowPhase.prototype.onConditions = function(pluginFunction, cb) {
7172
let steps = this.getSteps();
7273
if (steps && steps.length > 0) {
7374
steps.forEach( (step, ix) =>
74-
step.onConditions(pluginFunction, getcb(`step ${ix}}`)));
75+
step.onConditions(pluginFunction, getcb(`step ${ix}`)));
7576
}
7677
cb(null, {});
7778
};

lib/package/plugins/PO001-threatProtectionJSONConditionCheck.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)