apim-policy-utils
Version:
An XML file scripts maniputaling and debugging tool targeting to help working with Azure APIM Policy files in xml format.
76 lines • 3.21 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
const constants_1 = require("./constants");
const commander = __importStar(require("commander"));
const extractor_1 = require("./extractor");
const combiner_1 = require("./combiner");
const getVersion_1 = require("./getVersion");
const figlet = __importStar(require("figlet"));
const program = new commander.Command();
console.log(figlet.textSync("APIM Policy"));
program
.version((0, getVersion_1.getVersion)())
.description("Azure API Management Policy Editing and Debugging Tool")
.option('-e, --extract <value>', 'Extract the policies in the specified directory')
.option('-c, --combine <value...>', 'Combine the policies in the specified directory')
.option("-h, --help", "Output usage information", () => {
program.outputHelp();
})
.addHelpText('after', constants_1.cliHelp)
.parse(process.argv);
const options = program.opts();
if (options.extract) {
console.log(`✅ Extracting policy files from ${options.extract}`);
(0, extractor_1.extractFromDirectory)(options.extract);
}
if (options.combine) {
const paths = options.combine;
if (paths.length > 2) {
console.error('❌ Error: Too many paths provided for the -c option. Maximum allowed is 2.');
console.error('ℹ️ Please run the command with the -h | --help option to see the usage information.');
process.exit(1);
}
if (paths.length === 1) {
console.log(`✅ Combining policy files from ${options.combine[0]} and writing to the same directory`);
(0, combiner_1.combineFromDirectory)(options.combine[0]);
}
else if (paths.length === 2) {
console.log(`✅ Combining policy files from ${options.combine[0]} and writting to ${options.combine[1]}`);
(0, combiner_1.combineFromDirectory)(options.combine[0], options.combine[1]);
}
}
if (!process.argv.slice(2).length) {
program.outputHelp();
}
module.exports = {
extractor: extractor_1.extractFromDirectory,
combiner: combiner_1.combineFromDirectory
};
// module.exports = {
// extractor: extractFromDirectory,
// combiner: combineFromDirectory
// }
//# sourceMappingURL=index.js.map