Reorder Application and Firewall rules
Change the position of the rules of an Application or a Firewall with one PUT request per rule list to the Azion API v4.
You can reorder the rules of an Application or a Firewall with one PUT request to the Azion API v4. The request sends an order array with the ID of every rule in the list, in the new order. A list holds the rules of one Application phase, or every rule of a Firewall.
To reorder Firewall rules from Azion Console or the Azion CLI, refer to Change the order of Firewall rules. To reorder Application rules in Azion Console, move them in the list of the Rules Engine tab. For the Azion CLI command, refer to the CLI section of Rules Engine for Applications.
Prerequisites
- A personal token. To create one, refer to Manage personal tokens.
curl, to call the API.- An Application with two or more rules in the phase you want to reorder, or a Firewall with two or more rules.
Reorder the request rules of an Application
The order field of a rule is its position in its phase, from 0. The reorder request sets every position of the phase at once.
To reorder the request rules:
-
Store your token and the ID of the Application in shell variables. Replace the two values with your own:
Shell -
List the request rules in their current order. The
fieldsparameter keeps the ID, the name, and the position of each rule:ShellThe response lists the rules by position:
JSONA page holds at most 100 rules. If
nextis notnull, read the next pages too. To read every page, refer to Page through a list with filters and ordering. -
Send a
PUTrequest with every rule ID of the phase in the new order. Replace the IDs with your own. This example movesDeny adminto the first position:ShellThe API answers
202. The response holds the first page of the rules in their new order, with apage_sizeof 10. This excerpt shows the ID, the name, and the position of each rule:JSONWith more than 10 rules, the response holds the first 10, and
countandtotal_pagesreport the rest. The new order still applies to every rule you sent: list the rules again to read all of them.
Deny admin is the first request rule of the Application. The new order reaches traffic only after it propagates, and Azion guarantees no propagation time. To check it, repeat a request that a moved rule matches until every answer is the one you expect. For the order in which an Application runs its rules, and for propagation, refer to How Applications works.
Reorder the response rules of an Application
The response phase has its own list of positions, and its own reorder path, response_rules/order.
To reorder the response rules:
-
Store your token and the ID of the Application in shell variables. Replace the two values with your own:
Shell -
List the response rules in their current order:
ShellThe response lists the rules by position:
JSONA page holds at most 100 rules. If
nextis notnull, read the next pages too. -
Send a
PUTrequest with every response rule ID in the new order. Replace the IDs with your own:ShellThe API answers
202. The response holds the first page of the response rules in their new order:JSON
Remove server header is the first response rule of the Application, and the request rules keep their positions. The new order reaches traffic only after it propagates, and Azion guarantees no propagation time. To check it, repeat a request that a moved rule matches until every answer is the one you expect. For more information, refer to Propagation.
Reorder the rules of a Firewall
A Firewall has one list of rules, and its reorder path is request_rules/order under the Firewall.
To reorder the rules of a Firewall:
-
Store your token and the ID of the Firewall in shell variables. Replace the two values with your own:
Shell -
List the rules in their current order:
ShellThe response lists the rules by position:
JSONA page holds at most 100 rules. If
nextis notnull, read the next pages too. -
Send a
PUTrequest with every rule ID of the Firewall in the new order. Replace the IDs with your own:ShellThe API answers
202. The response holds the first page of the rules of the Firewall in their new order:JSON
Drop xmlrpc is the first rule of the Firewall. The new order reaches traffic only after it propagates, and Azion guarantees no propagation time. To check it, repeat a request that a moved rule matches until every answer is the one you expect. For the order in which a Firewall runs its rules, and for propagation, refer to How Firewall works.
Fix a rejected order
The API rejects an order array that does not list every rule of the phase, or of the Firewall, exactly once. On the three reorder paths, it answers 400, keeps the current positions, and names the problem in errors[0].code:
| Code | Title | Cause | Fix |
|---|---|---|---|
25002 |
Missing Rules In Order | The array leaves out a rule, or it is empty. | List every page of rules again and send every ID. |
25001 |
Invalid Rules | The array holds an ID that is not a rule of this list. | Remove the ID. |
25000 |
Duplicated Rules | The array holds an ID twice. | Keep one copy of the ID. |
With 25001, meta.not_found_ids lists the IDs that are not rules of the list. A request rule ID in a response order is one of them. With 25000, meta.duplicated_ids lists the repeated IDs.
For example, an array that leaves out one of the request rules returns this body:
After the fix, the PUT request returns the first page of the rules in their new order.