API Governance

Create, Test, Build, and Deploy Custom API Governance Rulesets With the Ruleset-Development-CLI Tool

The final part of the series explains developing, testing, building, and deploying custom rulesets with MuleSoft’s ruleset-development-cli tool.

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 Create and Test a Custom Ruleset

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

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 directory for your ruleset

Create a new directory where you want to store your ruleset and navigate into it.

Step 3 – Initialize the ruleset

Run the following command to initialize a new ruleset:

ruleset-development-cli init

Step 4 – Provide the ruleset details

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 – Review the generated directory structure

After providing all the required information, the CLI will generate a basic directory structure for your ruleset.

Step 6 – Add your rules

Add your rules to the rules directory under the ruleset directory structure generated by the CLI.

Step 7 – Test the ruleset

You can test your ruleset by running the following command:

ruleset-development-cli test

Step 8 – Run the tests

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 – Confirm a successful test run

If there are no test errors, the CLI will report a successful test run.

Step 10 – Build the ruleset

You can then build the ruleset by running the following command:

ruleset-development-cli build

Step 11 – Confirm the build output

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 ruleset

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 – Confirm a successful deployment

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!

Contact Us

Talk to an integration expert

About your environment — no pitch deck required.

Simple Contact Form [blog page]

Guilherme Machado
Guilherme Machado

Guilherme is an Integration Solution Architect at API People. Based in Curitiba, Paraná, Brazil, he has over 10 years experience in different spaces, from VoIP-embedded systems and network switches to MuleSoft APIs/Integrations. He is a MuleSoft Certified Developer 4, MuleSoft Certified Integration Architect, and a certified Azure Date Engineer.

Articles: 7
Stay ahead on integration & automation

Insights, product releases and event invites for technology leaders — straight to your inbox.

Discover more from API People

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from API People

Subscribe now to keep reading and get access to the full archive.

Continue reading