Updating rulesets and rules with the toolkit CLI

Use the API Connect toolkit CLI to update a ruleset or individual rules.

Updating a ruleset

  1. Create a JSON file that defines the updated ruleset.
    The following example shows an updated ruleset:
    {
        "title": "custom-ruleset-2",
        "description": "short ruleset updated",
        "ruleset_type": "custom"
    }
    
    where:
    • title is updated to a new title for the ruleset.
    • description is updated to a new description for the ruleset.
    • ruleset_type is updated to be custom for the ruleset.
  2. Log in to the toolkit as an Admin or as the owner of the provider organization that owns the ruleset.

  3. Run the rulesets:update toolkit command in governance mode:
    apic -m governance rulesets:update --org <target_org> --server <platform_api_host_name> RULESET RULESET_FILE
    where:
    • <target_org> is the name of the organization that owns the ruleset.
    • <platform_api_host_name> is the hostname portion URL of server that hosts the API Manager (the "management server").
      Tip: To determine the hostname, you can open the API Manager in a browser and copy the hostname from the URL in the address bar (beginning after https:// and ending before /manager).
    • RULESET_FILE is the path and filename of the JSON file that contains the updated ruleset.
    • RULESET is the name or the unique ID of the updated ruleset.
      To determine the ID of a ruleset, run the following command:
      apic -m governance rulesets:list --org <target_org> --server <platform_api_host_name>

Updating a rule

  1. Create a JSON file that defines the updated rule.
    The following example shows an updated rule:
    {
      "description": "Updated the rule",
      "message": "Schema of type array must specify maxItems and minItems. {{path}} {{error}}",
      "formats": [
        "oas3"
      ],
      "severity": "warn",
      "recommended": true,
      "given": [
        "$..[?(@.type==\"array\")]"
      ]
    }
    where:
    • description is updated to a new title for the rule
    • message is updated to a new message for the rule
    • formats array is replaced to have only the format oas3 for the rule
    • severity is updated to the warn value for the rule
    • recommended is updated to have a new value for the rule
    • given array is replaced to have new values for the rule
  2. Log in to the toolkit as an Admin or as the owner of the provider organization that owns the rule.

  3. Run the rules:update toolkit command in governance mode.

    There are two ways to specify the updated rule in the command, depending on whether you provide the rule name and version, or the rule ID:

    Specify the rule name and version in the update command
    apic -m governance rules:update --org <target_org> --server <platform_api_host_name> --ruleset <ruleset_name or ruleset_id> NAME:VERSION RULE_FILE
    where:
    • <target_org> is the name of the organization that owns the rule.
    • <platform_api_host_name> is the hostname portion URL of server that hosts the API Manager (the "management server").
      Tip: To determine the hostname, you can open the API Manager in a browser and copy the hostname from the URL in the address bar (beginning after https:// and ending before /manager).
    • <ruleset_name or ruleset_id> is the name or the unique ID of the ruleset to which the updated rule belongs.
    • NAME is the name of the updated rule.
    • VERSION is the version of the updated rule; increase the version when you update the rule, using the major.minor.patch format as in "1.0.1".
    • RULE_FILE is the path and filename of the JSON file that contains the updated rule.
    Specify the rule ID in the update command
    Instead of providing the rule's name and version, you can provide its unique ID instead by running the following command:
    apic -m governance rules:update --org <target_org> --server <platform_api_host_name> --ruleset <ruleset_name or ruleset_id> --id <rule_id> RULE_FILE
    where:
    • <target_org> is the name of the organization that owns the rule.
    • <platform_api_host_name> is the hostname portion URL of server that hosts the API Manager (the "management server").
      Tip: To determine the hostname, you can open the API Manager in a browser and copy the hostname from the URL in the address bar (beginning after https:// and ending before /manager).
    • <ruleset_name or ruleset_id> is the name or the unique ID of the ruleset to which the update rule belongs.
    • RULE_FILE is the path and filename of the JSON file that contains the updated rule.
    • <rule_id> is the value of the updated rule's unique ID.
      To determine the ID of a rule, run the following command:
      apic -m governance rules:list --org <target_org> --server <platform_api_host_name> --ruleset <ruleset_name> RULE_NAME