apigeelint
Version:
Node module and tool to lint a bundle for an Apigee API Proxy or sharedflow.
61 lines (51 loc) • 1.86 kB
JavaScript
/*
Copyright © 2019-2022,2026 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const ruleId = require("../lintUtil.js").getRuleId(),
debug = require("debug")("apigeelint:" + ruleId);
const plugin = {
ruleId,
name: "Check number of policies present in the bundle",
message:
"Large bundles can be problematic in development and difficult to maintain.",
fatal: false,
severity: 1, //warn
nodeType: "Bundle",
enabled: true,
};
const DEFAULT_POLICY_COUNT_LIMIT = 100;
const onBundle = function (bundle, cb) {
let flagged = false;
let policyCountLimit = DEFAULT_POLICY_COUNT_LIMIT;
if (bundle.config.policyCountLimit) {
debug(`policyCountLimit: ${bundle.config.policyCountLimit}`);
policyCountLimit = bundle.config.policyCountLimit;
} else {
debug(`policyCountLimit (DEFAULT): ${policyCountLimit}`);
}
if (bundle.policies && bundle.policies.length > policyCountLimit) {
bundle.addMessage({
plugin,
message:
`Policy count (${bundle.policies.length}) exceeds recommended limit of ${policyCountLimit}. ` +
`Consider refactoring into two or more bundles. Large bundles take longer to deploy and are more difficult to debug and maintain.`,
});
flagged = true;
}
if (typeof cb == "function") {
cb(null, flagged);
}
};
module.exports = {
plugin,
onBundle,
};