API Governance with MuleSoft Anypoint Platform (Part 4/4)
In the first post of this four-part series, we provided an overview of what API governance is in MuleSoft.
In the second post, we discussed API governance workflow and how to apply rulesets to APIs (via API governance profiles). We also reviewed the conformance dashboards, and where to see where an API is conformant in Exchange when a profile is applied to it.
In the third post, we discussed how to create, upload, and apply a custom ruleset. We also reviewed where these custom rulesets exist in Exchange and how to consume them in governance profiles.
This fourth and final post of the series will focus on how to create, test, build, and deploy custom rulesets for API governance in Anypoint Platform using the ruleset-development-cli tool. This is a high-level overview of the basic steps to follow. A link to a more comprehensive tutorial provided.
how-to
To create and test a MuleSoft ruleset with the ruleset-development-cli, you can follow the steps below:
Step 1
Install the ruleset-development-cli by running the following command in a terminal window:
npm install -g @mulesoft/ruleset-development-cli
Step 2
Create a new directory where you want to store your ruleset and navigate into it.
Step 3
Run the following command to initialize a new ruleset:
ruleset-development-cli init
Step 4
The CLI will prompt you for some information about your ruleset, such as the name, description, and version. Fill in the required fields as prompted.
Step 5
After providing all the required information, the CLI will generate a basic directory structure for your ruleset.
Step 6
Add your rules to the rules directory under the ruleset directory structure generated by the CLI.
Step 7
You can test your ruleset by running the following command:
ruleset-development-cli test
Step 8
The CLI will run the tests located in the test directory under the ruleset directory structure. Make sure you have added test cases for all of your rules in the test directory.
Step 9
If there are no test errors, the CLI will report a successful test run.
Step 10
You can then build the ruleset by running the following command:
ruleset-development-cli build
Step 11
If there are no build errors, the CLI will generate a .jar file that contains your ruleset in the target directory.
Step 12
Deploy the generated .jar file to your MuleSoft runtime environment by running the following command:
ruleset-development-cli deploy --target=<target-environment>
--file=<path-to-jar-file>
Note: Replace with the name or URL of the MuleSoft environment you want to deploy to (such as “dev” or “https://anypoint.mulesoft.com”), and with the path to the .jar file generated in step 10.
Step 13
If the deployment is successful, the CLI will report a successful deployment.
Summary
Even though it is a bit more complicated, it is much more robust to develop custom rulesets with the CLI tool. We have reviewed the steps required to:
- Install the CLI tool
- Initialize a new ruleset with the CLI tool
- How to test a new ruleset with the CLI tool
- How to build and deploy a new ruleset with the CLI tool
This is simply a high-level guide on how to develop rulesets with the CLI tool. A more comprehensive tutorial can be seen at this link.
In this four-part blog series we have reviewed:
- What API Governance with MuleSoft is
- The out-of-the-box rulesets and where they exist in the Anypoint Platform
- How to define governance profiles to apply rulesets to APIs
- How to manually develop and upload a new ruleset
- How to develop a new ruleset with the CLI tool
We hope this series on API Governance with MuleSoft was informative. Stay tuned for future posts!
