Note: This library is under active development as I expand it to cover Cloudflare API. Consider the public API of this package a little unstable as I work towards a v1.0. See Coverage.

Rulesets

The Cloudflare Ruleset Engine allows you to create and deploy rules and rulesets in different Cloudflare products using the same basic syntax.

Cloudflare API docs

List

Fetches all rulesets at the account level.

php
$response = $client->accounts()->rulesets()->get('ACCOUNT_ID');

Create

Creates a ruleset at the account level.

php
use Cloudflare\Configurations\Rules\BlockRule;
use Cloudflare\Configurations\Ruleset;

$ruleset = (new Ruleset('The human-readable name of the ruleset.'))
    ->managed() //Set Ruleset kind to 'managed'
    ->configSettings() //Set Ruleset phase to 'http_config_settings'
    ->setDescription('An informative description of the ruleset.');

//Create a BlockRule
$blockRule = new BlockRule(['title' => 'My Response Title', 'text' => 'My response text'], 'application/json', 400);

$blockRule->setExpression(function(ExpressionBuilder $builder){
    return $builder->field('ip.src')->eq('192.168.1.2')->or()->group(function(ExpressionBuilder $bilder){
        $bilder->not()->field('ssl')->or()->field('udp')->contains(32);
    })->or()->addExpression('ip.src', 'eq', '127.0.01');
});

$ruleset->addRule($blockRule);

$response = $client->accounts()->rulesets()->create('ACCOUNT_ID', $ruleset);

Details

Fetches the latest version of an account ruleset.

php
$response = $client->accounts()->rulesets()->details('ACCOUNT_ID', 'RULESET_ID');

Delete

Deletes all versions of an existing account ruleset.

php
$response = $client->accounts()->rulesets()->delete('ACCOUNT_ID', 'RULESET_ID');
Table of Contents